lua-cli 2.2.8-alpha.1 → 2.3.0-alpha.1

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 (191) hide show
  1. package/API_REFERENCE.md +1408 -0
  2. package/CLI_REFERENCE.md +818 -0
  3. package/GETTING_STARTED.md +1040 -0
  4. package/README.md +738 -424
  5. package/TEMPLATE_GUIDE.md +1398 -0
  6. package/dist/api/agent.api.service.d.ts +45 -0
  7. package/dist/api/agent.api.service.js +57 -0
  8. package/dist/api/auth.api.service.d.ts +48 -0
  9. package/dist/api/auth.api.service.js +54 -0
  10. package/dist/api/basket.api.service.d.ts +85 -0
  11. package/dist/api/basket.api.service.js +164 -0
  12. package/dist/api/chat.api.service.d.ts +21 -0
  13. package/dist/api/chat.api.service.js +24 -0
  14. package/dist/api/credentials.d.ts +24 -0
  15. package/dist/api/credentials.js +46 -0
  16. package/dist/api/custom.data.api.service.d.ts +69 -0
  17. package/dist/api/custom.data.api.service.js +125 -0
  18. package/dist/api/lazy-instances.d.ts +49 -0
  19. package/dist/api/lazy-instances.js +95 -0
  20. package/dist/api/order.api.service.d.ts +53 -0
  21. package/dist/api/order.api.service.js +95 -0
  22. package/dist/api/products.api.service.d.ts +66 -0
  23. package/dist/api/products.api.service.js +112 -0
  24. package/dist/api/skills.api.service.d.ts +77 -0
  25. package/dist/api/skills.api.service.js +88 -0
  26. package/dist/api/tool.api.service.d.ts +52 -0
  27. package/dist/api/tool.api.service.js +73 -0
  28. package/dist/api/user.data.api.service.d.ts +33 -0
  29. package/dist/api/user.data.api.service.js +59 -0
  30. package/dist/api-exports.d.ts +271 -0
  31. package/dist/api-exports.js +372 -0
  32. package/dist/cli/command-definitions.d.ts +30 -0
  33. package/dist/cli/command-definitions.js +71 -0
  34. package/dist/commands/agents.d.ts +20 -0
  35. package/dist/commands/agents.js +24 -2
  36. package/dist/commands/apiKey.d.ts +23 -0
  37. package/dist/commands/apiKey.js +23 -0
  38. package/dist/commands/compile.d.ts +24 -0
  39. package/dist/commands/compile.js +67 -759
  40. package/dist/commands/configure.d.ts +24 -0
  41. package/dist/commands/configure.js +31 -96
  42. package/dist/commands/deploy.d.ts +31 -19
  43. package/dist/commands/deploy.js +45 -74
  44. package/dist/commands/destroy.d.ts +27 -0
  45. package/dist/commands/destroy.js +27 -1
  46. package/dist/commands/dev.d.ts +25 -62
  47. package/dist/commands/dev.js +58 -873
  48. package/dist/commands/init.d.ts +27 -0
  49. package/dist/commands/init.js +98 -260
  50. package/dist/commands/push.d.ts +24 -21
  51. package/dist/commands/push.js +39 -92
  52. package/dist/commands/test.d.ts +26 -0
  53. package/dist/commands/test.js +41 -188
  54. package/dist/common/basket.instance.d.ts +78 -0
  55. package/dist/common/basket.instance.js +132 -0
  56. package/dist/common/data.entry.instance.d.ts +39 -0
  57. package/dist/common/data.entry.instance.js +76 -0
  58. package/dist/common/http.client.d.ts +64 -0
  59. package/dist/common/http.client.js +133 -0
  60. package/dist/common/order.instance.d.ts +40 -0
  61. package/dist/common/order.instance.js +79 -0
  62. package/dist/common/product.instance.d.ts +33 -0
  63. package/dist/common/product.instance.js +63 -0
  64. package/dist/common/product.pagination.instance.d.ts +43 -0
  65. package/dist/common/product.pagination.instance.js +74 -0
  66. package/dist/common/product.search.instance.d.ts +22 -0
  67. package/dist/common/product.search.instance.js +40 -0
  68. package/dist/common/user.instance.d.ts +41 -0
  69. package/dist/common/user.instance.js +84 -0
  70. package/dist/config/auth.constants.d.ts +11 -0
  71. package/dist/config/auth.constants.js +11 -0
  72. package/dist/config/compile.constants.d.ts +67 -0
  73. package/dist/config/compile.constants.js +99 -0
  74. package/dist/config/constants.d.ts +5 -0
  75. package/dist/config/constants.js +5 -0
  76. package/dist/config/dev.constants.d.ts +65 -0
  77. package/dist/config/dev.constants.js +79 -0
  78. package/dist/config/init.constants.d.ts +23 -0
  79. package/dist/config/init.constants.js +41 -0
  80. package/dist/index.d.ts +19 -3
  81. package/dist/index.js +28 -44
  82. package/dist/interfaces/admin.d.ts +101 -0
  83. package/dist/interfaces/admin.js +5 -0
  84. package/dist/interfaces/agent.d.ts +107 -0
  85. package/dist/interfaces/agent.js +5 -0
  86. package/dist/interfaces/baskets.d.ts +135 -0
  87. package/dist/interfaces/baskets.js +19 -0
  88. package/dist/interfaces/chat.d.ts +61 -0
  89. package/dist/interfaces/chat.js +5 -0
  90. package/dist/interfaces/common.d.ts +62 -0
  91. package/dist/interfaces/common.js +8 -0
  92. package/dist/interfaces/compile.d.ts +11 -0
  93. package/dist/interfaces/compile.js +4 -0
  94. package/dist/interfaces/custom.data.d.ts +82 -0
  95. package/dist/interfaces/custom.data.js +5 -0
  96. package/dist/interfaces/deploy.d.ts +29 -0
  97. package/dist/interfaces/deploy.js +4 -0
  98. package/dist/interfaces/dev.d.ts +53 -0
  99. package/dist/interfaces/dev.js +5 -0
  100. package/dist/interfaces/init.d.ts +60 -0
  101. package/dist/interfaces/init.js +4 -0
  102. package/dist/interfaces/orders.d.ts +91 -0
  103. package/dist/interfaces/orders.js +19 -0
  104. package/dist/interfaces/product.d.ts +65 -0
  105. package/dist/interfaces/product.js +5 -0
  106. package/dist/interfaces/push.d.ts +26 -0
  107. package/dist/interfaces/push.js +4 -0
  108. package/dist/interfaces/test.d.ts +36 -0
  109. package/dist/interfaces/test.js +4 -0
  110. package/dist/services/auth.d.ts +54 -99
  111. package/dist/services/auth.js +76 -12
  112. package/dist/types/api-contracts.d.ts +211 -0
  113. package/dist/types/api-contracts.js +8 -0
  114. package/dist/types/compile.types.d.ts +76 -0
  115. package/dist/types/compile.types.js +4 -0
  116. package/dist/types/index.d.ts +23 -85
  117. package/dist/types/index.js +25 -14
  118. package/dist/types/skill.d.ts +142 -0
  119. package/dist/{skill.js → types/skill.js} +66 -19
  120. package/dist/types/tool-validation.d.ts +34 -0
  121. package/dist/types/tool-validation.js +42 -0
  122. package/dist/utils/auth-flows.d.ts +26 -0
  123. package/dist/utils/auth-flows.js +141 -0
  124. package/dist/utils/bundling.d.ts +36 -0
  125. package/dist/utils/bundling.js +137 -0
  126. package/dist/utils/compile.d.ts +37 -0
  127. package/dist/utils/compile.js +242 -0
  128. package/dist/utils/deploy-api.d.ts +26 -0
  129. package/dist/utils/deploy-api.js +53 -0
  130. package/dist/utils/deploy-helpers.d.ts +46 -0
  131. package/dist/utils/deploy-helpers.js +86 -0
  132. package/dist/utils/deployment.d.ts +25 -0
  133. package/dist/utils/deployment.js +161 -0
  134. package/dist/utils/dev-api.d.ts +61 -0
  135. package/dist/utils/dev-api.js +262 -0
  136. package/dist/utils/dev-helpers.d.ts +46 -0
  137. package/dist/utils/dev-helpers.js +83 -0
  138. package/dist/utils/dev-server.d.ts +24 -0
  139. package/dist/utils/dev-server.js +555 -0
  140. package/dist/utils/dev-watcher.d.ts +31 -0
  141. package/dist/utils/dev-watcher.js +110 -0
  142. package/dist/utils/files.js +0 -5
  143. package/dist/utils/init-agent.d.ts +34 -0
  144. package/dist/utils/init-agent.js +129 -0
  145. package/dist/utils/init-helpers.d.ts +41 -0
  146. package/dist/utils/init-helpers.js +73 -0
  147. package/dist/utils/init-prompts.d.ts +47 -0
  148. package/dist/utils/init-prompts.js +168 -0
  149. package/dist/utils/push-api.d.ts +15 -0
  150. package/dist/utils/push-api.js +48 -0
  151. package/dist/utils/push-helpers.d.ts +38 -0
  152. package/dist/utils/push-helpers.js +84 -0
  153. package/dist/utils/sandbox-storage.d.ts +27 -0
  154. package/dist/utils/sandbox-storage.js +71 -0
  155. package/dist/utils/sandbox.js +78 -118
  156. package/dist/utils/skill-management.d.ts +14 -0
  157. package/dist/utils/skill-management.js +148 -0
  158. package/dist/utils/test-helpers.d.ts +40 -0
  159. package/dist/utils/test-helpers.js +92 -0
  160. package/dist/utils/test-prompts.d.ts +23 -0
  161. package/dist/utils/test-prompts.js +186 -0
  162. package/dist/utils/tool-detection.d.ts +18 -0
  163. package/dist/utils/tool-detection.js +110 -0
  164. package/dist/web/app.css +14 -9
  165. package/package.json +11 -12
  166. package/template/QUICKSTART.md +299 -144
  167. package/template/README.md +928 -349
  168. package/template/TOOL_EXAMPLES.md +655 -0
  169. package/template/package-lock.json +3781 -0
  170. package/template/package.json +1 -1
  171. package/template/src/index.ts +81 -40
  172. package/template/src/tools/BasketTool.ts +128 -0
  173. package/template/src/tools/CustomDataTool.ts +7 -13
  174. package/template/src/tools/OrderTool.ts +54 -0
  175. package/template/src/tools/PaymentTool.ts +1 -1
  176. package/template/src/tools/ProductsTool.ts +56 -118
  177. package/template/src/tools/UserDataTool.ts +4 -27
  178. package/dist/custom-data-api.d.ts +0 -72
  179. package/dist/custom-data-api.js +0 -174
  180. package/dist/product-api.d.ts +0 -197
  181. package/dist/product-api.js +0 -152
  182. package/dist/services/api.d.ts +0 -569
  183. package/dist/services/api.js +0 -625
  184. package/dist/skill.d.ts +0 -50
  185. package/dist/types.d.ts +0 -1
  186. package/dist/types.js +0 -2
  187. package/dist/user-data-api.d.ts +0 -39
  188. package/dist/user-data-api.js +0 -50
  189. package/template/API.md +0 -604
  190. package/template/DEVELOPER.md +0 -771
  191. package/template/lua.skill.yaml +0 -16
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Generic HTTP client with common error handling
3
+ * Provides a base class for all API service classes with standardized HTTP methods
4
+ */
5
+ export class HttpClient {
6
+ /**
7
+ * Creates an instance of HttpClient
8
+ * @param baseUrl - The base URL for all API requests
9
+ */
10
+ constructor(baseUrl) {
11
+ this.baseUrl = baseUrl;
12
+ }
13
+ /**
14
+ * Makes an HTTP request with standardized error handling
15
+ * @param url - The full URL to request
16
+ * @param options - Fetch API request options
17
+ * @returns Promise resolving to an ApiResponse with typed data
18
+ * @private
19
+ */
20
+ async request(url, options = {}) {
21
+ try {
22
+ const response = await fetch(url, {
23
+ ...options,
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ ...options.headers,
27
+ },
28
+ });
29
+ // Check if response is ok (status 200-299)
30
+ if (!response.ok) {
31
+ return {
32
+ success: false,
33
+ error: {
34
+ message: `HTTP ${response.status}: ${response.statusText}`,
35
+ statusCode: response.status,
36
+ },
37
+ };
38
+ }
39
+ // Try to parse JSON response
40
+ let data;
41
+ try {
42
+ data = await response.json();
43
+ }
44
+ catch (jsonError) {
45
+ data = {};
46
+ }
47
+ // If the response already has the ApiResponse structure, return it
48
+ if (typeof data === 'object' && data !== null && 'success' in data) {
49
+ return data;
50
+ }
51
+ // Otherwise, wrap the data in a successful ApiResponse
52
+ return {
53
+ success: true,
54
+ data,
55
+ };
56
+ }
57
+ catch (error) {
58
+ // Handle network errors, timeouts, etc.
59
+ return {
60
+ success: false,
61
+ error: {
62
+ message: error instanceof Error ? error.message : 'Network request failed',
63
+ statusCode: 0, // Use 0 to indicate network/connection error
64
+ },
65
+ };
66
+ }
67
+ }
68
+ /**
69
+ * Performs an HTTP GET request
70
+ * @param url - The relative URL path to request (will be appended to baseUrl)
71
+ * @param headers - Optional HTTP headers to include in the request
72
+ * @returns Promise resolving to an ApiResponse with typed data
73
+ * @protected
74
+ */
75
+ async httpGet(url, headers) {
76
+ return this.request(this.baseUrl + url, { method: 'GET', headers });
77
+ }
78
+ /**
79
+ * Performs an HTTP POST request
80
+ * @param url - The relative URL path to request (will be appended to baseUrl)
81
+ * @param data - Optional request body data (will be JSON stringified)
82
+ * @param headers - Optional HTTP headers to include in the request
83
+ * @returns Promise resolving to an ApiResponse with typed data
84
+ * @protected
85
+ */
86
+ async httpPost(url, data, headers) {
87
+ return this.request(this.baseUrl + url, {
88
+ method: 'POST',
89
+ body: data ? JSON.stringify(data) : undefined,
90
+ headers,
91
+ });
92
+ }
93
+ /**
94
+ * Performs an HTTP PUT request
95
+ * @param url - The relative URL path to request (will be appended to baseUrl)
96
+ * @param data - Optional request body data (will be JSON stringified)
97
+ * @param headers - Optional HTTP headers to include in the request
98
+ * @returns Promise resolving to an ApiResponse with typed data
99
+ * @protected
100
+ */
101
+ async httpPut(url, data, headers) {
102
+ return this.request(this.baseUrl + url, {
103
+ method: 'PUT',
104
+ body: data ? JSON.stringify(data) : undefined,
105
+ headers,
106
+ });
107
+ }
108
+ /**
109
+ * Performs an HTTP DELETE request
110
+ * @param url - The relative URL path to request (will be appended to baseUrl)
111
+ * @param headers - Optional HTTP headers to include in the request
112
+ * @returns Promise resolving to an ApiResponse with typed data
113
+ * @protected
114
+ */
115
+ async httpDelete(url, headers) {
116
+ return this.request(this.baseUrl + url, { method: 'DELETE', headers });
117
+ }
118
+ /**
119
+ * Performs an HTTP PATCH request
120
+ * @param url - The relative URL path to request (will be appended to baseUrl)
121
+ * @param data - Optional request body data (will be JSON stringified)
122
+ * @param headers - Optional HTTP headers to include in the request
123
+ * @returns Promise resolving to an ApiResponse with typed data
124
+ * @protected
125
+ */
126
+ async httpPatch(url, data, headers) {
127
+ return this.request(this.baseUrl + url, {
128
+ method: 'PATCH',
129
+ body: data ? JSON.stringify(data) : undefined,
130
+ headers,
131
+ });
132
+ }
133
+ }
@@ -0,0 +1,40 @@
1
+ import OrderApi from "../api/order.api.service.js";
2
+ import { OrderResponse, OrderStatus } from "../interfaces/orders.js";
3
+ /**
4
+ * Order instance class providing a fluent API for managing orders
5
+ * Provides methods for updating order status and order data
6
+ */
7
+ export default class OrderInstance {
8
+ private data;
9
+ private common;
10
+ private id;
11
+ private userId;
12
+ private agentId;
13
+ private orderId;
14
+ private orderAPI;
15
+ /**
16
+ * Creates a new OrderInstance
17
+ * @param api - The OrderApi instance for making API calls
18
+ * @param order - The order response data from the API
19
+ */
20
+ constructor(api: OrderApi, order: OrderResponse);
21
+ /**
22
+ * Custom toJSON method to control what gets serialized when logging
23
+ * @returns Serialized order data combining data and common fields
24
+ */
25
+ toJSON(): Record<string, any>;
26
+ /**
27
+ * Updates the order's status
28
+ * @param status - The new order status (e.g., 'pending', 'processing', 'shipped', 'delivered', 'cancelled')
29
+ * @returns Promise resolving to the updated order data
30
+ * @throws Error if the status update fails
31
+ */
32
+ updateStatus(status: OrderStatus): Promise<any>;
33
+ /**
34
+ * Updates the order's data
35
+ * @param data - The data fields to update (e.g., shipping info, notes, metadata)
36
+ * @returns Promise resolving to the updated order data
37
+ * @throws Error if the data update fails
38
+ */
39
+ update(data: Record<string, any>): Promise<any>;
40
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Order instance class providing a fluent API for managing orders
3
+ * Provides methods for updating order status and order data
4
+ */
5
+ export default class OrderInstance {
6
+ /**
7
+ * Creates a new OrderInstance
8
+ * @param api - The OrderApi instance for making API calls
9
+ * @param order - The order response data from the API
10
+ */
11
+ constructor(api, order) {
12
+ this.data = order.data;
13
+ this.common = order.common;
14
+ this.id = order.id;
15
+ this.userId = order.userId;
16
+ this.agentId = order.agentId;
17
+ this.orderId = order.orderId;
18
+ // Make orderAPI non-enumerable so it doesn't show up in console.log
19
+ Object.defineProperty(this, 'orderAPI', {
20
+ value: api,
21
+ writable: true,
22
+ enumerable: false,
23
+ configurable: true
24
+ });
25
+ }
26
+ /**
27
+ * Custom toJSON method to control what gets serialized when logging
28
+ * @returns Serialized order data combining data and common fields
29
+ */
30
+ toJSON() {
31
+ return {
32
+ ...this.data,
33
+ ...this.common,
34
+ id: this.id
35
+ };
36
+ }
37
+ /**
38
+ * Custom inspect method for Node.js console.log
39
+ * @returns Formatted order data for console output
40
+ */
41
+ [Symbol.for('nodejs.util.inspect.custom')]() {
42
+ return {
43
+ ...this.data,
44
+ ...this.common,
45
+ id: this.id
46
+ };
47
+ }
48
+ /**
49
+ * Updates the order's status
50
+ * @param status - The new order status (e.g., 'pending', 'processing', 'shipped', 'delivered', 'cancelled')
51
+ * @returns Promise resolving to the updated order data
52
+ * @throws Error if the status update fails
53
+ */
54
+ async updateStatus(status) {
55
+ const response = await this.orderAPI.updateStatus(status, this.id);
56
+ this.common = response.common;
57
+ return {
58
+ ...this.data,
59
+ ...this.common,
60
+ id: this.id
61
+ };
62
+ }
63
+ /**
64
+ * Updates the order's data
65
+ * @param data - The data fields to update (e.g., shipping info, notes, metadata)
66
+ * @returns Promise resolving to the updated order data
67
+ * @throws Error if the data update fails
68
+ */
69
+ async update(data) {
70
+ const response = await this.orderAPI.updateData(data, this.id);
71
+ this.data = response.data;
72
+ this.common = response.common;
73
+ return {
74
+ ...this.data,
75
+ ...this.common,
76
+ id: this.id
77
+ };
78
+ }
79
+ }
@@ -0,0 +1,33 @@
1
+ import { Product } from "../interfaces/product.js";
2
+ /**
3
+ * Product instance class providing a fluent API for managing individual products
4
+ * Provides methods for updating and deleting products
5
+ */
6
+ export default class ProductInstance {
7
+ data: Product;
8
+ private productAPI;
9
+ /**
10
+ * Creates a new ProductInstance
11
+ * @param api - The ProductAPI instance for making API calls
12
+ * @param product - The product data from the API
13
+ */
14
+ constructor(api: any, product: Product);
15
+ /**
16
+ * Custom toJSON method to control what gets serialized when logging
17
+ * @returns Serialized product data
18
+ */
19
+ toJSON(): Record<string, any>;
20
+ /**
21
+ * Updates the product's data
22
+ * @param data - The product fields to update (partial update supported)
23
+ * @returns Promise resolving to the updated Product
24
+ * @throws Error if the update fails or the product is not found
25
+ */
26
+ update(data: Record<string, any>): Promise<Product>;
27
+ /**
28
+ * Deletes the product from the catalog
29
+ * @returns Promise resolving to an empty Product object if deletion was successful
30
+ * @throws Error if the deletion fails or the product is not found
31
+ */
32
+ delete(): Promise<Product>;
33
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Product instance class providing a fluent API for managing individual products
3
+ * Provides methods for updating and deleting products
4
+ */
5
+ export default class ProductInstance {
6
+ /**
7
+ * Creates a new ProductInstance
8
+ * @param api - The ProductAPI instance for making API calls
9
+ * @param product - The product data from the API
10
+ */
11
+ constructor(api, product) {
12
+ this.data = product;
13
+ // Make productAPI non-enumerable so it doesn't show up in console.log
14
+ Object.defineProperty(this, 'productAPI', {
15
+ value: api,
16
+ writable: true,
17
+ enumerable: false,
18
+ configurable: true
19
+ });
20
+ }
21
+ /**
22
+ * Custom toJSON method to control what gets serialized when logging
23
+ * @returns Serialized product data
24
+ */
25
+ toJSON() {
26
+ return this.data;
27
+ }
28
+ /**
29
+ * Custom inspect method for Node.js console.log
30
+ * @returns Formatted product data for console output
31
+ */
32
+ [Symbol.for('nodejs.util.inspect.custom')]() {
33
+ return this.data;
34
+ }
35
+ /**
36
+ * Updates the product's data
37
+ * @param data - The product fields to update (partial update supported)
38
+ * @returns Promise resolving to the updated Product
39
+ * @throws Error if the update fails or the product is not found
40
+ */
41
+ async update(data) {
42
+ const response = await this.productAPI.update(data, this.data.id);
43
+ if (response.updated) {
44
+ this.data = response.product;
45
+ return this.data;
46
+ }
47
+ else {
48
+ throw new Error('Failed to update product');
49
+ }
50
+ }
51
+ /**
52
+ * Deletes the product from the catalog
53
+ * @returns Promise resolving to an empty Product object if deletion was successful
54
+ * @throws Error if the deletion fails or the product is not found
55
+ */
56
+ async delete() {
57
+ const response = await this.productAPI.delete(this.data.id);
58
+ if (response.deleted) {
59
+ this.data = {};
60
+ }
61
+ return this.data;
62
+ }
63
+ }
@@ -0,0 +1,43 @@
1
+ import { ProductsResponse } from "../interfaces/product.js";
2
+ import ProductInstance from "./product.instance.js";
3
+ /**
4
+ * Product pagination instance class providing a fluent API for paginated product results
5
+ * Provides methods for navigating through pages of products
6
+ */
7
+ export default class ProductPaginationInstance {
8
+ products: ProductInstance[];
9
+ pagination: {
10
+ currentPage: number;
11
+ totalPages: number;
12
+ totalCount: number;
13
+ limit: number;
14
+ hasNextPage: boolean;
15
+ hasPrevPage: boolean;
16
+ nextPage: number | null;
17
+ prevPage: number | null;
18
+ };
19
+ private productAPI;
20
+ /**
21
+ * Creates a new ProductPaginationInstance
22
+ * @param api - The ProductAPI instance for making API calls
23
+ * @param results - The paginated product results from the API
24
+ */
25
+ constructor(api: any, results: ProductsResponse);
26
+ /**
27
+ * Custom toJSON method to control what gets serialized when logging
28
+ * @returns Serialized products and pagination data
29
+ */
30
+ toJSON(): Record<string, any>;
31
+ /**
32
+ * Fetches the next page of products
33
+ * @returns Promise resolving to a new ProductPaginationInstance for the next page
34
+ * @throws Error if there is no next page available
35
+ */
36
+ nextPage(): Promise<ProductPaginationInstance>;
37
+ /**
38
+ * Fetches the previous page of products
39
+ * @returns Promise resolving to a new ProductPaginationInstance for the previous page
40
+ * @throws Error if there is no previous page available
41
+ */
42
+ prevPage(): Promise<ProductPaginationInstance>;
43
+ }
@@ -0,0 +1,74 @@
1
+ import ProductInstance from "./product.instance.js";
2
+ /**
3
+ * Product pagination instance class providing a fluent API for paginated product results
4
+ * Provides methods for navigating through pages of products
5
+ */
6
+ export default class ProductPaginationInstance {
7
+ /**
8
+ * Creates a new ProductPaginationInstance
9
+ * @param api - The ProductAPI instance for making API calls
10
+ * @param results - The paginated product results from the API
11
+ */
12
+ constructor(api, results) {
13
+ this.products = results.data?.map(product => new ProductInstance(api, product)) || [];
14
+ this.pagination = results.pagination || {
15
+ currentPage: 1,
16
+ totalPages: 1,
17
+ totalCount: 0,
18
+ limit: 10,
19
+ hasNextPage: false,
20
+ hasPrevPage: false,
21
+ nextPage: null,
22
+ prevPage: null
23
+ };
24
+ // Make productAPI non-enumerable so it doesn't show up in console.log
25
+ Object.defineProperty(this, 'productAPI', {
26
+ value: api,
27
+ writable: true,
28
+ enumerable: false,
29
+ configurable: true
30
+ });
31
+ }
32
+ /**
33
+ * Custom toJSON method to control what gets serialized when logging
34
+ * @returns Serialized products and pagination data
35
+ */
36
+ toJSON() {
37
+ return {
38
+ products: this.products,
39
+ pagination: this.pagination
40
+ };
41
+ }
42
+ /**
43
+ * Custom inspect method for Node.js console.log
44
+ * @returns Formatted products and pagination data for console output
45
+ */
46
+ [Symbol.for('nodejs.util.inspect.custom')]() {
47
+ return {
48
+ products: this.products,
49
+ pagination: this.pagination
50
+ };
51
+ }
52
+ /**
53
+ * Fetches the next page of products
54
+ * @returns Promise resolving to a new ProductPaginationInstance for the next page
55
+ * @throws Error if there is no next page available
56
+ */
57
+ async nextPage() {
58
+ if (!this.pagination.nextPage) {
59
+ throw new Error('No next page');
60
+ }
61
+ return await this.productAPI.get(this.pagination.nextPage, this.pagination.limit);
62
+ }
63
+ /**
64
+ * Fetches the previous page of products
65
+ * @returns Promise resolving to a new ProductPaginationInstance for the previous page
66
+ * @throws Error if there is no previous page available
67
+ */
68
+ async prevPage() {
69
+ if (!this.pagination.prevPage) {
70
+ throw new Error('No previous page');
71
+ }
72
+ return await this.productAPI.get(this.pagination.prevPage, this.pagination.limit);
73
+ }
74
+ }
@@ -0,0 +1,22 @@
1
+ import { SearchProductsResponse } from "../interfaces/product.js";
2
+ import { ProductAPI } from "../types/index.js";
3
+ import ProductInstance from "./product.instance.js";
4
+ /**
5
+ * Product search instance class providing a fluent API for product search results
6
+ * Contains an array of ProductInstance objects matching the search query
7
+ */
8
+ export default class ProductSearchInstance {
9
+ products: ProductInstance[];
10
+ private productAPI;
11
+ /**
12
+ * Creates a new ProductSearchInstance
13
+ * @param api - The ProductAPI instance for making API calls
14
+ * @param results - The product search results from the API
15
+ */
16
+ constructor(api: ProductAPI, results: SearchProductsResponse);
17
+ /**
18
+ * Custom toJSON method to control what gets serialized when logging
19
+ * @returns Serialized search results with product data
20
+ */
21
+ toJSON(): Record<string, any>;
22
+ }
@@ -0,0 +1,40 @@
1
+ import ProductInstance from "./product.instance.js";
2
+ /**
3
+ * Product search instance class providing a fluent API for product search results
4
+ * Contains an array of ProductInstance objects matching the search query
5
+ */
6
+ export default class ProductSearchInstance {
7
+ /**
8
+ * Creates a new ProductSearchInstance
9
+ * @param api - The ProductAPI instance for making API calls
10
+ * @param results - The product search results from the API
11
+ */
12
+ constructor(api, results) {
13
+ this.products = results.data?.map(product => new ProductInstance(api, product)) || [];
14
+ // Make productAPI non-enumerable so it doesn't show up in console.log
15
+ Object.defineProperty(this, 'productAPI', {
16
+ value: api,
17
+ writable: true,
18
+ enumerable: false,
19
+ configurable: true
20
+ });
21
+ }
22
+ /**
23
+ * Custom toJSON method to control what gets serialized when logging
24
+ * @returns Serialized search results with product data
25
+ */
26
+ toJSON() {
27
+ return {
28
+ products: this.products,
29
+ };
30
+ }
31
+ /**
32
+ * Custom inspect method for Node.js console.log
33
+ * @returns Formatted search results for console output
34
+ */
35
+ [Symbol.for('nodejs.util.inspect.custom')]() {
36
+ return {
37
+ products: this.products,
38
+ };
39
+ }
40
+ }
@@ -0,0 +1,41 @@
1
+ import { UserData } from "../interfaces/admin.js";
2
+ import { UserDataAPI } from "../types/index.js";
3
+ /**
4
+ * User data instance class providing a fluent API for managing user data
5
+ * Automatically sanitizes sensitive fields and provides methods for updating and clearing data
6
+ */
7
+ export default class UserDataInstance {
8
+ data: Record<string, any>;
9
+ private userAPI;
10
+ /**
11
+ * Creates a new UserDataInstance
12
+ * @param api - The UserDataAPI instance for making API calls
13
+ * @param data - The user data from the API (will be sanitized automatically)
14
+ */
15
+ constructor(api: UserDataAPI, data: UserData);
16
+ /**
17
+ * Removes sensitive fields from the data before storing
18
+ * @param data - The raw user data to sanitize
19
+ * @returns Sanitized data with sensitive fields removed
20
+ * @private
21
+ */
22
+ private sanitizeData;
23
+ /**
24
+ * Custom toJSON method to control what gets serialized when logging
25
+ * @returns Serialized user data
26
+ */
27
+ toJSON(): Record<string, any>;
28
+ /**
29
+ * Updates the user's data
30
+ * @param data - The data fields to update or add to user data
31
+ * @returns Promise resolving to the updated sanitized user data
32
+ * @throws Error if the update fails
33
+ */
34
+ update(data: Record<string, any>): Promise<any>;
35
+ /**
36
+ * Clears all user data for the current user
37
+ * @returns Promise resolving to true if clearing was successful
38
+ * @throws Error if the clear operation fails
39
+ */
40
+ clear(): Promise<boolean>;
41
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * User data instance class providing a fluent API for managing user data
3
+ * Automatically sanitizes sensitive fields and provides methods for updating and clearing data
4
+ */
5
+ export default class UserDataInstance {
6
+ /**
7
+ * Creates a new UserDataInstance
8
+ * @param api - The UserDataAPI instance for making API calls
9
+ * @param data - The user data from the API (will be sanitized automatically)
10
+ */
11
+ constructor(api, data) {
12
+ this.data = this.sanitizeData(data);
13
+ // Make userAPI non-enumerable so it doesn't show up in console.log
14
+ Object.defineProperty(this, 'userAPI', {
15
+ value: api,
16
+ writable: true,
17
+ enumerable: false,
18
+ configurable: true
19
+ });
20
+ }
21
+ /**
22
+ * Removes sensitive fields from the data before storing
23
+ * @param data - The raw user data to sanitize
24
+ * @returns Sanitized data with sensitive fields removed
25
+ * @private
26
+ */
27
+ sanitizeData(data) {
28
+ if (!data || typeof data !== 'object') {
29
+ return data;
30
+ }
31
+ // Create a copy of the data to avoid mutating the original
32
+ const sanitized = { ...data };
33
+ // Remove sensitive fields
34
+ const sensitiveFields = ['apiKey', 'agentId', 'userId', 'token', 'secret', 'key'];
35
+ sensitiveFields.forEach(field => {
36
+ delete sanitized[field];
37
+ });
38
+ return sanitized;
39
+ }
40
+ /**
41
+ * Custom toJSON method to control what gets serialized when logging
42
+ * @returns Serialized user data
43
+ */
44
+ toJSON() {
45
+ return this.data;
46
+ }
47
+ /**
48
+ * Custom inspect method for Node.js console.log
49
+ * @returns Formatted user data for console output
50
+ */
51
+ [Symbol.for('nodejs.util.inspect.custom')]() {
52
+ return this.data;
53
+ }
54
+ /**
55
+ * Updates the user's data
56
+ * @param data - The data fields to update or add to user data
57
+ * @returns Promise resolving to the updated sanitized user data
58
+ * @throws Error if the update fails
59
+ */
60
+ async update(data) {
61
+ try {
62
+ const response = await this.userAPI.update(data);
63
+ this.data = this.sanitizeData(response.data);
64
+ return this.data;
65
+ }
66
+ catch (error) {
67
+ throw new Error('Failed to update user data');
68
+ }
69
+ }
70
+ /**
71
+ * Clears all user data for the current user
72
+ * @returns Promise resolving to true if clearing was successful
73
+ * @throws Error if the clear operation fails
74
+ */
75
+ async clear() {
76
+ try {
77
+ await this.userAPI.clear();
78
+ return true;
79
+ }
80
+ catch (error) {
81
+ throw new Error('Failed to clear user data');
82
+ }
83
+ }
84
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Constants for authentication service
3
+ */
4
+ /**
5
+ * Keytar service name for secure credential storage
6
+ */
7
+ export declare const KEYTAR_SERVICE = "lua-cli";
8
+ /**
9
+ * Keytar account name for API key storage
10
+ */
11
+ export declare const KEYTAR_ACCOUNT = "api-key";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Constants for authentication service
3
+ */
4
+ /**
5
+ * Keytar service name for secure credential storage
6
+ */
7
+ export const KEYTAR_SERVICE = "lua-cli";
8
+ /**
9
+ * Keytar account name for API key storage
10
+ */
11
+ export const KEYTAR_ACCOUNT = "api-key";