bukku-client 0.1.0-test.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 (231) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +85 -0
  3. package/dist/accounting/accounts/index.d.ts +52 -0
  4. package/dist/accounting/accounts/index.d.ts.map +1 -0
  5. package/dist/accounting/accounts/index.js +72 -0
  6. package/dist/accounting/accounts/index.js.map +1 -0
  7. package/dist/accounting/accounts/type.d.ts +125 -0
  8. package/dist/accounting/accounts/type.d.ts.map +1 -0
  9. package/dist/accounting/accounts/type.js +4 -0
  10. package/dist/accounting/accounts/type.js.map +1 -0
  11. package/dist/accounting/index.d.ts +10 -0
  12. package/dist/accounting/index.d.ts.map +1 -0
  13. package/dist/accounting/index.js +16 -0
  14. package/dist/accounting/index.js.map +1 -0
  15. package/dist/accounting/journal-entries/index.d.ts +52 -0
  16. package/dist/accounting/journal-entries/index.d.ts.map +1 -0
  17. package/dist/accounting/journal-entries/index.js +72 -0
  18. package/dist/accounting/journal-entries/index.js.map +1 -0
  19. package/dist/accounting/journal-entries/type.d.ts +151 -0
  20. package/dist/accounting/journal-entries/type.d.ts.map +1 -0
  21. package/dist/accounting/journal-entries/type.js +4 -0
  22. package/dist/accounting/journal-entries/type.js.map +1 -0
  23. package/dist/common/type.d.ts +105 -0
  24. package/dist/common/type.d.ts.map +1 -0
  25. package/dist/common/type.js +3 -0
  26. package/dist/common/type.js.map +1 -0
  27. package/dist/contacts/contacts/index.d.ts +57 -0
  28. package/dist/contacts/contacts/index.d.ts.map +1 -0
  29. package/dist/contacts/contacts/index.js +82 -0
  30. package/dist/contacts/contacts/index.js.map +1 -0
  31. package/dist/contacts/contacts/type.d.ts +286 -0
  32. package/dist/contacts/contacts/type.d.ts.map +1 -0
  33. package/dist/contacts/contacts/type.js +4 -0
  34. package/dist/contacts/contacts/type.js.map +1 -0
  35. package/dist/contacts/groups/index.d.ts +42 -0
  36. package/dist/contacts/groups/index.d.ts.map +1 -0
  37. package/dist/contacts/groups/index.js +59 -0
  38. package/dist/contacts/groups/index.js.map +1 -0
  39. package/dist/contacts/groups/type.d.ts +34 -0
  40. package/dist/contacts/groups/type.d.ts.map +1 -0
  41. package/dist/contacts/groups/type.js +4 -0
  42. package/dist/contacts/groups/type.js.map +1 -0
  43. package/dist/contacts/index.d.ts +10 -0
  44. package/dist/contacts/index.d.ts.map +1 -0
  45. package/dist/contacts/index.js +15 -0
  46. package/dist/contacts/index.js.map +1 -0
  47. package/dist/control-panel/index.d.ts +15 -0
  48. package/dist/control-panel/index.d.ts.map +1 -0
  49. package/dist/control-panel/index.js +35 -0
  50. package/dist/control-panel/index.js.map +1 -0
  51. package/dist/control-panel/locations/index.d.ts +51 -0
  52. package/dist/control-panel/locations/index.d.ts.map +1 -0
  53. package/dist/control-panel/locations/index.js +70 -0
  54. package/dist/control-panel/locations/index.js.map +1 -0
  55. package/dist/control-panel/locations/type.d.ts +91 -0
  56. package/dist/control-panel/locations/type.d.ts.map +1 -0
  57. package/dist/control-panel/locations/type.js +4 -0
  58. package/dist/control-panel/locations/type.js.map +1 -0
  59. package/dist/control-panel/tag-groups/index.d.ts +44 -0
  60. package/dist/control-panel/tag-groups/index.d.ts.map +1 -0
  61. package/dist/control-panel/tag-groups/index.js +63 -0
  62. package/dist/control-panel/tag-groups/index.js.map +1 -0
  63. package/dist/control-panel/tag-groups/type.d.ts +64 -0
  64. package/dist/control-panel/tag-groups/type.d.ts.map +1 -0
  65. package/dist/control-panel/tag-groups/type.js +4 -0
  66. package/dist/control-panel/tag-groups/type.js.map +1 -0
  67. package/dist/control-panel/tags/index.d.ts +43 -0
  68. package/dist/control-panel/tags/index.d.ts.map +1 -0
  69. package/dist/control-panel/tags/index.js +60 -0
  70. package/dist/control-panel/tags/index.js.map +1 -0
  71. package/dist/control-panel/tags/type.d.ts +60 -0
  72. package/dist/control-panel/tags/type.d.ts.map +1 -0
  73. package/dist/control-panel/tags/type.js +4 -0
  74. package/dist/control-panel/tags/type.js.map +1 -0
  75. package/dist/files/index.d.ts +29 -0
  76. package/dist/files/index.d.ts.map +1 -0
  77. package/dist/files/index.js +42 -0
  78. package/dist/files/index.js.map +1 -0
  79. package/dist/files/type.d.ts +50 -0
  80. package/dist/files/type.d.ts.map +1 -0
  81. package/dist/files/type.js +4 -0
  82. package/dist/files/type.js.map +1 -0
  83. package/dist/index.d.ts +73 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +130 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/lists/index.d.ts +24 -0
  88. package/dist/lists/index.d.ts.map +1 -0
  89. package/dist/lists/index.js +33 -0
  90. package/dist/lists/index.js.map +1 -0
  91. package/dist/lists/type.d.ts +781 -0
  92. package/dist/lists/type.d.ts.map +1 -0
  93. package/dist/lists/type.js +3 -0
  94. package/dist/lists/type.js.map +1 -0
  95. package/dist/products/groups/index.d.ts +42 -0
  96. package/dist/products/groups/index.d.ts.map +1 -0
  97. package/dist/products/groups/index.js +59 -0
  98. package/dist/products/groups/index.js.map +1 -0
  99. package/dist/products/groups/type.d.ts +53 -0
  100. package/dist/products/groups/type.d.ts.map +1 -0
  101. package/dist/products/groups/type.js +5 -0
  102. package/dist/products/groups/type.js.map +1 -0
  103. package/dist/products/index.d.ts +10 -0
  104. package/dist/products/index.d.ts.map +1 -0
  105. package/dist/products/index.js +15 -0
  106. package/dist/products/index.js.map +1 -0
  107. package/dist/products/products/index.d.ts +51 -0
  108. package/dist/products/products/index.d.ts.map +1 -0
  109. package/dist/products/products/index.js +70 -0
  110. package/dist/products/products/index.js.map +1 -0
  111. package/dist/products/products/type.d.ts +270 -0
  112. package/dist/products/products/type.d.ts.map +1 -0
  113. package/dist/products/products/type.js +4 -0
  114. package/dist/products/products/type.js.map +1 -0
  115. package/dist/purchases/bills/index.d.ts +51 -0
  116. package/dist/purchases/bills/index.d.ts.map +1 -0
  117. package/dist/purchases/bills/index.js +75 -0
  118. package/dist/purchases/bills/index.js.map +1 -0
  119. package/dist/purchases/bills/type.d.ts +254 -0
  120. package/dist/purchases/bills/type.d.ts.map +1 -0
  121. package/dist/purchases/bills/type.js +4 -0
  122. package/dist/purchases/bills/type.js.map +1 -0
  123. package/dist/purchases/credit-notes/index.d.ts +51 -0
  124. package/dist/purchases/credit-notes/index.d.ts.map +1 -0
  125. package/dist/purchases/credit-notes/index.js +71 -0
  126. package/dist/purchases/credit-notes/index.js.map +1 -0
  127. package/dist/purchases/credit-notes/type.d.ts +204 -0
  128. package/dist/purchases/credit-notes/type.d.ts.map +1 -0
  129. package/dist/purchases/credit-notes/type.js +4 -0
  130. package/dist/purchases/credit-notes/type.js.map +1 -0
  131. package/dist/purchases/goods-received-notes/index.d.ts +51 -0
  132. package/dist/purchases/goods-received-notes/index.d.ts.map +1 -0
  133. package/dist/purchases/goods-received-notes/index.js +71 -0
  134. package/dist/purchases/goods-received-notes/index.js.map +1 -0
  135. package/dist/purchases/goods-received-notes/type.d.ts +184 -0
  136. package/dist/purchases/goods-received-notes/type.d.ts.map +1 -0
  137. package/dist/purchases/goods-received-notes/type.js +4 -0
  138. package/dist/purchases/goods-received-notes/type.js.map +1 -0
  139. package/dist/purchases/index.d.ts +18 -0
  140. package/dist/purchases/index.d.ts.map +1 -0
  141. package/dist/purchases/index.js +23 -0
  142. package/dist/purchases/index.js.map +1 -0
  143. package/dist/purchases/payments/index.d.ts +51 -0
  144. package/dist/purchases/payments/index.d.ts.map +1 -0
  145. package/dist/purchases/payments/index.js +71 -0
  146. package/dist/purchases/payments/index.js.map +1 -0
  147. package/dist/purchases/payments/type.d.ts +183 -0
  148. package/dist/purchases/payments/type.d.ts.map +1 -0
  149. package/dist/purchases/payments/type.js +4 -0
  150. package/dist/purchases/payments/type.js.map +1 -0
  151. package/dist/purchases/purchase-orders/index.d.ts +51 -0
  152. package/dist/purchases/purchase-orders/index.d.ts.map +1 -0
  153. package/dist/purchases/purchase-orders/index.js +71 -0
  154. package/dist/purchases/purchase-orders/index.js.map +1 -0
  155. package/dist/purchases/purchase-orders/type.d.ts +182 -0
  156. package/dist/purchases/purchase-orders/type.d.ts.map +1 -0
  157. package/dist/purchases/purchase-orders/type.js +4 -0
  158. package/dist/purchases/purchase-orders/type.js.map +1 -0
  159. package/dist/purchases/refunds/index.d.ts +51 -0
  160. package/dist/purchases/refunds/index.d.ts.map +1 -0
  161. package/dist/purchases/refunds/index.js +71 -0
  162. package/dist/purchases/refunds/index.js.map +1 -0
  163. package/dist/purchases/refunds/type.d.ts +181 -0
  164. package/dist/purchases/refunds/type.d.ts.map +1 -0
  165. package/dist/purchases/refunds/type.js +4 -0
  166. package/dist/purchases/refunds/type.js.map +1 -0
  167. package/dist/sales/credit-notes/index.d.ts +52 -0
  168. package/dist/sales/credit-notes/index.d.ts.map +1 -0
  169. package/dist/sales/credit-notes/index.js +72 -0
  170. package/dist/sales/credit-notes/index.js.map +1 -0
  171. package/dist/sales/credit-notes/type.d.ts +304 -0
  172. package/dist/sales/credit-notes/type.d.ts.map +1 -0
  173. package/dist/sales/credit-notes/type.js +4 -0
  174. package/dist/sales/credit-notes/type.js.map +1 -0
  175. package/dist/sales/delivery-orders/index.d.ts +51 -0
  176. package/dist/sales/delivery-orders/index.d.ts.map +1 -0
  177. package/dist/sales/delivery-orders/index.js +72 -0
  178. package/dist/sales/delivery-orders/index.js.map +1 -0
  179. package/dist/sales/delivery-orders/type.d.ts +212 -0
  180. package/dist/sales/delivery-orders/type.d.ts.map +1 -0
  181. package/dist/sales/delivery-orders/type.js +4 -0
  182. package/dist/sales/delivery-orders/type.js.map +1 -0
  183. package/dist/sales/index.d.ts +20 -0
  184. package/dist/sales/index.d.ts.map +1 -0
  185. package/dist/sales/index.js +24 -0
  186. package/dist/sales/index.js.map +1 -0
  187. package/dist/sales/invoices/index.d.ts +52 -0
  188. package/dist/sales/invoices/index.d.ts.map +1 -0
  189. package/dist/sales/invoices/index.js +73 -0
  190. package/dist/sales/invoices/index.js.map +1 -0
  191. package/dist/sales/invoices/type.d.ts +335 -0
  192. package/dist/sales/invoices/type.d.ts.map +1 -0
  193. package/dist/sales/invoices/type.js +4 -0
  194. package/dist/sales/invoices/type.js.map +1 -0
  195. package/dist/sales/payments/index.d.ts +52 -0
  196. package/dist/sales/payments/index.d.ts.map +1 -0
  197. package/dist/sales/payments/index.js +72 -0
  198. package/dist/sales/payments/index.js.map +1 -0
  199. package/dist/sales/payments/type.d.ts +242 -0
  200. package/dist/sales/payments/type.d.ts.map +1 -0
  201. package/dist/sales/payments/type.js +4 -0
  202. package/dist/sales/payments/type.js.map +1 -0
  203. package/dist/sales/quotations/index.d.ts +51 -0
  204. package/dist/sales/quotations/index.d.ts.map +1 -0
  205. package/dist/sales/quotations/index.js +71 -0
  206. package/dist/sales/quotations/index.js.map +1 -0
  207. package/dist/sales/quotations/type.d.ts +202 -0
  208. package/dist/sales/quotations/type.d.ts.map +1 -0
  209. package/dist/sales/quotations/type.js +3 -0
  210. package/dist/sales/quotations/type.js.map +1 -0
  211. package/dist/sales/refunds/index.d.ts +52 -0
  212. package/dist/sales/refunds/index.d.ts.map +1 -0
  213. package/dist/sales/refunds/index.js +72 -0
  214. package/dist/sales/refunds/index.js.map +1 -0
  215. package/dist/sales/refunds/type.d.ts +225 -0
  216. package/dist/sales/refunds/type.d.ts.map +1 -0
  217. package/dist/sales/refunds/type.js +4 -0
  218. package/dist/sales/refunds/type.js.map +1 -0
  219. package/dist/sales/sales-orders/index.d.ts +52 -0
  220. package/dist/sales/sales-orders/index.d.ts.map +1 -0
  221. package/dist/sales/sales-orders/index.js +72 -0
  222. package/dist/sales/sales-orders/index.js.map +1 -0
  223. package/dist/sales/sales-orders/type.d.ts +202 -0
  224. package/dist/sales/sales-orders/type.d.ts.map +1 -0
  225. package/dist/sales/sales-orders/type.js +4 -0
  226. package/dist/sales/sales-orders/type.js.map +1 -0
  227. package/dist/types.d.ts +17 -0
  228. package/dist/types.d.ts.map +1 -0
  229. package/dist/types.js +4 -0
  230. package/dist/types.js.map +1 -0
  231. package/package.json +44 -0
