aranea-sdk-cli 0.5.5 → 0.5.6
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/commands/auth.js +188 -0
- package/dist/commands/permission.js +2 -1
- package/package.json +2 -2
package/dist/commands/auth.js
CHANGED
|
@@ -426,3 +426,191 @@ exports.authCommand
|
|
|
426
426
|
console.log(chalk_1.default.green('\n✓ Credentials cleared.'));
|
|
427
427
|
console.log(` Removed: ${CREDENTIALS_FILE}`);
|
|
428
428
|
});
|
|
429
|
+
// auth check-cic
|
|
430
|
+
exports.authCommand
|
|
431
|
+
.command('check-cic <cic>')
|
|
432
|
+
.description('Check if a CIC code is registered')
|
|
433
|
+
.option('--tid <tid>', 'Filter by tenant ID')
|
|
434
|
+
.option('--json', 'Output as JSON')
|
|
435
|
+
.action(async (cic, options) => {
|
|
436
|
+
const credentials = loadCredentials();
|
|
437
|
+
if (!credentials) {
|
|
438
|
+
console.log(chalk_1.default.yellow('\nNo saved credentials found.'));
|
|
439
|
+
console.log('Run "aranea-sdk auth login" to authenticate.');
|
|
440
|
+
process.exit(1);
|
|
441
|
+
}
|
|
442
|
+
// Ensure valid token
|
|
443
|
+
let token = credentials.idToken;
|
|
444
|
+
if (isTokenExpired(credentials)) {
|
|
445
|
+
try {
|
|
446
|
+
const newCredentials = await refreshIdToken(credentials.refreshToken);
|
|
447
|
+
saveCredentials(newCredentials);
|
|
448
|
+
token = newCredentials.idToken;
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
console.error(chalk_1.default.red('Token expired and refresh failed. Please login again.'));
|
|
452
|
+
process.exit(1);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
// Normalize CIC (6 digits)
|
|
456
|
+
const normalizedCIC = cic.replace(/\D/g, '').padStart(6, '0');
|
|
457
|
+
if (normalizedCIC.length !== 6) {
|
|
458
|
+
console.error(chalk_1.default.red(`Invalid CIC format: ${cic}. Must be 6 digits.`));
|
|
459
|
+
process.exit(1);
|
|
460
|
+
}
|
|
461
|
+
if (!options.json) {
|
|
462
|
+
console.log(chalk_1.default.cyan(`\n=== CIC Check: ${normalizedCIC} ===\n`));
|
|
463
|
+
}
|
|
464
|
+
try {
|
|
465
|
+
const projectId = 'mobesorder';
|
|
466
|
+
const results = [];
|
|
467
|
+
// 1. Search AraneaDevice: userObject where lacis.cic == normalizedCIC
|
|
468
|
+
const deviceUrl = `https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents:runQuery`;
|
|
469
|
+
const deviceQuery = {
|
|
470
|
+
structuredQuery: {
|
|
471
|
+
from: [{ collectionId: 'userObject' }],
|
|
472
|
+
where: {
|
|
473
|
+
fieldFilter: {
|
|
474
|
+
field: { fieldPath: 'lacis.cic' },
|
|
475
|
+
op: 'EQUAL',
|
|
476
|
+
value: { stringValue: normalizedCIC },
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
limit: 10,
|
|
480
|
+
},
|
|
481
|
+
};
|
|
482
|
+
const deviceResponse = await fetch(deviceUrl, {
|
|
483
|
+
method: 'POST',
|
|
484
|
+
headers: {
|
|
485
|
+
'Content-Type': 'application/json',
|
|
486
|
+
Authorization: `Bearer ${token}`,
|
|
487
|
+
},
|
|
488
|
+
body: JSON.stringify(deviceQuery),
|
|
489
|
+
});
|
|
490
|
+
if (deviceResponse.ok) {
|
|
491
|
+
const deviceData = await deviceResponse.json();
|
|
492
|
+
for (const item of deviceData) {
|
|
493
|
+
if (item.document) {
|
|
494
|
+
const docPath = item.document.name;
|
|
495
|
+
const lacisId = docPath.split('/').pop() || '';
|
|
496
|
+
const fields = item.document.fields;
|
|
497
|
+
const lacisFields = fields.lacis?.mapValue?.fields;
|
|
498
|
+
const baseFields = fields.base?.mapValue?.fields;
|
|
499
|
+
// tid filter
|
|
500
|
+
const docTid = lacisFields?.tid?.stringValue;
|
|
501
|
+
if (options.tid && docTid !== options.tid)
|
|
502
|
+
continue;
|
|
503
|
+
results.push({
|
|
504
|
+
type: 'AraneaDevice',
|
|
505
|
+
lacisId,
|
|
506
|
+
tid: docTid,
|
|
507
|
+
typeDomain: lacisFields?.type_domain?.stringValue,
|
|
508
|
+
deviceType: lacisFields?.type?.stringValue,
|
|
509
|
+
displayName: baseFields?.display_name?.stringValue,
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// 2. Search HumanUser: userObject_detail where cic_code == normalizedCIC
|
|
515
|
+
const userQuery = {
|
|
516
|
+
structuredQuery: {
|
|
517
|
+
from: [{ collectionId: 'userObject_detail' }],
|
|
518
|
+
where: {
|
|
519
|
+
compositeFilter: {
|
|
520
|
+
op: 'AND',
|
|
521
|
+
filters: [
|
|
522
|
+
{
|
|
523
|
+
fieldFilter: {
|
|
524
|
+
field: { fieldPath: 'cic_code' },
|
|
525
|
+
op: 'EQUAL',
|
|
526
|
+
value: { stringValue: normalizedCIC },
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
fieldFilter: {
|
|
531
|
+
field: { fieldPath: 'cic_active' },
|
|
532
|
+
op: 'EQUAL',
|
|
533
|
+
value: { booleanValue: true },
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
],
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
limit: 10,
|
|
540
|
+
},
|
|
541
|
+
};
|
|
542
|
+
const userResponse = await fetch(deviceUrl, {
|
|
543
|
+
method: 'POST',
|
|
544
|
+
headers: {
|
|
545
|
+
'Content-Type': 'application/json',
|
|
546
|
+
Authorization: `Bearer ${token}`,
|
|
547
|
+
},
|
|
548
|
+
body: JSON.stringify(userQuery),
|
|
549
|
+
});
|
|
550
|
+
if (userResponse.ok) {
|
|
551
|
+
const userData = await userResponse.json();
|
|
552
|
+
for (const item of userData) {
|
|
553
|
+
if (item.document) {
|
|
554
|
+
const docPath = item.document.name;
|
|
555
|
+
const lacisId = docPath.split('/').pop() || '';
|
|
556
|
+
// Fetch corresponding userObject to get tid
|
|
557
|
+
const userObjUrl = `https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents/userObject/${lacisId}`;
|
|
558
|
+
const userObjResponse = await fetch(userObjUrl, {
|
|
559
|
+
method: 'GET',
|
|
560
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
561
|
+
});
|
|
562
|
+
if (userObjResponse.ok) {
|
|
563
|
+
const userObjData = await userObjResponse.json();
|
|
564
|
+
const fields = userObjData.fields;
|
|
565
|
+
const lacisFields = fields.lacis?.mapValue?.fields;
|
|
566
|
+
const baseFields = fields.base?.mapValue?.fields;
|
|
567
|
+
const docTid = lacisFields?.tid?.stringValue;
|
|
568
|
+
if (options.tid && docTid !== options.tid)
|
|
569
|
+
continue;
|
|
570
|
+
results.push({
|
|
571
|
+
type: 'HumanUser',
|
|
572
|
+
lacisId,
|
|
573
|
+
tid: docTid,
|
|
574
|
+
typeDomain: lacisFields?.type_domain?.stringValue,
|
|
575
|
+
displayName: baseFields?.display_name?.stringValue,
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
// Output results
|
|
582
|
+
if (options.json) {
|
|
583
|
+
console.log(JSON.stringify({
|
|
584
|
+
cic: normalizedCIC,
|
|
585
|
+
registered: results.length > 0,
|
|
586
|
+
count: results.length,
|
|
587
|
+
entries: results,
|
|
588
|
+
}, null, 2));
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
if (results.length === 0) {
|
|
592
|
+
console.log(chalk_1.default.yellow(`CIC ${normalizedCIC} is not registered.`));
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
console.log(chalk_1.default.green(`✓ CIC ${normalizedCIC} is registered (${results.length} entries)\n`));
|
|
596
|
+
for (const entry of results) {
|
|
597
|
+
console.log(` ${chalk_1.default.cyan('●')} ${chalk_1.default.bold(entry.type)}`);
|
|
598
|
+
console.log(` LacisID: ${entry.lacisId}`);
|
|
599
|
+
if (entry.tid)
|
|
600
|
+
console.log(` TID: ${entry.tid}`);
|
|
601
|
+
if (entry.typeDomain)
|
|
602
|
+
console.log(` TypeDomain: ${entry.typeDomain}`);
|
|
603
|
+
if (entry.deviceType)
|
|
604
|
+
console.log(` DeviceType: ${entry.deviceType}`);
|
|
605
|
+
if (entry.displayName)
|
|
606
|
+
console.log(` DisplayName: ${entry.displayName}`);
|
|
607
|
+
console.log('');
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
catch (error) {
|
|
613
|
+
console.error(chalk_1.default.red(`\n✖ CIC check failed: ${error.message}`));
|
|
614
|
+
process.exit(1);
|
|
615
|
+
}
|
|
616
|
+
});
|
|
@@ -26,7 +26,8 @@ const FIREBASE_PROJECTS = {
|
|
|
26
26
|
production: 'mobesorder',
|
|
27
27
|
staging: 'mobesorder-staging',
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
// Note: LacisOath functions are deployed in us-central1 (default region)
|
|
30
|
+
const FIREBASE_REGION = 'us-central1';
|
|
30
31
|
/**
|
|
31
32
|
* Call Firebase Callable Function
|
|
32
33
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aranea-sdk-cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "AraneaSDK CLI - ESP32 IoTデバイス開発支援ツール",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=18.0.0"
|
|
62
62
|
},
|
|
63
|
-
|
|
63
|
+
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
}
|
|
66
66
|
}
|