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,91 @@
1
+ /**
2
+ * Order Interfaces
3
+ * Order management and fulfillment
4
+ */
5
+ import { BasketItem } from "./baskets.js";
6
+ /**
7
+ * Order status enumeration.
8
+ * Represents the lifecycle states of an order.
9
+ */
10
+ export declare enum OrderStatus {
11
+ /** Order created but not yet confirmed */
12
+ PENDING = "pending",
13
+ /** Order confirmed and being processed */
14
+ CONFIRMED = "confirmed",
15
+ /** Order completed and delivered */
16
+ FULFILLED = "fulfilled",
17
+ /** Order cancelled */
18
+ CANCELLED = "cancelled"
19
+ }
20
+ /**
21
+ * Order data container.
22
+ * Contains the order details, items, and metadata.
23
+ */
24
+ export interface OrderData {
25
+ currency: string;
26
+ items: BasketItem[];
27
+ createdAt: string;
28
+ basketId: string;
29
+ orderDate: string;
30
+ orderId: string;
31
+ [key: string]: any;
32
+ }
33
+ /**
34
+ * Common order properties.
35
+ * Calculated/derived properties maintained by the system.
36
+ */
37
+ export interface OrderCommon {
38
+ status: 'pending' | 'confirmed' | 'fulfilled' | 'cancelled';
39
+ totalAmount: string | number;
40
+ currency: string;
41
+ itemCount: number;
42
+ }
43
+ /**
44
+ * Complete order entity.
45
+ * Full order object as stored in the database.
46
+ */
47
+ export interface OrderResponse {
48
+ id: string;
49
+ userId: string;
50
+ agentId: string;
51
+ orderId: string;
52
+ data: OrderData;
53
+ common: OrderCommon;
54
+ createdAt: string;
55
+ updatedAt: string;
56
+ __v: number;
57
+ }
58
+ /**
59
+ * Request to create a new order.
60
+ * Typically created from a basket.
61
+ */
62
+ export interface CreateOrderRequest {
63
+ basketId: string;
64
+ data: {
65
+ [key: string]: any;
66
+ };
67
+ }
68
+ /**
69
+ * Response from order creation.
70
+ */
71
+ export interface CreateOrderResponse {
72
+ success: boolean;
73
+ message: string;
74
+ data: OrderResponse;
75
+ }
76
+ /**
77
+ * Response from updating order status.
78
+ */
79
+ export interface UpdateOrderStatusResponse {
80
+ success: boolean;
81
+ message: string;
82
+ data: OrderResponse;
83
+ }
84
+ /**
85
+ * Response from getting user orders.
86
+ */
87
+ export interface GetUserOrdersResponse {
88
+ success: boolean;
89
+ message: string;
90
+ data: OrderResponse[];
91
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Order Interfaces
3
+ * Order management and fulfillment
4
+ */
5
+ /**
6
+ * Order status enumeration.
7
+ * Represents the lifecycle states of an order.
8
+ */
9
+ export var OrderStatus;
10
+ (function (OrderStatus) {
11
+ /** Order created but not yet confirmed */
12
+ OrderStatus["PENDING"] = "pending";
13
+ /** Order confirmed and being processed */
14
+ OrderStatus["CONFIRMED"] = "confirmed";
15
+ /** Order completed and delivered */
16
+ OrderStatus["FULFILLED"] = "fulfilled";
17
+ /** Order cancelled */
18
+ OrderStatus["CANCELLED"] = "cancelled";
19
+ })(OrderStatus || (OrderStatus = {}));
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Product Interfaces
3
+ * Product catalog management
4
+ */
5
+ import { Pagination } from './common.js';
6
+ /**
7
+ * Product entity.
8
+ * Flexible schema allows any properties to be stored.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const product: Product = {
13
+ * id: '123',
14
+ * name: 'Laptop',
15
+ * price: 999.99,
16
+ * category: 'Electronics',
17
+ * inStock: true
18
+ * };
19
+ * ```
20
+ */
21
+ export interface Product {
22
+ id: string;
23
+ [key: string]: any;
24
+ }
25
+ /**
26
+ * Response from get products API.
27
+ * Includes pagination for large catalogs.
28
+ */
29
+ export interface ProductsResponse {
30
+ success: boolean;
31
+ data?: Product[];
32
+ message?: string;
33
+ pagination?: Pagination;
34
+ }
35
+ /**
36
+ * Response from product creation.
37
+ * Indicates if product was newly created or updated existing.
38
+ */
39
+ export interface CreateProductResponse {
40
+ updated: boolean;
41
+ isNew: boolean;
42
+ product: Product;
43
+ }
44
+ /**
45
+ * Response from product update.
46
+ */
47
+ export interface UpdateProductResponse {
48
+ updated: boolean;
49
+ isNew: boolean;
50
+ product: Product;
51
+ }
52
+ /**
53
+ * Response from product deletion.
54
+ */
55
+ export interface DeleteProductResponse {
56
+ deleted: boolean;
57
+ }
58
+ /**
59
+ * Response from product search.
60
+ */
61
+ export interface SearchProductsResponse {
62
+ success: boolean;
63
+ message: string;
64
+ data: Product[];
65
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Product Interfaces
3
+ * Product catalog management
4
+ */
5
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Interface definitions for push command
3
+ */
4
+ /**
5
+ * Response from push version API endpoint
6
+ */
7
+ export interface PushVersionResponse {
8
+ success: boolean;
9
+ data?: {
10
+ skillsId: string;
11
+ version: string;
12
+ context: string;
13
+ description: string;
14
+ tools: any[];
15
+ _id: string;
16
+ id: string;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ __v: number;
20
+ };
21
+ error?: {
22
+ message: string;
23
+ error: string;
24
+ statusCode: number;
25
+ };
26
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Interface definitions for push command
3
+ */
4
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Interface definitions for test command
3
+ */
4
+ /**
5
+ * Tool information from deploy.json
6
+ */
7
+ export interface ToolData {
8
+ name: string;
9
+ description: string;
10
+ inputSchema: any;
11
+ execute: string;
12
+ skillName?: string;
13
+ }
14
+ /**
15
+ * Tool choice for inquirer prompt
16
+ */
17
+ export interface ToolChoice {
18
+ name: string;
19
+ value: ToolData;
20
+ }
21
+ /**
22
+ * Schema property definition
23
+ */
24
+ export interface SchemaProperty {
25
+ type: string;
26
+ properties?: Record<string, SchemaProperty>;
27
+ required?: string[];
28
+ description?: string;
29
+ }
30
+ /**
31
+ * Input schema structure
32
+ */
33
+ export interface InputSchema {
34
+ properties?: Record<string, SchemaProperty>;
35
+ required?: string[];
36
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Interface definitions for test command
3
+ */
4
+ export {};
@@ -1,106 +1,61 @@
1
- import { UserData } from "../types/index.js";
1
+ /**
2
+ * Authentication Service
3
+ * Handles all authentication operations including API key management and OTP flows
4
+ */
5
+ import { UserData } from "../interfaces/admin.js";
6
+ /**
7
+ * Saves API key to secure system keychain.
8
+ * Uses the system's native credential storage (Keychain on macOS,
9
+ * Credential Vault on Windows, libsecret on Linux).
10
+ *
11
+ * @param apiKey - The API key to store securely
12
+ * @returns Promise that resolves when key is saved
13
+ */
2
14
  export declare function saveApiKey(apiKey: string): Promise<void>;
15
+ /**
16
+ * Loads API key from secure system keychain.
17
+ *
18
+ * @returns Promise resolving to API key or null if not found
19
+ */
3
20
  export declare function loadApiKey(): Promise<string | null>;
21
+ /**
22
+ * Deletes API key from secure system keychain.
23
+ * This is used for logout functionality.
24
+ *
25
+ * @returns Promise resolving to true if deleted, false if not found
26
+ */
4
27
  export declare function deleteApiKey(): Promise<boolean>;
28
+ /**
29
+ * Validates an API key with the server and retrieves user data.
30
+ * This function will exit the process if the API key is invalid.
31
+ *
32
+ * @param apiKey - The API key to validate
33
+ * @returns Promise resolving to user data including admin info and organizations
34
+ * @throws Exits process with code 1 if API key is invalid
35
+ */
5
36
  export declare function checkApiKey(apiKey: string): Promise<UserData>;
37
+ /**
38
+ * Requests an OTP (One-Time Password) to be sent to the specified email.
39
+ * The OTP will be valid for a limited time and can be used once.
40
+ *
41
+ * @param email - Email address to send OTP to
42
+ * @returns Promise resolving to true if OTP sent successfully, false otherwise
43
+ */
6
44
  export declare function requestEmailOTP(email: string): Promise<boolean>;
45
+ /**
46
+ * Verifies an OTP code and retrieves a sign-in token.
47
+ * The sign-in token can be used to generate an API key.
48
+ *
49
+ * @param email - Email address the OTP was sent to
50
+ * @param pin - The OTP code received via email
51
+ * @returns Promise resolving to sign-in token or null if verification failed
52
+ */
7
53
  export declare function verifyOTPAndGetToken(email: string, pin: string): Promise<string | null>;
54
+ /**
55
+ * Generates a permanent API key using a sign-in token.
56
+ * The sign-in token is obtained from successful OTP verification.
57
+ *
58
+ * @param signInToken - Token obtained from OTP verification
59
+ * @returns Promise resolving to API key or null if generation failed
60
+ */
8
61
  export declare function generateApiKey(signInToken: string): Promise<string | null>;
9
- export interface CreateSkillResponse {
10
- success: boolean;
11
- data?: {
12
- name: string;
13
- public: boolean;
14
- agentId: string;
15
- active: boolean;
16
- _id: string;
17
- id: string;
18
- createdAt: string;
19
- updatedAt: string;
20
- __v: number;
21
- };
22
- error?: {
23
- message: string;
24
- error: string;
25
- statusCode: number;
26
- };
27
- }
28
- export interface AgentType {
29
- id: string;
30
- name: string;
31
- features: Record<string, any>;
32
- requiredSubAgentMetadata?: string[];
33
- }
34
- export interface CreateAgentRequest {
35
- id: string;
36
- type: string;
37
- metadata: Record<string, any>;
38
- persona: {
39
- agentName: string;
40
- businessType: string;
41
- brandPersonality: string;
42
- brandTraits: string;
43
- };
44
- features: Record<string, boolean>;
45
- channels: any[];
46
- org: {
47
- registeredName: string;
48
- };
49
- }
50
- export interface CreateAgentResponse {
51
- success: boolean;
52
- data?: {
53
- agentId: string;
54
- name: string;
55
- baseAgentId: string;
56
- persona: string;
57
- createdAt: string;
58
- welcomeMessage: string;
59
- featuresOverride: Record<string, any>;
60
- _id: string;
61
- updatedAt: string;
62
- __v: number;
63
- org: {
64
- registeredName: string;
65
- type: string;
66
- agents: string[];
67
- paymentMethods: any[];
68
- _id: string;
69
- id: string;
70
- createdAt: number;
71
- __v: number;
72
- };
73
- };
74
- error?: {
75
- message: string;
76
- error: string;
77
- statusCode: number;
78
- };
79
- }
80
- export interface AgentDetailsResponse {
81
- success: boolean;
82
- data?: {
83
- _id: string;
84
- agentId: string;
85
- name: string;
86
- baseAgentId: string;
87
- persona: string;
88
- createdAt: string;
89
- welcomeMessage: string;
90
- featuresOverride: Record<string, any>;
91
- updatedAt: string;
92
- __v: number;
93
- personaConfig: {
94
- agentName: string;
95
- businessType: string;
96
- brandPersonality: string;
97
- brandTraits: string;
98
- };
99
- skills: any[];
100
- };
101
- error?: {
102
- message: string;
103
- error: string;
104
- statusCode: number;
105
- };
106
- }
@@ -1,27 +1,76 @@
1
+ /**
2
+ * Authentication Service
3
+ * Handles all authentication operations including API key management and OTP flows
4
+ */
1
5
  import keytar from "keytar";
2
- import { ApiService } from "./api.js";
3
- const SERVICE = "lua-cli";
4
- const ACCOUNT = "api-key";
6
+ import AuthApi from "../api/auth.api.service.js";
7
+ import { BASE_URLS } from "../config/constants.js";
8
+ import { KEYTAR_SERVICE, KEYTAR_ACCOUNT } from "../config/auth.constants.js";
9
+ // ============================================================================
10
+ // KEYTAR OPERATIONS (Secure Local Storage)
11
+ // ============================================================================
12
+ /**
13
+ * Saves API key to secure system keychain.
14
+ * Uses the system's native credential storage (Keychain on macOS,
15
+ * Credential Vault on Windows, libsecret on Linux).
16
+ *
17
+ * @param apiKey - The API key to store securely
18
+ * @returns Promise that resolves when key is saved
19
+ */
5
20
  export async function saveApiKey(apiKey) {
6
- await keytar.setPassword(SERVICE, ACCOUNT, apiKey);
21
+ await keytar.setPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT, apiKey);
7
22
  }
23
+ /**
24
+ * Loads API key from secure system keychain.
25
+ *
26
+ * @returns Promise resolving to API key or null if not found
27
+ */
8
28
  export async function loadApiKey() {
9
- return keytar.getPassword(SERVICE, ACCOUNT);
29
+ return keytar.getPassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
10
30
  }
31
+ /**
32
+ * Deletes API key from secure system keychain.
33
+ * This is used for logout functionality.
34
+ *
35
+ * @returns Promise resolving to true if deleted, false if not found
36
+ */
11
37
  export async function deleteApiKey() {
12
- return keytar.deletePassword(SERVICE, ACCOUNT);
38
+ return keytar.deletePassword(KEYTAR_SERVICE, KEYTAR_ACCOUNT);
13
39
  }
40
+ // ============================================================================
41
+ // API OPERATIONS (Server Authentication)
42
+ // ============================================================================
43
+ /**
44
+ * Validates an API key with the server and retrieves user data.
45
+ * This function will exit the process if the API key is invalid.
46
+ *
47
+ * @param apiKey - The API key to validate
48
+ * @returns Promise resolving to user data including admin info and organizations
49
+ * @throws Exits process with code 1 if API key is invalid
50
+ */
14
51
  export async function checkApiKey(apiKey) {
15
- const result = await ApiService.Auth.checkApiKey(apiKey);
52
+ const authApi = new AuthApi(BASE_URLS.API);
53
+ const result = await authApi.checkApiKey(apiKey);
16
54
  if (!result.success) {
17
55
  console.error(`❌ Invalid API key`);
18
56
  process.exit(1);
19
57
  }
20
58
  return result.data;
21
59
  }
60
+ // ============================================================================
61
+ // EMAIL OTP AUTHENTICATION FLOW
62
+ // ============================================================================
63
+ /**
64
+ * Requests an OTP (One-Time Password) to be sent to the specified email.
65
+ * The OTP will be valid for a limited time and can be used once.
66
+ *
67
+ * @param email - Email address to send OTP to
68
+ * @returns Promise resolving to true if OTP sent successfully, false otherwise
69
+ */
22
70
  export async function requestEmailOTP(email) {
23
71
  try {
24
- const result = await ApiService.Auth.sendOtp(email);
72
+ const authApi = new AuthApi(BASE_URLS.AUTH);
73
+ const result = await authApi.sendOtp(email);
25
74
  return result.success;
26
75
  }
27
76
  catch (error) {
@@ -29,9 +78,18 @@ export async function requestEmailOTP(email) {
29
78
  return false;
30
79
  }
31
80
  }
81
+ /**
82
+ * Verifies an OTP code and retrieves a sign-in token.
83
+ * The sign-in token can be used to generate an API key.
84
+ *
85
+ * @param email - Email address the OTP was sent to
86
+ * @param pin - The OTP code received via email
87
+ * @returns Promise resolving to sign-in token or null if verification failed
88
+ */
32
89
  export async function verifyOTPAndGetToken(email, pin) {
33
90
  try {
34
- const result = await ApiService.Auth.verifyOtp(email, pin);
91
+ const authApi = new AuthApi(BASE_URLS.AUTH);
92
+ const result = await authApi.verifyOtp(email, pin);
35
93
  return result.success ? result.data.signInToken : null;
36
94
  }
37
95
  catch (error) {
@@ -39,9 +97,17 @@ export async function verifyOTPAndGetToken(email, pin) {
39
97
  return null;
40
98
  }
41
99
  }
100
+ /**
101
+ * Generates a permanent API key using a sign-in token.
102
+ * The sign-in token is obtained from successful OTP verification.
103
+ *
104
+ * @param signInToken - Token obtained from OTP verification
105
+ * @returns Promise resolving to API key or null if generation failed
106
+ */
42
107
  export async function generateApiKey(signInToken) {
43
108
  try {
44
- const result = await ApiService.Auth.getApiKey(signInToken);
109
+ const authApi = new AuthApi(BASE_URLS.AUTH);
110
+ const result = await authApi.getApiKey(signInToken);
45
111
  return result.success ? result.data.apiKey : null;
46
112
  }
47
113
  catch (error) {
@@ -49,5 +115,3 @@ export async function generateApiKey(signInToken) {
49
115
  return null;
50
116
  }
51
117
  }
52
- // API functions moved to centralized ApiService and api.ts
53
- // Use ApiService.getAgentTypes(), ApiService.createAgent(), ApiService.getAgentDetails() instead