@@ -0,0 +1,50 @@
1
+ import { BukkuListPagination } from "../common/type";
2
+ /**
3
+ * Represents the structure of the uploaded file details as returned by the API.
4
+ * Based on the 'file' object in the POST /files response sample.
5
+ */
6
+ export interface BukkuUploadedFile {
7
+ id: number;
8
+ filename: string;
9
+ url: string;
10
+ mime_type: string;
11
+ size: number;
12
+ created_at: string;
13
+ updated_at: string;
14
+ }
15
+ /**
16
+ * Represents the API response structure when a file is successfully uploaded.
17
+ */
18
+ export interface BukkuFileResponse {
19
+ file: BukkuUploadedFile;
20
+ }
21
+ /**
22
+ * Enum for file types for filtering.
23
+ */
24
+ export type BukkuFileTypeFilter = "IMAGE" | "VIDEO" | "EXCEL" | "PDF";
25
+ /**
26
+ * Parameters for listing files.
27
+ * Based on GET /files query parameters.
28
+ */
29
+ export interface BukkuFileListParams {
30
+ search?: string;
31
+ type?: BukkuFileTypeFilter;
32
+ is_used?: boolean;
33
+ page?: number;
34
+ page_size?: number;
35
+ [key: string]: any;
36
+ }
37
+ /**
38
+ * Represents a file item as it appears in a list.
39
+ * This might be identical to BukkuUploadedFile, but defined separately for clarity in list contexts.
40
+ */
41
+ export interface BukkuFileListItem extends BukkuUploadedFile {
42
+ }
43
+ /**
44
+ * Represents the API response structure for listing files.
45
+ */
46
+ export interface BukkuFileListApiResponse {
47
+ paging: BukkuListPagination;
48
+ files: BukkuFileListItem[];
49
+ }
50
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/files/type.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAID;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;CAG3D;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // bukku/src/files/type.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/files/type.ts"],"names":[],"mappings":";AAAA,0BAA0B"}
@@ -0,0 +1,73 @@
1
+ import { URL } from "url";
2
+ import { SalesAPI } from "./sales";
3
+ import { PurchasesAPI } from "./purchases";
4
+ import { ContactsAPI } from "./contacts";
5
+ import { ProductsAPI } from "./products";
6
+ import { AccountingAPI } from "./accounting";
7
+ import { ListsAPI } from "./lists";
8
+ import type { ListType, GetListsRequestBody, GetListsResponse, CountryItem, TermItem, CurrencyItem, CurrenciesList, StandardListData } from "./lists/type";
9
+ /**
10
+ * Configuration options for the BukkuClient.
11
+ */
12
+ export interface BukkuClientOptions {
13
+ /**
14
+ * Your Bukku API Access Token.
15
+ * Can be retrieved from Control Panel -> Integrations in your Bukku web app.
16
+ */
17
+ accessToken: string;
18
+ /**
19
+ * The subdomain of the company account you are accessing (e.g., "example" if your Bukku URL is example.bukku.my).
20
+ */
21
+ companySubdomain: string;
22
+ /**
23
+ * The base URL for the Bukku API.
24
+ * For production server, use: https://api.bukku.my
25
+ * For staging server, use: https://api.bukku.fyi
26
+ */
27
+ apiBaseUrl: string;
28
+ /**
29
+ * Optional fetch implementation. If not provided, uses global fetch.
30
+ * This is useful for Node.js environments prior to v18 or for using custom fetch libraries.
31
+ */
32
+ fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
33
+ }
34
+ /**
35
+ * BukkuAPIError class for handling API specific errors.
36
+ */
37
+ export declare class BukkuAPIError extends Error {
38
+ status?: number | undefined;
39
+ responseData?: any | undefined;
40
+ constructor(message: string, status?: number | undefined, responseData?: any | undefined);
41
+ }
42
+ export type { ListType, GetListsRequestBody, GetListsResponse, CountryItem, TermItem, CurrencyItem, CurrenciesList, StandardListData, };
43
+ /**
44
+ * A TypeScript client for interacting with the Bukku REST API.
45
+ */
46
+ export declare class BukkuClient {
47
+ private readonly accessToken;
48
+ private readonly companySubdomain;
49
+ private readonly apiBaseUrl;
50
+ private readonly fetchImplementation;
51
+ readonly sales: SalesAPI;
52
+ readonly purchases: PurchasesAPI;
53
+ readonly contacts: ContactsAPI;
54
+ readonly products: ProductsAPI;
55
+ readonly accounting: AccountingAPI;
56
+ readonly lists: ListsAPI;
57
+ /**
58
+ * Creates an instance of the BukkuClient.
59
+ * @param options - Configuration options for the client.
60
+ */
61
+ constructor(options: BukkuClientOptions);
62
+ /**
63
+ * A private helper method to make authenticated requests to the Bukku API.
64
+ * @param endpoint - The API endpoint (e.g., '/v1/invoices').
65
+ * @param method - HTTP method (GET, POST, PUT, DELETE, etc.).
66
+ * @param body - Optional request body for POST/PUT requests.
67
+ * @param queryParams - Optional query parameters.
68
+ * @returns A Promise resolving to the JSON response from the API.
69
+ * @throws BukkuAPIError if the API returns an error.
70
+ */
71
+ private _request;
72
+ }
73
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EACV,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC7E;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IAG7B,MAAM,CAAC,EAAE,MAAM;IACf,YAAY,CAAC,EAAE,GAAG;gBAFzB,OAAO,EAAE,MAAM,EACR,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,YAAY,CAAC,EAAE,GAAG,YAAA;CAO5B;AAGD,YAAY,EACV,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,CAAC;AAEF;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAGb;IAEvB,SAAgB,KAAK,EAAE,QAAQ,CAAC;IAChC,SAAgB,SAAS,EAAE,YAAY,CAAC;IACxC,SAAgB,QAAQ,EAAE,WAAW,CAAC;IACtC,SAAgB,QAAQ,EAAE,WAAW,CAAC;IACtC,SAAgB,UAAU,EAAE,aAAa,CAAC;IAC1C,SAAgB,KAAK,EAAE,QAAQ,CAAC;IAEhC;;;OAGG;gBACS,OAAO,EAAE,kBAAkB;IA4CvC;;;;;;;;OAQG;YACW,QAAQ;CAiEvB"}
package/dist/index.js ADDED
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ // src/index.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.BukkuClient = exports.BukkuAPIError = void 0;
5
+ const url_1 = require("url"); // Using 'url' module for robust URL handling
6
+ const sales_1 = require("./sales");
7
+ const purchases_1 = require("./purchases");
8
+ const contacts_1 = require("./contacts");
9
+ const products_1 = require("./products");
10
+ const accounting_1 = require("./accounting");
11
+ const lists_1 = require("./lists");
12
+ /**
13
+ * BukkuAPIError class for handling API specific errors.
14
+ */
15
+ class BukkuAPIError extends Error {
16
+ constructor(message, status, responseData) {
17
+ super(message);
18
+ this.status = status;
19
+ this.responseData = responseData;
20
+ this.name = "BukkuAPIError";
21
+ // Set the prototype explicitly.
22
+ Object.setPrototypeOf(this, BukkuAPIError.prototype);
23
+ }
24
+ }
25
+ exports.BukkuAPIError = BukkuAPIError;
26
+ /**
27
+ * A TypeScript client for interacting with the Bukku REST API.
28
+ */
29
+ class BukkuClient {
30
+ /**
31
+ * Creates an instance of the BukkuClient.
32
+ * @param options - Configuration options for the client.
33
+ */
34
+ constructor(options) {
35
+ if (!options.accessToken) {
36
+ throw new Error("Bukku API Access Token (accessToken) is required.");
37
+ }
38
+ if (!options.companySubdomain) {
39
+ throw new Error("Bukku Company Subdomain (companySubdomain) is required.");
40
+ }
41
+ this.accessToken = options.accessToken;
42
+ this.companySubdomain = options.companySubdomain;
43
+ this.apiBaseUrl = options.apiBaseUrl;
44
+ if (options.fetch) {
45
+ this.fetchImplementation = options.fetch;
46
+ }
47
+ else if (typeof fetch !== "undefined") {
48
+ this.fetchImplementation = fetch;
49
+ }
50
+ else {
51
+ // This error will be thrown if global fetch is not available and no polyfill is provided.
52
+ // For Node.js < 18, users will need to pass a fetch polyfill (e.g., node-fetch).
53
+ throw new Error("Global fetch is not available. Please provide a fetch implementation in BukkuClientOptions or use Node.js v18+.");
54
+ }
55
+ // Validate apiBaseUrl
56
+ try {
57
+ new url_1.URL(this.apiBaseUrl);
58
+ }
59
+ catch (error) {
60
+ throw new Error(`Invalid apiBaseUrl: ${this.apiBaseUrl}. It must be a valid URL.`);
61
+ }
62
+ // Initialize API modules
63
+ this.sales = new sales_1.SalesAPI(this._request.bind(this));
64
+ this.purchases = new purchases_1.PurchasesAPI(this._request.bind(this));
65
+ this.contacts = new contacts_1.ContactsAPI(this._request.bind(this));
66
+ this.products = new products_1.ProductsAPI(this._request.bind(this));
67
+ this.accounting = new accounting_1.AccountingAPI(this._request.bind(this));
68
+ this.lists = new lists_1.ListsAPI(this._request.bind(this));
69
+ }
70
+ /**
71
+ * A private helper method to make authenticated requests to the Bukku API.
72
+ * @param endpoint - The API endpoint (e.g., '/v1/invoices').
73
+ * @param method - HTTP method (GET, POST, PUT, DELETE, etc.).
74
+ * @param body - Optional request body for POST/PUT requests.
75
+ * @param queryParams - Optional query parameters.
76
+ * @returns A Promise resolving to the JSON response from the API.
77
+ * @throws BukkuAPIError if the API returns an error.
78
+ */
79
+ async _request(endpoint, method, // Add other methods as needed
80
+ body, queryParams) {
81
+ const url = new url_1.URL(endpoint, this.apiBaseUrl);
82
+ if (queryParams) {
83
+ Object.entries(queryParams).forEach(([key, value]) => {
84
+ url.searchParams.append(key, String(value));
85
+ });
86
+ }
87
+ const headers = {
88
+ Authorization: `Bearer ${this.accessToken}`,
89
+ "Company-Subdomain": this.companySubdomain,
90
+ Accept: "application/json",
91
+ };
92
+ if (body) {
93
+ headers["Content-Type"] = "application/json";
94
+ }
95
+ const config = {
96
+ method,
97
+ headers,
98
+ body: body ? JSON.stringify(body) : undefined,
99
+ };
100
+ try {
101
+ const response = await this.fetchImplementation(url.toString(), config);
102
+ if (!response.ok) {
103
+ // Attempt to parse error response, but don't fail if it's not JSON
104
+ let errorData;
105
+ try {
106
+ errorData = await response.json();
107
+ }
108
+ catch (e) {
109
+ // If response is not JSON, use text
110
+ errorData = await response.text();
111
+ }
112
+ throw new BukkuAPIError(`API request failed: ${response.status} ${response.statusText}`, response.status, errorData);
113
+ }
114
+ // Handle cases where response might be empty (e.g., 204 No Content)
115
+ if (response.status === 204) {
116
+ return {}; // Or handle as undefined based on preference
117
+ }
118
+ return (await response.json());
119
+ }
120
+ catch (error) {
121
+ if (error instanceof BukkuAPIError) {
122
+ throw error;
123
+ }
124
+ // Catch network errors or other issues not originating from the API's HTTP response
125
+ throw new BukkuAPIError(error instanceof Error ? error.message : String(error));
126
+ }
127
+ }
128
+ }
129
+ exports.BukkuClient = BukkuClient;
130
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,eAAe;;;AAEf,6BAA0B,CAAC,6CAA6C;AACxE,mCAAmC;AACnC,2CAA2C;AAC3C,yCAAyC;AACzC,yCAAyC;AACzC,6CAA6C;AAC7C,mCAAmC;AAyCnC;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IACtC,YACE,OAAe,EACR,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;YACd,CAAC;YACD,oFAAoF;YACpF,MAAM,IAAI,aAAa,CACrB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA1ID,kCA0IC"}
@@ -0,0 +1,24 @@
1
+ import type { BukkuAPIRequestFunction } from "../types";
2
+ import type { GetListsRequestBody, GetListsResponse } from "./type";
3
+ /**
4
+ * Provides access to the Lists API endpoints.
5
+ * Currently, this handles the generic POST /v2/lists endpoint.
6
+ */
7
+ export declare class ListsAPI {
8
+ private request;
9
+ /**
10
+ * Initializes the ListsAPI with the BukkuAPIRequestFunction.
11
+ * @param request - The function to make authenticated API requests.
12
+ */
13
+ constructor(request: BukkuAPIRequestFunction);
14
+ /**
15
+ * Fetches multiple types of lists from the Bukku API.
16
+ * Corresponds to the POST /v2/lists endpoint.
17
+ *
18
+ * @param body - The request body specifying which lists to fetch and any associated parameters.
19
+ * @returns A Promise resolving to the API response containing the requested lists.
20
+ * @throws BukkuAPIError if the API returns an error.
21
+ */
22
+ get(body: GetListsRequestBody): Promise<GetListsResponse>;
23
+ }
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lists/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAEpE;;;GAGG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAA0B;IAEzC;;;OAGG;gBACS,OAAO,EAAE,uBAAuB;IAI5C;;;;;;;OAOG;IACG,GAAG,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAMhE"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // bukku/src/lists/index.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ListsAPI = void 0;
5
+ /**
6
+ * Provides access to the Lists API endpoints.
7
+ * Currently, this handles the generic POST /v2/lists endpoint.
8
+ */
9
+ class ListsAPI {
10
+ /**
11
+ * Initializes the ListsAPI with the BukkuAPIRequestFunction.
12
+ * @param request - The function to make authenticated API requests.
13
+ */
14
+ constructor(request) {
15
+ this.request = request;
16
+ }
17
+ /**
18
+ * Fetches multiple types of lists from the Bukku API.
19
+ * Corresponds to the POST /v2/lists endpoint.
20
+ *
21
+ * @param body - The request body specifying which lists to fetch and any associated parameters.
22
+ * @returns A Promise resolving to the API response containing the requested lists.
23
+ * @throws BukkuAPIError if the API returns an error.
24
+ */
25
+ async get(body) {
26
+ if (!body || !body.lists || body.lists.length === 0) {
27
+ throw new Error("The 'lists' array in the request body is required and cannot be empty.");
28
+ }
29
+ return this.request("/v2/lists", "POST", body);
30
+ }
31
+ }
32
+ exports.ListsAPI = ListsAPI;
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lists/index.ts"],"names":[],"mappings":";AAAA,2BAA2B;;;AAK3B;;;GAGG;AACH,MAAa,QAAQ;IAGnB;;;OAGG;IACH,YAAY,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,IAAyB;QACjC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;QAC5F,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAmB,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACnE,CAAC;CACF;AAzBD,4BAyBC"}