@inworld/cli 0.2.15 → 0.2.16
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.
- package/dist/index.js +1086 -639
- package/dist/index.js.map +4 -4
- package/dist/package.json +49 -0
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts +10 -0
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js +16 -0
- package/dist/proto/generated/portal/ai/inworld/language_codes/language_codes.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts +13 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.js +2 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/errors.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js +15 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/operations.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts +14 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graph_configuration.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.d.ts +116 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.js +71 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/graphs.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts +14 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1/remote/configuration/targeting.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts +76 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js +40 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/apikeys.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts +10 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/impression_event_data.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts +7 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js +13 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/language_code.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts +115 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js +86 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts +255 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js +88 -0
- package/dist/proto/generated/portal/ai/inworld/studio/v1alpha/workspaces.pb.js.map +1 -0
- package/dist/proto/generated/portal/fetch.pb.d.ts +26 -0
- package/dist/proto/generated/portal/fetch.pb.d.ts.map +1 -0
- package/dist/proto/generated/portal/fetch.pb.js +274 -0
- package/dist/proto/generated/portal/fetch.pb.js.map +1 -0
- package/dist/src/auth/callback_server.d.ts +41 -0
- package/dist/src/auth/callback_server.d.ts.map +1 -0
- package/dist/src/auth/callback_server.js +136 -0
- package/dist/src/auth/callback_server.js.map +1 -0
- package/dist/src/auth/manager.d.ts +97 -0
- package/dist/src/auth/manager.d.ts.map +1 -0
- package/dist/src/auth/manager.js +340 -0
- package/dist/src/auth/manager.js.map +1 -0
- package/dist/src/auth/utils.d.ts +45 -0
- package/dist/src/auth/utils.d.ts.map +1 -0
- package/dist/src/auth/utils.js +183 -0
- package/dist/src/auth/utils.js.map +1 -0
- package/dist/src/commands/auth/disable_telemetry_command.d.ts +3 -0
- package/dist/src/commands/auth/disable_telemetry_command.d.ts.map +1 -0
- package/dist/src/commands/auth/enable_telemetry_command.d.ts +3 -0
- package/dist/src/commands/auth/enable_telemetry_command.d.ts.map +1 -0
- package/dist/src/commands/auth/login_ci_command.d.ts +3 -0
- package/dist/src/commands/auth/login_ci_command.d.ts.map +1 -0
- package/dist/src/commands/auth/login_ci_command.js +41 -0
- package/dist/src/commands/auth/login_ci_command.js.map +1 -0
- package/dist/src/commands/auth/login_command.d.ts +4 -0
- package/dist/src/commands/auth/login_command.d.ts.map +1 -0
- package/dist/src/commands/auth/login_command.js +134 -0
- package/dist/src/commands/auth/login_command.js.map +1 -0
- package/dist/src/commands/auth/logout_command.d.ts +4 -0
- package/dist/src/commands/auth/logout_command.d.ts.map +1 -0
- package/dist/src/commands/auth/logout_command.js +54 -0
- package/dist/src/commands/auth/logout_command.js.map +1 -0
- package/dist/src/commands/auth/print_access_token_command.d.ts +3 -0
- package/dist/src/commands/auth/print_access_token_command.d.ts.map +1 -0
- package/dist/src/commands/auth/print_access_token_command.js +21 -0
- package/dist/src/commands/auth/print_access_token_command.js.map +1 -0
- package/dist/src/commands/auth/print_api_key_command.d.ts +3 -0
- package/dist/src/commands/auth/print_api_key_command.d.ts.map +1 -0
- package/dist/src/commands/auth/print_api_key_command.js +26 -0
- package/dist/src/commands/auth/print_api_key_command.js.map +1 -0
- package/dist/src/commands/auth/status_command.d.ts +4 -0
- package/dist/src/commands/auth/status_command.d.ts.map +1 -0
- package/dist/src/commands/auth/status_command.js +84 -0
- package/dist/src/commands/auth/status_command.js.map +1 -0
- package/dist/src/commands/auth_command.d.ts +3 -0
- package/dist/src/commands/auth_command.d.ts.map +1 -0
- package/dist/src/commands/auth_command.js +20 -0
- package/dist/src/commands/auth_command.js.map +1 -0
- package/dist/src/commands/graph/graph_deploy_command.d.ts +24 -0
- package/dist/src/commands/graph/graph_deploy_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_deploy_command.js +191 -0
- package/dist/src/commands/graph/graph_deploy_command.js.map +1 -0
- package/dist/src/commands/graph/graph_init_command.d.ts +4 -0
- package/dist/src/commands/graph/graph_init_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_init_command.js +376 -0
- package/dist/src/commands/graph/graph_init_command.js.map +1 -0
- package/dist/src/commands/graph/graph_run_command.d.ts +24 -0
- package/dist/src/commands/graph/graph_run_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_run_command.js +50 -0
- package/dist/src/commands/graph/graph_run_command.js.map +1 -0
- package/dist/src/commands/graph/graph_serve_command.d.ts +4 -0
- package/dist/src/commands/graph/graph_serve_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_serve_command.js +40 -0
- package/dist/src/commands/graph/graph_serve_command.js.map +1 -0
- package/dist/src/commands/graph/graph_variant_command.d.ts +3 -0
- package/dist/src/commands/graph/graph_variant_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_variant_command.js +13 -0
- package/dist/src/commands/graph/graph_variant_command.js.map +1 -0
- package/dist/src/commands/graph/graph_visualize_command.d.ts +7 -0
- package/dist/src/commands/graph/graph_visualize_command.d.ts.map +1 -0
- package/dist/src/commands/graph/graph_visualize_command.js +35 -0
- package/dist/src/commands/graph/graph_visualize_command.js.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts +3 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.d.ts.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.js +25 -0
- package/dist/src/commands/graph/variant/graph_variant_list_command.js.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts +7 -0
- package/dist/src/commands/graph/variant/graph_variant_print_command.d.ts.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_print_command.js +45 -0
- package/dist/src/commands/graph/variant/graph_variant_print_command.js.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts +3 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.d.ts.map +1 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.js +45 -0
- package/dist/src/commands/graph/variant/graph_variant_register_command.js.map +1 -0
- package/dist/src/commands/graph_command.d.ts +3 -0
- package/dist/src/commands/graph_command.d.ts.map +1 -0
- package/dist/src/commands/graph_command.js +20 -0
- package/dist/src/commands/graph_command.js.map +1 -0
- package/dist/src/commands/tts_commands.d.ts +17 -0
- package/dist/src/commands/tts_commands.d.ts.map +1 -0
- package/dist/src/commands/tts_commands.js +568 -0
- package/dist/src/commands/tts_commands.js.map +1 -0
- package/dist/src/commands/workspace_command.d.ts +12 -0
- package/dist/src/commands/workspace_command.d.ts.map +1 -0
- package/dist/src/commands/workspace_command.js +33 -0
- package/dist/src/commands/workspace_command.js.map +1 -0
- package/dist/src/constants.d.ts +10 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +30 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/grpc/core/InworldError.d.ts +30 -0
- package/dist/src/grpc/core/InworldError.d.ts.map +1 -0
- package/dist/src/grpc/core/InworldError.js +46 -0
- package/dist/src/grpc/core/InworldError.js.map +1 -0
- package/dist/src/grpc/core/statusCodes.d.ts +122 -0
- package/dist/src/grpc/core/statusCodes.d.ts.map +1 -0
- package/dist/src/grpc/core/statusCodes.js +133 -0
- package/dist/src/grpc/core/statusCodes.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/services/analytics.d.ts +45 -0
- package/dist/src/services/analytics.d.ts.map +1 -0
- package/dist/src/services/deploy_service.d.ts +4 -0
- package/dist/src/services/deploy_service.d.ts.map +1 -0
- package/dist/src/services/deploy_service.js +128 -0
- package/dist/src/services/deploy_service.js.map +1 -0
- package/dist/src/services/graph_loader.d.ts +7 -0
- package/dist/src/services/graph_loader.d.ts.map +1 -0
- package/dist/src/services/graph_loader.js +103 -0
- package/dist/src/services/graph_loader.js.map +1 -0
- package/dist/src/services/graph_variant_service.d.ts +12 -0
- package/dist/src/services/graph_variant_service.d.ts.map +1 -0
- package/dist/src/services/graph_variant_service.js +66 -0
- package/dist/src/services/graph_variant_service.js.map +1 -0
- package/dist/src/services/tts_service.d.ts +273 -0
- package/dist/src/services/tts_service.d.ts.map +1 -0
- package/dist/src/services/tts_service.js +299 -0
- package/dist/src/services/tts_service.js.map +1 -0
- package/dist/src/services/update_checker.d.ts +37 -0
- package/dist/src/services/update_checker.d.ts.map +1 -0
- package/dist/src/services/workspace_service.d.ts +47 -0
- package/dist/src/services/workspace_service.d.ts.map +1 -0
- package/dist/src/services/workspace_service.js +222 -0
- package/dist/src/services/workspace_service.js.map +1 -0
- package/dist/src/templates/llm_tts/graph.d.ts +2 -0
- package/dist/src/templates/llm_tts/graph.d.ts.map +1 -0
- package/dist/src/utils/array.d.ts +2 -0
- package/dist/src/utils/array.d.ts.map +1 -0
- package/dist/src/utils/array.js +4 -0
- package/dist/src/utils/array.js.map +1 -0
- package/dist/src/utils/confirm.d.ts +62 -0
- package/dist/src/utils/confirm.d.ts.map +1 -0
- package/dist/src/utils/confirm.js +90 -0
- package/dist/src/utils/confirm.js.map +1 -0
- package/dist/src/utils/long_running_operations.d.ts +38 -0
- package/dist/src/utils/long_running_operations.d.ts.map +1 -0
- package/dist/src/utils/long_running_operations.js +62 -0
- package/dist/src/utils/long_running_operations.js.map +1 -0
- package/dist/src/utils/resource_name_helper.d.ts +12 -0
- package/dist/src/utils/resource_name_helper.d.ts.map +1 -0
- package/dist/src/utils/resource_name_helper.js +29 -0
- package/dist/src/utils/resource_name_helper.js.map +1 -0
- package/dist/src/utils/selector.d.ts +62 -0
- package/dist/src/utils/selector.d.ts.map +1 -0
- package/dist/src/utils/selector.js +77 -0
- package/dist/src/utils/selector.js.map +1 -0
- package/dist/src/utils/spinner.d.ts +75 -0
- package/dist/src/utils/spinner.d.ts.map +1 -0
- package/dist/src/utils/spinner.js +178 -0
- package/dist/src/utils/spinner.js.map +1 -0
- package/dist/src/utils/ui.d.ts +27 -0
- package/dist/src/utils/ui.d.ts.map +1 -0
- package/dist/src/utils/ui.js +83 -0
- package/dist/src/utils/ui.js.map +1 -0
- package/dist/templates/llm_tts/graph.ts +2 -1
- package/package.json +3 -2
- package/src/templates/llm_tts/graph.ts +2 -1
- package/dist/src/templates/simple/README.md +0 -106
- package/dist/src/templates/simple/graph.ts +0 -32
- package/dist/src/templates/simple/metadata.json +0 -26
- package/dist/templates/simple/README.md +0 -106
- package/dist/templates/simple/graph.ts +0 -32
- package/dist/templates/simple/metadata.json +0 -26
- package/src/templates/simple/README.md +0 -106
- package/src/templates/simple/graph.ts +0 -32
- package/src/templates/simple/metadata.json +0 -26
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// Keyring will be dynamically imported to avoid crashes when libsecret is not available
|
|
2
|
+
import Conf from 'conf';
|
|
3
|
+
import { createHash } from 'crypto';
|
|
4
|
+
import { AuthType, Users, } from '../../proto/generated/portal/ai/inworld/studio/v1alpha/users.pb.js';
|
|
5
|
+
import { FIREBASE_API_KEY, INWORLD_ENV, PLATFORM_URL } from '@/constants.js';
|
|
6
|
+
import * as ui from '@/utils/ui';
|
|
7
|
+
/**
|
|
8
|
+
* AuthManager handles secure storage and retrieval of authentication credentials.
|
|
9
|
+
* It uses the OS keychain as the primary storage method with an encrypted
|
|
10
|
+
* configuration file as a fallback.
|
|
11
|
+
*/
|
|
12
|
+
export class AuthManager {
|
|
13
|
+
static SERVICE_NAME = 'InworldCLI';
|
|
14
|
+
static ACCOUNT_NAME = 'default';
|
|
15
|
+
static CONFIG_KEY = 'credentials';
|
|
16
|
+
conf = null;
|
|
17
|
+
keyringModule = null;
|
|
18
|
+
keyringLoadAttempted = false;
|
|
19
|
+
keyringAvailable = false;
|
|
20
|
+
constructor() {
|
|
21
|
+
// Conf and keyring will be initialized lazily when first needed
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Lazily loads the keyring module with fallback if unavailable
|
|
25
|
+
*/
|
|
26
|
+
async getKeyring() {
|
|
27
|
+
if (this.keyringLoadAttempted) {
|
|
28
|
+
return this.keyringModule;
|
|
29
|
+
}
|
|
30
|
+
this.keyringLoadAttempted = true;
|
|
31
|
+
try {
|
|
32
|
+
const module = (await import('@zowe/secrets-for-zowe-sdk'));
|
|
33
|
+
this.keyringModule = module.keyring;
|
|
34
|
+
return this.keyringModule;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
ui.print(`⚠️ Failed to load keychain: ${error.message}`);
|
|
38
|
+
this.keyringModule = null;
|
|
39
|
+
this.keyringAvailable = false;
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Lazily initializes the Conf instance with encrypted storage
|
|
45
|
+
*/
|
|
46
|
+
async getConf() {
|
|
47
|
+
if (!this.conf) {
|
|
48
|
+
const encryptionKey = await this.generateEncryptionKey();
|
|
49
|
+
this.conf = new Conf({
|
|
50
|
+
projectName: 'inworld-cli',
|
|
51
|
+
encryptionKey,
|
|
52
|
+
schema: {
|
|
53
|
+
credentials: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
refreshToken: { type: 'string' },
|
|
57
|
+
email: { type: 'string' },
|
|
58
|
+
inworldToken: { type: 'string' },
|
|
59
|
+
expiresAt: { type: 'number' },
|
|
60
|
+
workspace: { type: 'string' },
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return this.conf;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generates a machine-specific encryption key for the configuration file
|
|
70
|
+
*/
|
|
71
|
+
async generateEncryptionKey() {
|
|
72
|
+
const platform = process.platform;
|
|
73
|
+
const arch = process.arch;
|
|
74
|
+
const hostname = (await import('os')).hostname();
|
|
75
|
+
const username = (await import('os')).userInfo().username;
|
|
76
|
+
// Create a unique key based on machine characteristics
|
|
77
|
+
const data = `${platform}-${arch}-${hostname}-${username}-inworld-cli`;
|
|
78
|
+
return createHash('sha256').update(data).digest('hex').substring(0, 32);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Saves credentials securely
|
|
82
|
+
*/
|
|
83
|
+
async saveCredentials(credentials) {
|
|
84
|
+
try {
|
|
85
|
+
// Try to save to OS keychain first
|
|
86
|
+
const keyring = await this.getKeyring();
|
|
87
|
+
if (keyring) {
|
|
88
|
+
try {
|
|
89
|
+
const credentialsJsonString = JSON.stringify(credentials);
|
|
90
|
+
await keyring.setPassword(AuthManager.SERVICE_NAME, AuthManager.ACCOUNT_NAME, credentialsJsonString);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
catch (_keychainError) {
|
|
94
|
+
ui.print('⚠ Could not save to system keychain, using encrypted file storage');
|
|
95
|
+
// Fall through to use conf
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Fallback to encrypted configuration file
|
|
99
|
+
const conf = await this.getConf();
|
|
100
|
+
conf.set(AuthManager.CONFIG_KEY, credentials);
|
|
101
|
+
ui.success('✓ Credentials saved to encrypted configuration');
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
throw new Error(`Failed to save credentials: ${error}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves stored credentials
|
|
109
|
+
*/
|
|
110
|
+
async getCredentials() {
|
|
111
|
+
try {
|
|
112
|
+
const keyring = await this.getKeyring();
|
|
113
|
+
if (keyring) {
|
|
114
|
+
try {
|
|
115
|
+
const credentialsJson = await keyring.getPassword(AuthManager.SERVICE_NAME, AuthManager.ACCOUNT_NAME);
|
|
116
|
+
if (credentialsJson) {
|
|
117
|
+
return JSON.parse(credentialsJson);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (_keychainError) {
|
|
121
|
+
// Keychain read failed, try config file
|
|
122
|
+
// Don't log here as this is a common path
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const conf = await this.getConf();
|
|
126
|
+
const credentials = conf.get(AuthManager.CONFIG_KEY);
|
|
127
|
+
return credentials || null;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
throw new Error(`Failed to retrieve credentials: ${error}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async getApiKey() {
|
|
134
|
+
const credentials = await this.getCredentials();
|
|
135
|
+
return credentials?.apiKey || null;
|
|
136
|
+
}
|
|
137
|
+
async getWorkspace() {
|
|
138
|
+
const credentials = await this.getCredentials();
|
|
139
|
+
return credentials?.workspace || null;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Updates the Inworld token and its expiration
|
|
143
|
+
*/
|
|
144
|
+
async updateInworldToken(token, expirationTime) {
|
|
145
|
+
const credentials = await this.getCredentials();
|
|
146
|
+
if (!credentials) {
|
|
147
|
+
throw new Error('No credentials found to update');
|
|
148
|
+
}
|
|
149
|
+
credentials.inworldToken = token;
|
|
150
|
+
credentials.expiresAt = new Date(expirationTime).getTime();
|
|
151
|
+
await this.saveCredentials(credentials);
|
|
152
|
+
}
|
|
153
|
+
async updateWorkspaceAndApiKey(workspace, apiKey) {
|
|
154
|
+
const credentials = await this.getCredentials();
|
|
155
|
+
if (!credentials) {
|
|
156
|
+
throw new Error('No credentials found to update');
|
|
157
|
+
}
|
|
158
|
+
credentials.workspace = workspace;
|
|
159
|
+
credentials.apiKey = apiKey;
|
|
160
|
+
await this.saveCredentials(credentials);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks if the stored Inworld token is still valid
|
|
164
|
+
*/
|
|
165
|
+
async isTokenValid() {
|
|
166
|
+
const credentials = await this.getCredentials();
|
|
167
|
+
if (!credentials || !credentials.inworldToken) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
// If we have an expiration time, check it
|
|
171
|
+
if (credentials.expiresAt) {
|
|
172
|
+
return Date.now() < credentials.expiresAt;
|
|
173
|
+
}
|
|
174
|
+
// Otherwise assume it's valid (will fail on API call if not)
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Generates an Inworld token from a Firebase ID token
|
|
179
|
+
*
|
|
180
|
+
* @param firebaseToken The Firebase ID token
|
|
181
|
+
* @returns The generated Inworld token or null if generation fails
|
|
182
|
+
*/
|
|
183
|
+
async generateInworldToken(firebaseToken) {
|
|
184
|
+
try {
|
|
185
|
+
ui.print('Generating Inworld token...');
|
|
186
|
+
const tokenResponse = await Users.GenerateTokenUser({
|
|
187
|
+
type: AuthType.AUTH_TYPE_FIREBASE,
|
|
188
|
+
token: firebaseToken,
|
|
189
|
+
}, {
|
|
190
|
+
headers: {
|
|
191
|
+
Authorization: `Bearer ${firebaseToken}`,
|
|
192
|
+
'Grpc-Metadata-X-Authorization-Bearer-Type': 'firebase',
|
|
193
|
+
},
|
|
194
|
+
pathPrefix: PLATFORM_URL,
|
|
195
|
+
});
|
|
196
|
+
if (tokenResponse?.token) {
|
|
197
|
+
return {
|
|
198
|
+
token: tokenResponse.token,
|
|
199
|
+
expiresAt: tokenResponse.expirationTime,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
ui.printError('Failed to generate Inworld token:');
|
|
206
|
+
console.error(error);
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Refreshes the Inworld token using the stored refresh token
|
|
212
|
+
*/
|
|
213
|
+
async refreshToken() {
|
|
214
|
+
const credentials = await this.getCredentials();
|
|
215
|
+
if (!credentials || !credentials.refreshToken) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
// Use the refresh token to get a new Firebase ID token
|
|
220
|
+
const firebaseApiKey = FIREBASE_API_KEY;
|
|
221
|
+
if (!firebaseApiKey) {
|
|
222
|
+
throw new Error('FIREBASE_API_KEY environment variable not set');
|
|
223
|
+
}
|
|
224
|
+
const tokenFetchResponse = await fetch(`https://securetoken.googleapis.com/v1/token?key=${firebaseApiKey}`, {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
body: new URLSearchParams({
|
|
227
|
+
grant_type: 'refresh_token',
|
|
228
|
+
refresh_token: credentials.refreshToken,
|
|
229
|
+
}),
|
|
230
|
+
});
|
|
231
|
+
const tokenResponse = (await tokenFetchResponse.json());
|
|
232
|
+
if (tokenResponse?.id_token) {
|
|
233
|
+
// Generate new Inworld token
|
|
234
|
+
const inworldTokenResult = await this.generateInworldToken(tokenResponse.id_token);
|
|
235
|
+
if (inworldTokenResult) {
|
|
236
|
+
// Update stored token
|
|
237
|
+
await this.updateInworldToken(inworldTokenResult.token, inworldTokenResult.expiresAt);
|
|
238
|
+
return inworldTokenResult.token;
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
ui.printError('Failed to refresh token:');
|
|
246
|
+
console.error(error);
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Gets a valid Inworld token, refreshing if necessary
|
|
252
|
+
*/
|
|
253
|
+
async getValidToken() {
|
|
254
|
+
// Check if current token is valid
|
|
255
|
+
if (await this.isTokenValid()) {
|
|
256
|
+
const credentials = await this.getCredentials();
|
|
257
|
+
return credentials?.inworldToken || null;
|
|
258
|
+
}
|
|
259
|
+
// Try to refresh the token
|
|
260
|
+
ui.print('Token expired, refreshing...');
|
|
261
|
+
return await this.refreshToken();
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Authenticates and saves credentials from Firebase auth data
|
|
265
|
+
* This is typically called after successful Firebase authentication
|
|
266
|
+
*
|
|
267
|
+
* @param firebaseToken The Firebase ID token
|
|
268
|
+
* @param refreshToken The Firebase refresh token
|
|
269
|
+
* @param email The user's email address
|
|
270
|
+
* @returns true if successful, false otherwise
|
|
271
|
+
*/
|
|
272
|
+
async authenticateAndSaveCredentials(firebaseToken, refreshToken, email, workspace, env) {
|
|
273
|
+
try {
|
|
274
|
+
// Generate Inworld token
|
|
275
|
+
const inworldTokenResult = await this.generateInworldToken(firebaseToken);
|
|
276
|
+
if (!inworldTokenResult) {
|
|
277
|
+
ui.printError('Failed to generate Inworld token');
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
// Calculate expiration time
|
|
281
|
+
const expiresAt = new Date(inworldTokenResult.expiresAt).getTime();
|
|
282
|
+
// Save all credentials
|
|
283
|
+
const credentials = {
|
|
284
|
+
refreshToken,
|
|
285
|
+
email,
|
|
286
|
+
inworldToken: inworldTokenResult.token,
|
|
287
|
+
workspace,
|
|
288
|
+
expiresAt,
|
|
289
|
+
env,
|
|
290
|
+
};
|
|
291
|
+
await this.saveCredentials(credentials);
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
ui.printError('Failed to authenticate and save credentials:');
|
|
296
|
+
console.error(error);
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Clears all stored credentials
|
|
302
|
+
*/
|
|
303
|
+
async clearCredentials() {
|
|
304
|
+
try {
|
|
305
|
+
// Try to clear from OS keychain
|
|
306
|
+
const keyring = await this.getKeyring();
|
|
307
|
+
if (keyring) {
|
|
308
|
+
try {
|
|
309
|
+
await keyring.deletePassword(AuthManager.SERVICE_NAME, AuthManager.ACCOUNT_NAME);
|
|
310
|
+
}
|
|
311
|
+
catch (_keychainError) {
|
|
312
|
+
// Ignore keychain errors
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
// Clear from configuration file
|
|
316
|
+
const conf = await this.getConf();
|
|
317
|
+
conf.delete(AuthManager.CONFIG_KEY);
|
|
318
|
+
ui.success('✓ Credentials cleared');
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
throw new Error(`Failed to clear credentials: ${error}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Checks if user is authenticated
|
|
326
|
+
*/
|
|
327
|
+
async isAuthenticated() {
|
|
328
|
+
const credentials = await this.getCredentials();
|
|
329
|
+
if (credentials?.env && credentials?.env !== INWORLD_ENV) {
|
|
330
|
+
ui.print(`Warning: Currently saved credentials might not match current Inworld CLI environment.\n\n` +
|
|
331
|
+
`Current Inworld CLI environment is ${INWORLD_ENV}\n` +
|
|
332
|
+
`Environment of current credentials is ${credentials?.env}\n\n` +
|
|
333
|
+
`You can run "inworld login --force" to login with the correct environment.`);
|
|
334
|
+
}
|
|
335
|
+
return credentials !== null && !!credentials.refreshToken;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// Export singleton instance
|
|
339
|
+
export const authManager = new AuthManager();
|
|
340
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/auth/manager.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EACL,QAAQ,EACR,KAAK,GACN,MAAM,oEAAoE,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AA8BjC;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAU,YAAY,GAAG,YAAY,CAAC;IAC5C,MAAM,CAAU,YAAY,GAAG,SAAS,CAAC;IACzC,MAAM,CAAU,UAAU,GAAG,aAAa,CAAC;IAE3C,IAAI,GAA+C,IAAI,CAAC;IACxD,aAAa,GAAoC,IAAI,CAAC;IACtD,oBAAoB,GAAY,KAAK,CAAC;IACtC,gBAAgB,GAAY,KAAK,CAAC;IAE1C;QACE,gEAAgE;IAClE,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,UAAU;QACtB,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,aAAa,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QAEjC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAC1B,4BAA4B,CAC7B,CAAkB,CAAC;YACpB,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC;YACpC,OAAO,IAAI,CAAC,aAAa,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAU,EAAE,CAA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AAK,CACN,2FAA2F;gBACzF,sCAAsC,WAAW,IAAI;gBACrD,yCAAyC,WAAW,EAAE,GAAG,MAAM;gBAC/D,4EAA4E,CAC/E,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,KAAK,IAAI,IAAI,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC;IAC5D,CAAC;;AAGH,4BAA4B;AAC5B,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as fm from '@/proto/generated/portal/fetch.pb.js';
|
|
2
|
+
import { BadRequestDetails, InworldErrorContract } from '@/grpc/core/InworldError';
|
|
3
|
+
import { GrpcStatusCode } from '@/grpc/core/statusCodes';
|
|
4
|
+
/**
|
|
5
|
+
* Authentication utilities for CLI commands
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Ensures the user is authenticated before proceeding.
|
|
9
|
+
* If not authenticated, prompts the user to login and exits.
|
|
10
|
+
*/
|
|
11
|
+
export declare function requireAuth(): Promise<void>;
|
|
12
|
+
export declare function requireWorkspace(): Promise<string>;
|
|
13
|
+
export declare function requireApiKey(): Promise<string>;
|
|
14
|
+
export type InworldRequestRetryOptions = {
|
|
15
|
+
maxRetries: number;
|
|
16
|
+
backoffFactor: number;
|
|
17
|
+
minTimeout: number;
|
|
18
|
+
maxTimeout?: number;
|
|
19
|
+
withMetadata?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare class InworldError extends Error {
|
|
22
|
+
code: GrpcStatusCode;
|
|
23
|
+
details: BadRequestDetails[];
|
|
24
|
+
metadata?: unknown;
|
|
25
|
+
constructor(error: InworldErrorContract | Error, metadata?: unknown);
|
|
26
|
+
}
|
|
27
|
+
export type PbFunc<P, R> = (req: P, initReq?: fm.InitReq) => Promise<R>;
|
|
28
|
+
export declare function retryableAuthenticatedInworldRequest<RequestOptions, Response>(pb: PbFunc<RequestOptions, Response>, req: RequestOptions, options?: InworldRequestRetryOptions, signal?: AbortSignal): Promise<Response | undefined>;
|
|
29
|
+
export type ArgsWithSignal<P = unknown> = P & {
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
};
|
|
32
|
+
export declare const authenticatedInworldRequest: <P, R>(pb: PbFunc<P, R>, req: P, inworldToken?: string, signal?: AbortSignal) => Promise<R | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the user is authenticated without exiting.
|
|
35
|
+
* Useful for commands that have optional authentication.
|
|
36
|
+
*
|
|
37
|
+
* @returns true if authenticated, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export declare function isAuthenticated(): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Shows the current authentication status.
|
|
42
|
+
* Useful for debugging or status commands.
|
|
43
|
+
*/
|
|
44
|
+
export declare function showAuthStatus(): Promise<void>;
|
|
45
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/auth/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAE3D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EAGrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAMzD;;GAEG;AAEH;;;GAGG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAWjD;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,CASxD;AAED,wBAAsB,aAAa,oBAgBlC;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAEP,KAAK,EAAE,oBAAoB,GAAG,KAAK,EAAE,QAAQ,CAAC,EAAE,OAAO;CAgBpE;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAExE,wBAAsB,oCAAoC,CACxD,cAAc,EACd,QAAQ,EAER,EAAE,EAAE,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,EACpC,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE,0BAIR,EACD,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAuE/B;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAEvE,eAAO,MAAM,2BAA2B,GAAU,CAAC,EAAE,CAAC,EACpD,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAChB,KAAK,CAAC,EACN,eAAe,MAAM,EACrB,SAAS,WAAW,2BAoBrB,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAExD;AAED;;;GAGG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CA0BpD"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { PLATFORM_URL } from '@/constants.js';
|
|
2
|
+
import { isGrpcError, isInworldErrorContract, } from '@/grpc/core/InworldError';
|
|
3
|
+
import { GrpcStatusCode } from '@/grpc/core/statusCodes';
|
|
4
|
+
import { CommonRetryableGrpcStatusCodes } from '@/grpc/core/statusCodes';
|
|
5
|
+
import { isLongRunningOperationResponse } from '@/utils/long_running_operations';
|
|
6
|
+
import * as ui from '@/utils/ui';
|
|
7
|
+
import { authManager } from '@/auth/manager.js';
|
|
8
|
+
/**
|
|
9
|
+
* Authentication utilities for CLI commands
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Ensures the user is authenticated before proceeding.
|
|
13
|
+
* If not authenticated, prompts the user to login and exits.
|
|
14
|
+
*/
|
|
15
|
+
export async function requireAuth() {
|
|
16
|
+
const isAuthenticated = await authManager.isAuthenticated();
|
|
17
|
+
if (!isAuthenticated) {
|
|
18
|
+
console.log();
|
|
19
|
+
ui.printError('❌ Authentication required');
|
|
20
|
+
ui.print('You must be logged in to use this command.');
|
|
21
|
+
console.log();
|
|
22
|
+
ui.print('Run: inworld login');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export async function requireWorkspace() {
|
|
27
|
+
const workspaceResourceName = await authManager.getWorkspace();
|
|
28
|
+
if (!workspaceResourceName) {
|
|
29
|
+
console.log();
|
|
30
|
+
ui.printError('❌ Workspace required');
|
|
31
|
+
ui.print('Please run "inworld ws select" to select a workspace.');
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
return workspaceResourceName;
|
|
35
|
+
}
|
|
36
|
+
export async function requireApiKey() {
|
|
37
|
+
let apiKey;
|
|
38
|
+
if (process.env.INWORLD_API_KEY) {
|
|
39
|
+
apiKey = process.env.INWORLD_API_KEY;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
apiKey = await authManager.getApiKey();
|
|
43
|
+
}
|
|
44
|
+
if (!apiKey) {
|
|
45
|
+
console.log();
|
|
46
|
+
ui.printError('❌ API key required');
|
|
47
|
+
ui.print('Please export "INWORLD_API_KEY" to environment variable or run "inworld login" to login.');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
return apiKey;
|
|
51
|
+
}
|
|
52
|
+
export class InworldError extends Error {
|
|
53
|
+
code;
|
|
54
|
+
details;
|
|
55
|
+
metadata;
|
|
56
|
+
constructor(error, metadata) {
|
|
57
|
+
super(error.message);
|
|
58
|
+
if (isInworldErrorContract(error)) {
|
|
59
|
+
this.message = error.message;
|
|
60
|
+
this.code = error.code;
|
|
61
|
+
this.details = error.details;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
this.code = GrpcStatusCode.UNKNOWN;
|
|
65
|
+
this.details = [];
|
|
66
|
+
}
|
|
67
|
+
this.metadata = metadata;
|
|
68
|
+
Object.setPrototypeOf(this, InworldError.prototype);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export async function retryableAuthenticatedInworldRequest(pb, req, options = {
|
|
72
|
+
maxRetries: 5,
|
|
73
|
+
backoffFactor: 2,
|
|
74
|
+
minTimeout: 300,
|
|
75
|
+
}, signal) {
|
|
76
|
+
const maxRetries = options.maxRetries;
|
|
77
|
+
const backoffFactor = options.backoffFactor;
|
|
78
|
+
const minTimeout = options.minTimeout;
|
|
79
|
+
const maxTimeout = options.maxTimeout ?? minTimeout * backoffFactor ** maxRetries * 2;
|
|
80
|
+
/**
|
|
81
|
+
* Recursive function to retry the inworld request with exponential backoff.
|
|
82
|
+
* @param {number} currentAttempt - The current attempt number.
|
|
83
|
+
* @param {AbortSignal} [signal] - AbortSignal to be able to abort operations.
|
|
84
|
+
* * @returns {Promise<Response | undefined>} A promise that resolves with the response or rejects if the maximum retries are reached.
|
|
85
|
+
*/
|
|
86
|
+
const retryRequest = async (currentAttempt, signal) => {
|
|
87
|
+
signal?.throwIfAborted();
|
|
88
|
+
try {
|
|
89
|
+
const response = await authenticatedInworldRequest(pb, req);
|
|
90
|
+
if (isLongRunningOperationResponse(response) && response?.done) {
|
|
91
|
+
// BE started sending metadata not in the error, but on the same level as the response for some cases.
|
|
92
|
+
if ((response?.error || response?.metadata?.error) &&
|
|
93
|
+
options.withMetadata) {
|
|
94
|
+
throw response;
|
|
95
|
+
}
|
|
96
|
+
if (response?.error) {
|
|
97
|
+
throw response.error;
|
|
98
|
+
}
|
|
99
|
+
return response;
|
|
100
|
+
}
|
|
101
|
+
return response;
|
|
102
|
+
}
|
|
103
|
+
catch (cause) {
|
|
104
|
+
const error = cause;
|
|
105
|
+
const isGrpcGatewayError = isGrpcError(cause);
|
|
106
|
+
/**
|
|
107
|
+
* Retry if the error is a gRPC error and the status code is in the list of retryable status codes
|
|
108
|
+
* OR
|
|
109
|
+
* the error is not a gRPC error. Since it can be a network error, we should retry.
|
|
110
|
+
*/
|
|
111
|
+
const allowRetry = (isGrpcGatewayError &&
|
|
112
|
+
CommonRetryableGrpcStatusCodes.includes(error.code)) ||
|
|
113
|
+
!isGrpcGatewayError;
|
|
114
|
+
if (allowRetry && currentAttempt < maxRetries) {
|
|
115
|
+
const timeout = Math.min(minTimeout * Math.pow(backoffFactor, currentAttempt), maxTimeout);
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
resolve(retryRequest(currentAttempt + 1));
|
|
119
|
+
}, timeout);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
throw new InworldError(error.metadata
|
|
124
|
+
? error
|
|
125
|
+
.error
|
|
126
|
+
: error, error.metadata);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return retryRequest(1, signal);
|
|
131
|
+
}
|
|
132
|
+
export const authenticatedInworldRequest = async (pb, req, inworldToken, signal) => {
|
|
133
|
+
if (!inworldToken) {
|
|
134
|
+
requireAuth();
|
|
135
|
+
inworldToken = (await authManager.getValidToken()) || '';
|
|
136
|
+
}
|
|
137
|
+
if (inworldToken) {
|
|
138
|
+
const request = {
|
|
139
|
+
...{
|
|
140
|
+
headers: {
|
|
141
|
+
Authorization: `Bearer ${inworldToken}`,
|
|
142
|
+
'Grpc-Metadata-X-Authorization-Bearer-Type': 'inworld',
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
pathPrefix: PLATFORM_URL,
|
|
146
|
+
signal,
|
|
147
|
+
};
|
|
148
|
+
return pb(req, request);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Checks if the user is authenticated without exiting.
|
|
153
|
+
* Useful for commands that have optional authentication.
|
|
154
|
+
*
|
|
155
|
+
* @returns true if authenticated, false otherwise
|
|
156
|
+
*/
|
|
157
|
+
export async function isAuthenticated() {
|
|
158
|
+
return await authManager.isAuthenticated();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Shows the current authentication status.
|
|
162
|
+
* Useful for debugging or status commands.
|
|
163
|
+
*/
|
|
164
|
+
export async function showAuthStatus() {
|
|
165
|
+
const isAuth = await authManager.isAuthenticated();
|
|
166
|
+
if (!isAuth) {
|
|
167
|
+
ui.printError('🔒 Not authenticated');
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const credentials = await authManager.getCredentials();
|
|
171
|
+
const email = credentials?.email || 'Unknown';
|
|
172
|
+
const hasValidToken = await authManager.isTokenValid();
|
|
173
|
+
ui.success('✓ Authenticated');
|
|
174
|
+
ui.print(` Email: ${email}`);
|
|
175
|
+
ui.print(` Token status: ${hasValidToken ? 'Valid' : 'Expired (will refresh automatically)'}`);
|
|
176
|
+
if (credentials?.expiresAt) {
|
|
177
|
+
const expiresIn = Math.round((credentials.expiresAt - Date.now()) / 1000 / 60);
|
|
178
|
+
if (expiresIn > 0) {
|
|
179
|
+
ui.print(` Token expires in: ${expiresIn} minutes`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/auth/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAGL,WAAW,EACX,sBAAsB,GACvB,MAA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;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,eAAe,EAAE,CAAC;IAEnD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,EAAE,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC;QACtC,OAAO;IACT,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,cAAc,EAAE,CAAC;IACvD,MAAM,KAAK,GAAG,WAAW,EAAE,KAAK,IAAI,SAAS,CAAC;IAC9C,MAAM,aAAa,GAAG,MAAM,WAAW,CAAC,YAAY,EAAE,CAAC;IAEvD,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC9B,EAAE,CAAC,KAAK,CAAC,YAAY,KAAK,EAAE,CAAC,CAAC;IAC9B,EAAE,CAAC,KAAK,CACN,mBAAmB,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,sCAAsC,EAAE,CACtF,CAAC;IAEF,IAAI,WAAW,EAAE,SAAS,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAC1B,CAAC,WAAW,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,EAAE,CACjD,CAAC;QACF,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YAClB,EAAE,CAAC,KAAK,CAAC,uBAAuB,SAAS,UAAU,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disable_telemetry_command.d.ts","sourceRoot":"","sources":["../../../../src/commands/auth/disable_telemetry_command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqBpC,eAAO,MAAM,uBAAuB,SAEH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enable_telemetry_command.d.ts","sourceRoot":"","sources":["../../../../src/commands/auth/enable_telemetry_command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,eAAO,MAAM,sBAAsB,SAEH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login_ci_command.d.ts","sourceRoot":"","sources":["../../../../src/commands/auth/login_ci_command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkDpC,eAAO,MAAM,cAAc,SAQH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { authManager } from '@/auth/manager';
|
|
3
|
+
import { INWORLD_ENV } from '@/constants';
|
|
4
|
+
import { WorkspaceService } from '@/services/workspace_service.js';
|
|
5
|
+
import { setGlobalForceYes } from '@/utils/confirm.js';
|
|
6
|
+
import * as ui from '@/utils/ui';
|
|
7
|
+
const loginCiAction = async (options) => {
|
|
8
|
+
try {
|
|
9
|
+
// Enable auto-confirm for all prompts in CI mode
|
|
10
|
+
setGlobalForceYes(true);
|
|
11
|
+
console.log();
|
|
12
|
+
ui.printHeader('🎭 Authenticating with external Firebase token');
|
|
13
|
+
console.log();
|
|
14
|
+
const success = await authManager.authenticateAndSaveCredentials(options.token, options.refreshToken || options.token, // Use token as fallback if no refresh token
|
|
15
|
+
options.email,
|
|
16
|
+
/* workspace */ undefined, INWORLD_ENV);
|
|
17
|
+
if (!success) {
|
|
18
|
+
ui.printError('Failed to authenticate with provided token');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
console.log();
|
|
22
|
+
ui.success('✓ Authentication successful!');
|
|
23
|
+
ui.print(`Email: ${options.email}`);
|
|
24
|
+
await WorkspaceService.activateWorkspace({ forceFirst: true });
|
|
25
|
+
ui.print('\nAuthentication completed.');
|
|
26
|
+
process.exit(0);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.log();
|
|
30
|
+
ui.printError('Token-based authentication failed:');
|
|
31
|
+
console.error(error);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export const loginCiCommand = new Command('login-ci')
|
|
36
|
+
.description('Authenticate using Firebase token (for CI/testing)')
|
|
37
|
+
.requiredOption('-t, --token <token>', 'Firebase ID token')
|
|
38
|
+
.requiredOption('-e, --email <email>', 'Email address')
|
|
39
|
+
.option('-r, --refresh-token <refreshToken>', 'Firebase refresh token (optional, enables token refresh)')
|
|
40
|
+
.action(loginCiAction);
|
|
41
|
+
//# sourceMappingURL=login_ci_command.js.map
|