aranea-sdk-cli 0.3.6 → 0.3.8

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.
@@ -55,6 +55,7 @@ const axios_1 = __importDefault(require("axios"));
55
55
  const fs = __importStar(require("fs"));
56
56
  const path = __importStar(require("path"));
57
57
  const config_1 = require("../config");
58
+ const auth_1 = require("./auth");
58
59
  // ============================================================================
59
60
  // Config
60
61
  // ============================================================================
@@ -71,10 +72,15 @@ const CATEGORIES = ['api', 'guide', 'code', 'reference', 'incident', 'tip'];
71
72
  // Helper Functions
72
73
  // ============================================================================
73
74
  /**
74
- * Firebase Auth トークンを環境変数から取得
75
+ * Firebase Auth トークンを取得(保存済み認証情報 or 環境変数)
75
76
  */
76
- function getAuthToken() {
77
- return process.env.ARANEA_AUTH_TOKEN || process.env.FIREBASE_AUTH_TOKEN || null;
77
+ async function getAuthToken() {
78
+ // 1. 環境変数を優先
79
+ const envToken = process.env.ARANEA_AUTH_TOKEN || process.env.FIREBASE_AUTH_TOKEN;
80
+ if (envToken)
81
+ return envToken;
82
+ // 2. 保存済み認証情報から取得(自動リフレッシュ含む)
83
+ return await (0, auth_1.getValidToken)();
78
84
  }
79
85
  /**
80
86
  * API呼び出し(Callable形式)
@@ -143,10 +149,11 @@ exports.knowledgeCommand
143
149
  .action(async (options) => {
144
150
  try {
145
151
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
152
+ (0, config_1.checkStagingAvailability)(env, 'knowledge add --title <title> --category <cat>');
146
153
  (0, config_1.warnIfProduction)(env, 'knowledge add');
147
154
  console.log(chalk_1.default.bold(`\n=== Knowledge Add (${env}) ===\n`));
148
155
  // 認証トークン
149
- const token = options.token || getAuthToken();
156
+ const token = options.token || await getAuthToken();
150
157
  if (!token) {
151
158
  console.error(chalk_1.default.red('❌ 認証トークンが必要です。--token または ARANEA_AUTH_TOKEN 環境変数を設定'));
152
159
  process.exit(1);
@@ -228,8 +235,9 @@ exports.knowledgeCommand
228
235
  .action(async (options) => {
229
236
  try {
230
237
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
238
+ (0, config_1.checkStagingAvailability)(env, 'knowledge search --query <query>');
231
239
  console.log(chalk_1.default.bold(`\n=== Knowledge Search (${env}) ===\n`));
232
- const token = options.token || getAuthToken();
240
+ const token = options.token || await getAuthToken();
233
241
  if (!token) {
234
242
  console.error(chalk_1.default.red('❌ 認証トークンが必要です'));
235
243
  process.exit(1);
@@ -272,8 +280,9 @@ exports.knowledgeCommand
272
280
  .action(async (options) => {
273
281
  try {
274
282
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
283
+ (0, config_1.checkStagingAvailability)(env, 'knowledge list');
275
284
  console.log(chalk_1.default.bold(`\n=== Knowledge List (${env}) ===\n`));
276
- const token = options.token || getAuthToken();
285
+ const token = options.token || await getAuthToken();
277
286
  if (!token) {
278
287
  console.error(chalk_1.default.red('❌ 認証トークンが必要です'));
279
288
  process.exit(1);
@@ -314,8 +323,9 @@ exports.knowledgeCommand
314
323
  .action(async (options) => {
315
324
  try {
316
325
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
326
+ (0, config_1.checkStagingAvailability)(env, 'knowledge get --id <id>');
317
327
  console.log(chalk_1.default.bold(`\n=== Knowledge Get (${env}) ===\n`));
318
- const token = options.token || getAuthToken();
328
+ const token = options.token || await getAuthToken();
319
329
  if (!token) {
320
330
  console.error(chalk_1.default.red('❌ 認証トークンが必要です'));
321
331
  process.exit(1);
@@ -346,9 +356,10 @@ exports.knowledgeCommand
346
356
  .action(async (options) => {
347
357
  try {
348
358
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
359
+ (0, config_1.checkStagingAvailability)(env, 'knowledge delete --id <id>');
349
360
  (0, config_1.warnIfProduction)(env, 'knowledge delete');
350
361
  console.log(chalk_1.default.bold(`\n=== Knowledge Delete (${env}) ===\n`));
351
- const token = options.token || getAuthToken();
362
+ const token = options.token || await getAuthToken();
352
363
  if (!token) {
353
364
  console.error(chalk_1.default.red('❌ 認証トークンが必要です'));
354
365
  process.exit(1);
@@ -52,6 +52,7 @@ const ora_1 = __importDefault(require("ora"));
52
52
  const axios_1 = __importDefault(require("axios"));
53
53
  const readline = __importStar(require("readline"));
54
54
  const config_1 = require("../config");
55
+ const auth_1 = require("./auth");
55
56
  // ============================================================================
56
57
  // Config
57
58
  // ============================================================================
@@ -66,10 +67,13 @@ function getMetatronApiBase(env) {
66
67
  // Helper Functions
67
68
  // ============================================================================
68
69
  /**
69
- * Firebase Auth トークンを環境変数から取得
70
+ * Firebase Auth トークンを取得(保存済み認証情報 or 環境変数)
70
71
  */
71
- function getAuthToken() {
72
- return process.env.ARANEA_AUTH_TOKEN || process.env.FIREBASE_AUTH_TOKEN || null;
72
+ async function getAuthToken() {
73
+ const envToken = process.env.ARANEA_AUTH_TOKEN || process.env.FIREBASE_AUTH_TOKEN;
74
+ if (envToken)
75
+ return envToken;
76
+ return await (0, auth_1.getValidToken)();
73
77
  }
74
78
  /**
75
79
  * Metatron API呼び出し
@@ -123,11 +127,12 @@ exports.metatronCommand
123
127
  .action(async (question, options) => {
124
128
  try {
125
129
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
130
+ (0, config_1.checkStagingAvailability)(env, 'metatron ask "<question>"');
126
131
  if (!options.raw) {
127
132
  console.log(chalk_1.default.bold(`\n=== AraneaMetatron (${env}) ===\n`));
128
133
  console.log(chalk_1.default.gray(`Q: ${question}`));
129
134
  }
130
- const token = options.token || getAuthToken();
135
+ const token = options.token || await getAuthToken();
131
136
  if (!token) {
132
137
  console.error(chalk_1.default.red('❌ 認証トークンが必要です。--token または ARANEA_AUTH_TOKEN 環境変数を設定'));
133
138
  process.exit(1);
@@ -156,10 +161,11 @@ exports.metatronCommand
156
161
  .option('-e, --endpoint <env>', '環境 (staging|production)', 'production')
157
162
  .action(async (options) => {
158
163
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
164
+ (0, config_1.checkStagingAvailability)(env, 'metatron chat');
159
165
  console.log(chalk_1.default.bold(`\n=== AraneaMetatron Chat (${env}) ===\n`));
160
166
  console.log(chalk_1.default.gray('AraneaSDKについて質問してください。'));
161
167
  console.log(chalk_1.default.gray('終了するには "exit" または Ctrl+C を入力\n'));
162
- const token = options.token || getAuthToken();
168
+ const token = options.token || await getAuthToken();
163
169
  if (!token) {
164
170
  console.error(chalk_1.default.red('❌ 認証トークンが必要です。--token または ARANEA_AUTH_TOKEN 環境変数を設定'));
165
171
  process.exit(1);
@@ -165,6 +165,8 @@ exports.schemaCommand
165
165
  .option('-e, --endpoint <env>', 'Environment (staging|production)', 'staging')
166
166
  .action(async (options) => {
167
167
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
168
+ // Check staging availability
169
+ (0, config_1.checkStagingAvailability)(env, 'schema list');
168
170
  const apiBase = getSchemaApiBase(env);
169
171
  const spinner = (0, ora_1.default)(`Fetching schema list from ${env}...`).start();
170
172
  try {
@@ -211,6 +213,8 @@ exports.schemaCommand
211
213
  .option('--json', 'Output as JSON')
212
214
  .action(async (options) => {
213
215
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
216
+ // Check staging availability
217
+ (0, config_1.checkStagingAvailability)(env, 'schema get --type <type>');
214
218
  const apiBase = getSchemaApiBase(env);
215
219
  const spinner = (0, ora_1.default)(`Fetching schema for ${options.type} from ${env}...`).start();
216
220
  try {
@@ -358,6 +362,8 @@ exports.schemaCommand
358
362
  .option('-e, --endpoint <env>', 'Environment (staging|production)', 'staging')
359
363
  .action(async (options) => {
360
364
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
365
+ // Check staging availability
366
+ (0, config_1.checkStagingAvailability)(env, 'schema validate --type <type> --file <file>');
361
367
  const apiBase = getSchemaApiBase(env);
362
368
  const spinner = (0, ora_1.default)('Validating...').start();
363
369
  try {
@@ -553,7 +559,7 @@ exports.schemaCommand
553
559
  .action(async (options) => {
554
560
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
555
561
  // Check staging availability
556
- (0, config_1.checkStagingAvailability)(env, 'schema push --endpoint production');
562
+ (0, config_1.checkStagingAvailability)(env, 'schema push --file <file>');
557
563
  // Require --force for production
558
564
  if (!options.dryRun && !(0, config_1.requireProductionConfirmation)(env, 'schema push', options.force)) {
559
565
  process.exit(1);
@@ -688,6 +694,8 @@ exports.schemaCommand
688
694
  .option('-y, --confirm', 'Skip confirmation prompt')
689
695
  .action(async (options) => {
690
696
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
697
+ // Check staging availability
698
+ (0, config_1.checkStagingAvailability)(env, 'schema promote --type <type>');
691
699
  const apiBase = getSchemaApiBase(env);
692
700
  // Always warn for promote
693
701
  console.log(chalk_1.default.yellow(`\nPromoting schema to PRODUCTION state in ${env} environment\n`));
@@ -794,6 +802,8 @@ exports.schemaCommand
794
802
  .option('--json', 'Output as JSON')
795
803
  .action(async (options) => {
796
804
  const env = (0, config_1.resolveEnvironment)(options.endpoint);
805
+ // Check staging availability
806
+ (0, config_1.checkStagingAvailability)(env, 'schema info --type <type>');
797
807
  const apiBase = getSchemaApiBase(env);
798
808
  const spinner = (0, ora_1.default)(`Fetching schema info: ${options.type} from ${env}...`).start();
799
809
  try {
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ const program = new commander_1.Command();
28
28
  program
29
29
  .name('aranea-sdk')
30
30
  .description('AraneaSDK CLI - デバイス開発支援ツール')
31
- .version('0.3.6');
31
+ .version('0.3.8');
32
32
  // test コマンド
33
33
  program.addCommand(test_1.testCommand);
34
34
  // simulate コマンド
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aranea-sdk-cli",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "AraneaSDK CLI - ESP32 IoTデバイス開発支援ツール",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",