@credibledata/cred-cli 0.0.100 → 0.0.103
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/README-DEV.md +2 -2
- package/README.md +1 -1
- package/coverage/coverage-summary.json +40 -0
- package/coverage/tmp/coverage-2152-1789496974457-0.json +1 -0
- package/coverage/tmp/coverage-2153-1789496954404-0.json +1 -0
- package/dist/client/api.js +6151 -2254
- package/dist/client/api.js.map +1 -1
- package/dist/client/base.js +1 -1
- package/dist/client/common.js +1 -1
- package/dist/client/configuration.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/clientconfiguration.js +114 -26
- package/dist/clientconfiguration.js.map +1 -1
- package/dist/clientconfiguration.spec.js +159 -37
- package/dist/clientconfiguration.spec.js.map +1 -1
- package/dist/commands/add.js +36 -5
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/connection/createconnections.js +4 -4
- package/dist/commands/connection/createconnections.js.map +1 -1
- package/dist/commands/connection/createconnections.spec.js +11 -1
- package/dist/commands/connection/createconnections.spec.js.map +1 -1
- package/dist/commands/connection/deleteconnection.js +4 -4
- package/dist/commands/connection/deleteconnection.js.map +1 -1
- package/dist/commands/connection/deleteconnection.spec.js +1 -1
- package/dist/commands/connection/deleteconnection.spec.js.map +1 -1
- package/dist/commands/connection/listconnections.js +4 -4
- package/dist/commands/connection/listconnections.js.map +1 -1
- package/dist/commands/connection/listconnections.spec.js +1 -1
- package/dist/commands/connection/listconnections.spec.js.map +1 -1
- package/dist/commands/{project/createproject.js → environment/createenvironment.js} +17 -14
- package/dist/commands/environment/createenvironment.js.map +1 -0
- package/dist/commands/{project/createproject.spec.js → environment/createenvironment.spec.js} +46 -46
- package/dist/commands/environment/createenvironment.spec.js.map +1 -0
- package/dist/commands/{project/deleteproject.js → environment/deleteenvironment.js} +9 -9
- package/dist/commands/environment/deleteenvironment.js.map +1 -0
- package/dist/commands/{project/deleteproject.spec.js → environment/deleteenvironment.spec.js} +29 -29
- package/dist/commands/environment/deleteenvironment.spec.js.map +1 -0
- package/dist/commands/{project/getproject.js → environment/getenvironment.js} +8 -8
- package/dist/commands/environment/getenvironment.js.map +1 -0
- package/dist/commands/{project/getproject.spec.js → environment/getenvironment.spec.js} +32 -33
- package/dist/commands/environment/getenvironment.spec.js.map +1 -0
- package/dist/commands/{project/listprojects.js → environment/listenvironments.js} +10 -10
- package/dist/commands/environment/listenvironments.js.map +1 -0
- package/dist/commands/{project/listprojects.spec.js → environment/listenvironments.spec.js} +35 -35
- package/dist/commands/environment/listenvironments.spec.js.map +1 -0
- package/dist/commands/{project/setproject.js → environment/setenvironment.js} +6 -5
- package/dist/commands/environment/setenvironment.js.map +1 -0
- package/dist/commands/{project/setproject.spec.js → environment/setenvironment.spec.js} +9 -9
- package/dist/commands/environment/setenvironment.spec.js.map +1 -0
- package/dist/commands/environment/updateenvironment.js +130 -0
- package/dist/commands/environment/updateenvironment.js.map +1 -0
- package/dist/commands/environment/updateenvironment.spec.js +213 -0
- package/dist/commands/environment/updateenvironment.spec.js.map +1 -0
- package/dist/commands/get.js +66 -5
- package/dist/commands/get.js.map +1 -1
- package/dist/commands/legacy.js +9 -0
- package/dist/commands/legacy.js.map +1 -0
- package/dist/commands/list.js +95 -4
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/materialization/cancelrun.js +62 -0
- package/dist/commands/materialization/cancelrun.js.map +1 -0
- package/dist/commands/materialization/getindex.js +52 -0
- package/dist/commands/materialization/getindex.js.map +1 -0
- package/dist/commands/materialization/getmaterialization.js +54 -0
- package/dist/commands/materialization/getmaterialization.js.map +1 -0
- package/dist/commands/materialization/getpreaggregate.js +55 -0
- package/dist/commands/materialization/getpreaggregate.js.map +1 -0
- package/dist/commands/materialization/getrun.js +54 -0
- package/dist/commands/materialization/getrun.js.map +1 -0
- package/dist/commands/materialization/listindexes.js +58 -0
- package/dist/commands/materialization/listindexes.js.map +1 -0
- package/dist/commands/materialization/listmaterializations.js +52 -0
- package/dist/commands/materialization/listmaterializations.js.map +1 -0
- package/dist/commands/materialization/listpreaggregates.js +61 -0
- package/dist/commands/materialization/listpreaggregates.js.map +1 -0
- package/dist/commands/materialization/listruns.js +60 -0
- package/dist/commands/materialization/listruns.js.map +1 -0
- package/dist/commands/materialization/rerun.js +111 -0
- package/dist/commands/materialization/rerun.js.map +1 -0
- package/dist/commands/misc/login.js +16 -2
- package/dist/commands/misc/login.js.map +1 -1
- package/dist/commands/misc/login.spec.js +133 -5
- package/dist/commands/misc/login.spec.js.map +1 -1
- package/dist/commands/package/deletepackage.js +4 -4
- package/dist/commands/package/deletepackage.js.map +1 -1
- package/dist/commands/package/deletepackage.spec.js +1 -1
- package/dist/commands/package/deletepackage.spec.js.map +1 -1
- package/dist/commands/package/listpackages.js +11 -4
- package/dist/commands/package/listpackages.js.map +1 -1
- package/dist/commands/package/listpackages.spec.js +13 -1
- package/dist/commands/package/listpackages.spec.js.map +1 -1
- package/dist/commands/package/publish.js +36 -13
- package/dist/commands/package/publish.js.map +1 -1
- package/dist/commands/package/publish.spec.js +27 -1
- package/dist/commands/package/publish.spec.js.map +1 -1
- package/dist/commands/package/updatepackage.js +4 -4
- package/dist/commands/package/updatepackage.js.map +1 -1
- package/dist/commands/package/updatepackage.spec.js +1 -1
- package/dist/commands/package/updatepackage.spec.js.map +1 -1
- package/dist/commands/permission/createpermission.js +123 -0
- package/dist/commands/permission/createpermission.js.map +1 -0
- package/dist/commands/permission/createpermission.spec.js +360 -0
- package/dist/commands/permission/createpermission.spec.js.map +1 -0
- package/dist/commands/permission/deletepermission.js +86 -0
- package/dist/commands/permission/deletepermission.js.map +1 -0
- package/dist/commands/permission/getpermission.js +85 -0
- package/dist/commands/permission/getpermission.js.map +1 -0
- package/dist/commands/permission/listpermissions.js +75 -0
- package/dist/commands/permission/listpermissions.js.map +1 -0
- package/dist/commands/permission/scope.js +140 -0
- package/dist/commands/permission/scope.js.map +1 -0
- package/dist/commands/rm.js +26 -4
- package/dist/commands/rm.js.map +1 -1
- package/dist/commands/set.js +12 -4
- package/dist/commands/set.js.map +1 -1
- package/dist/commands/update.js +29 -10
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/version/archive-unarchive-version.js +4 -5
- package/dist/commands/version/archive-unarchive-version.js.map +1 -1
- package/dist/commands/version/archive-unarchive-version.spec.js +4 -4
- package/dist/commands/version/archive-unarchive-version.spec.js.map +1 -1
- package/dist/commands/version/listversions.js +4 -4
- package/dist/commands/version/listversions.js.map +1 -1
- package/dist/commands/version/listversions.spec.js +1 -1
- package/dist/commands/version/listversions.spec.js.map +1 -1
- package/dist/common/UserGroupId.js +1 -1
- package/dist/common/UserGroupId.js.map +1 -1
- package/dist/common/UserGroupId.spec.js +2 -4
- package/dist/common/UserGroupId.spec.js.map +1 -1
- package/dist/constants.js +95 -19
- package/dist/constants.js.map +1 -1
- package/dist/constants.spec.js +90 -0
- package/dist/constants.spec.js.map +1 -0
- package/dist/index.js +128 -15
- package/dist/index.js.map +1 -1
- package/dist/logger.js +5 -1
- package/dist/logger.js.map +1 -1
- package/openapitools.json +4 -1
- package/package.json +10 -9
- package/src/client/api.ts +9363 -3093
- package/src/client/base.ts +1 -1
- package/src/client/common.ts +1 -1
- package/src/client/configuration.ts +1 -1
- package/src/client/index.ts +1 -1
- package/src/clientconfiguration.spec.ts +238 -113
- package/src/clientconfiguration.ts +131 -30
- package/src/commands/add.ts +78 -12
- package/src/commands/connection/createconnections.spec.ts +11 -1
- package/src/commands/connection/createconnections.ts +4 -4
- package/src/commands/connection/deleteconnection.spec.ts +1 -1
- package/src/commands/connection/deleteconnection.ts +4 -4
- package/src/commands/connection/listconnections.spec.ts +1 -1
- package/src/commands/connection/listconnections.ts +4 -4
- package/src/commands/{project/createproject.spec.ts → environment/createenvironment.spec.ts} +56 -54
- package/src/commands/{project/createproject.ts → environment/createenvironment.ts} +17 -14
- package/src/commands/{project/deleteproject.spec.ts → environment/deleteenvironment.spec.ts} +59 -30
- package/src/commands/{project/deleteproject.ts → environment/deleteenvironment.ts} +10 -10
- package/src/commands/environment/getenvironment.spec.ts +110 -0
- package/src/commands/{project/getproject.ts → environment/getenvironment.ts} +9 -9
- package/src/commands/{project/listprojects.spec.ts → environment/listenvironments.spec.ts} +37 -35
- package/src/commands/{project/listprojects.ts → environment/listenvironments.ts} +13 -8
- package/src/commands/{project/setproject.spec.ts → environment/setenvironment.spec.ts} +8 -8
- package/src/commands/{project/setproject.ts → environment/setenvironment.ts} +4 -4
- package/src/commands/environment/updateenvironment.spec.ts +386 -0
- package/src/commands/environment/updateenvironment.ts +168 -0
- package/src/commands/get.ts +131 -9
- package/src/commands/legacy.ts +5 -0
- package/src/commands/list.ts +204 -9
- package/src/commands/materialization/cancelrun.ts +70 -0
- package/src/commands/materialization/getindex.ts +55 -0
- package/src/commands/materialization/getmaterialization.ts +57 -0
- package/src/commands/materialization/getpreaggregate.ts +58 -0
- package/src/commands/materialization/getrun.ts +55 -0
- package/src/commands/materialization/listindexes.ts +69 -0
- package/src/commands/materialization/listmaterializations.ts +53 -0
- package/src/commands/materialization/listpreaggregates.ts +74 -0
- package/src/commands/materialization/listruns.ts +77 -0
- package/src/commands/materialization/rerun.ts +123 -0
- package/src/commands/misc/login.spec.ts +165 -7
- package/src/commands/misc/login.ts +20 -2
- package/src/commands/package/deletepackage.spec.ts +1 -1
- package/src/commands/package/deletepackage.ts +4 -4
- package/src/commands/package/listpackages.spec.ts +17 -1
- package/src/commands/package/listpackages.ts +11 -4
- package/src/commands/package/publish.spec.ts +46 -1
- package/src/commands/package/publish.ts +38 -13
- package/src/commands/package/updatepackage.spec.ts +1 -1
- package/src/commands/package/updatepackage.ts +4 -4
- package/src/commands/permission/createpermission.spec.ts +507 -0
- package/src/commands/permission/createpermission.ts +181 -0
- package/src/commands/permission/deletepermission.ts +117 -0
- package/src/commands/permission/getpermission.ts +115 -0
- package/src/commands/permission/listpermissions.ts +101 -0
- package/src/commands/permission/scope.ts +180 -0
- package/src/commands/rm.ts +54 -9
- package/src/commands/set.ts +13 -4
- package/src/commands/update.ts +66 -23
- package/src/commands/version/archive-unarchive-version.spec.ts +4 -4
- package/src/commands/version/archive-unarchive-version.ts +4 -7
- package/src/commands/version/listversions.spec.ts +1 -1
- package/src/commands/version/listversions.ts +4 -4
- package/src/common/UserGroupId.spec.ts +2 -4
- package/src/common/UserGroupId.ts +1 -1
- package/src/constants.spec.ts +111 -0
- package/src/constants.ts +131 -19
- package/src/index.ts +187 -18
- package/src/logger.ts +5 -1
- package/bun.lock +0 -1158
- package/dist/commands/project/createproject.js.map +0 -1
- package/dist/commands/project/createproject.spec.js.map +0 -1
- package/dist/commands/project/deleteproject.js.map +0 -1
- package/dist/commands/project/deleteproject.spec.js.map +0 -1
- package/dist/commands/project/getproject.js.map +0 -1
- package/dist/commands/project/getproject.spec.js.map +0 -1
- package/dist/commands/project/listprojects.js.map +0 -1
- package/dist/commands/project/listprojects.spec.js.map +0 -1
- package/dist/commands/project/setproject.js.map +0 -1
- package/dist/commands/project/setproject.spec.js.map +0 -1
- package/dist/commands/project/updateproject.js +0 -68
- package/dist/commands/project/updateproject.js.map +0 -1
- package/dist/commands/project/updateproject.spec.js +0 -129
- package/dist/commands/project/updateproject.spec.js.map +0 -1
- package/src/commands/project/getproject.spec.ts +0 -109
- package/src/commands/project/updateproject.spec.ts +0 -217
- package/src/commands/project/updateproject.ts +0 -82
package/src/client/base.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
4
|
* Credible Admin API
|
|
5
|
-
* The Credible Admin API is a comprehensive REST API that empowers organizations to manage their Malloy data modeling ecosystem with enterprise-grade security and governance. This API provides programmatic access to all administrative functions, enabling seamless integration with existing workflows and automation systems. ## Key Features - **Organization Management**: Create and manage organizations with fine-grained access controls - **
|
|
5
|
+
* The Credible Admin API is a comprehensive REST API that empowers organizations to manage their Malloy data modeling ecosystem with enterprise-grade security and governance. This API provides programmatic access to all administrative functions, enabling seamless integration with existing workflows and automation systems. ## Key Features - **Organization Management**: Create and manage organizations with fine-grained access controls - **Environment & Package Lifecycle**: Full CRUD operations for environments, packages, and versions - **Connection Management**: Secure database connection configuration and management - **Permission Management**: Granular role-based access control (RBAC) at organization, environment, package, workspace, and document levels - **Workspace Management**: Collaborative workspaces for data modeling and analysis - **User & Group Management**: Comprehensive user administration with group-based permissions ## Resource Hierarchy The API follows a hierarchical resource structure with fine-grained permission management at each level: ``` Organizations ├── Permissions ├── Environments │ ├── Permissions │ ├── Packages │ │ ├── Permissions │ │ └── Versions │ └── Connections ├── Workspaces │ ├── Permissions │ └── Documents │ └── Permissions └── Groups ├── Permissions └── Members System-Level Resources: ├── Users ├── System Permissions └── Demo Operations ``` ## Authentication & Authorization All API endpoints require proper authentication. The API implements fine-grained authorization using role-based permissions: - **Admin**: Full access to all resources within scope - **Modeler**: Can create and modify data models and packages - **Viewer**: Read-only access to resources - **Manager**: Workspace management capabilities - **Editor**: Document editing permissions ## Rate Limiting & Best Practices - API requests are rate-limited to ensure system stability - Implement proper error handling and retry logic - Cache responses when appropriate to reduce API calls ## Support & Documentation For additional support, examples, and integration guides, visit our developer documentation or contact our support team.
|
|
6
6
|
*
|
|
7
7
|
* The version of the OpenAPI document: v0
|
|
8
8
|
* Contact: support@credibledata.com
|
package/src/client/common.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
4
|
* Credible Admin API
|
|
5
|
-
* The Credible Admin API is a comprehensive REST API that empowers organizations to manage their Malloy data modeling ecosystem with enterprise-grade security and governance. This API provides programmatic access to all administrative functions, enabling seamless integration with existing workflows and automation systems. ## Key Features - **Organization Management**: Create and manage organizations with fine-grained access controls - **
|
|
5
|
+
* The Credible Admin API is a comprehensive REST API that empowers organizations to manage their Malloy data modeling ecosystem with enterprise-grade security and governance. This API provides programmatic access to all administrative functions, enabling seamless integration with existing workflows and automation systems. ## Key Features - **Organization Management**: Create and manage organizations with fine-grained access controls - **Environment & Package Lifecycle**: Full CRUD operations for environments, packages, and versions - **Connection Management**: Secure database connection configuration and management - **Permission Management**: Granular role-based access control (RBAC) at organization, environment, package, workspace, and document levels - **Workspace Management**: Collaborative workspaces for data modeling and analysis - **User & Group Management**: Comprehensive user administration with group-based permissions ## Resource Hierarchy The API follows a hierarchical resource structure with fine-grained permission management at each level: ``` Organizations ├── Permissions ├── Environments │ ├── Permissions │ ├── Packages │ │ ├── Permissions │ │ └── Versions │ └── Connections ├── Workspaces │ ├── Permissions │ └── Documents │ └── Permissions └── Groups ├── Permissions └── Members System-Level Resources: ├── Users ├── System Permissions └── Demo Operations ``` ## Authentication & Authorization All API endpoints require proper authentication. The API implements fine-grained authorization using role-based permissions: - **Admin**: Full access to all resources within scope - **Modeler**: Can create and modify data models and packages - **Viewer**: Read-only access to resources - **Manager**: Workspace management capabilities - **Editor**: Document editing permissions ## Rate Limiting & Best Practices - API requests are rate-limited to ensure system stability - Implement proper error handling and retry logic - Cache responses when appropriate to reduce API calls ## Support & Documentation For additional support, examples, and integration guides, visit our developer documentation or contact our support team.
|
|
6
6
|
*
|
|
7
7
|
* The version of the OpenAPI document: v0
|
|
8
8
|
* Contact: support@credibledata.com
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
4
|
* Credible Admin API
|
|
5
|
-
* The Credible Admin API is a comprehensive REST API that empowers organizations to manage their Malloy data modeling ecosystem with enterprise-grade security and governance. This API provides programmatic access to all administrative functions, enabling seamless integration with existing workflows and automation systems. ## Key Features - **Organization Management**: Create and manage organizations with fine-grained access controls - **
|
|
5
|
+
* The Credible Admin API is a comprehensive REST API that empowers organizations to manage their Malloy data modeling ecosystem with enterprise-grade security and governance. This API provides programmatic access to all administrative functions, enabling seamless integration with existing workflows and automation systems. ## Key Features - **Organization Management**: Create and manage organizations with fine-grained access controls - **Environment & Package Lifecycle**: Full CRUD operations for environments, packages, and versions - **Connection Management**: Secure database connection configuration and management - **Permission Management**: Granular role-based access control (RBAC) at organization, environment, package, workspace, and document levels - **Workspace Management**: Collaborative workspaces for data modeling and analysis - **User & Group Management**: Comprehensive user administration with group-based permissions ## Resource Hierarchy The API follows a hierarchical resource structure with fine-grained permission management at each level: ``` Organizations ├── Permissions ├── Environments │ ├── Permissions │ ├── Packages │ │ ├── Permissions │ │ └── Versions │ └── Connections ├── Workspaces │ ├── Permissions │ └── Documents │ └── Permissions └── Groups ├── Permissions └── Members System-Level Resources: ├── Users ├── System Permissions └── Demo Operations ``` ## Authentication & Authorization All API endpoints require proper authentication. The API implements fine-grained authorization using role-based permissions: - **Admin**: Full access to all resources within scope - **Modeler**: Can create and modify data models and packages - **Viewer**: Read-only access to resources - **Manager**: Workspace management capabilities - **Editor**: Document editing permissions ## Rate Limiting & Best Practices - API requests are rate-limited to ensure system stability - Implement proper error handling and retry logic - Cache responses when appropriate to reduce API calls ## Support & Documentation For additional support, examples, and integration guides, visit our developer documentation or contact our support team.
|
|
6
6
|
*
|
|
7
7
|
* The version of the OpenAPI document: v0
|
|
8
8
|
* Contact: support@credibledata.com
|
package/src/client/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
4
|
* Credible Admin API
|
|
5
|
-
* The Credible Admin API is a comprehensive REST API that empowers organizations to manage their Malloy data modeling ecosystem with enterprise-grade security and governance. This API provides programmatic access to all administrative functions, enabling seamless integration with existing workflows and automation systems. ## Key Features - **Organization Management**: Create and manage organizations with fine-grained access controls - **
|
|
5
|
+
* The Credible Admin API is a comprehensive REST API that empowers organizations to manage their Malloy data modeling ecosystem with enterprise-grade security and governance. This API provides programmatic access to all administrative functions, enabling seamless integration with existing workflows and automation systems. ## Key Features - **Organization Management**: Create and manage organizations with fine-grained access controls - **Environment & Package Lifecycle**: Full CRUD operations for environments, packages, and versions - **Connection Management**: Secure database connection configuration and management - **Permission Management**: Granular role-based access control (RBAC) at organization, environment, package, workspace, and document levels - **Workspace Management**: Collaborative workspaces for data modeling and analysis - **User & Group Management**: Comprehensive user administration with group-based permissions ## Resource Hierarchy The API follows a hierarchical resource structure with fine-grained permission management at each level: ``` Organizations ├── Permissions ├── Environments │ ├── Permissions │ ├── Packages │ │ ├── Permissions │ │ └── Versions │ └── Connections ├── Workspaces │ ├── Permissions │ └── Documents │ └── Permissions └── Groups ├── Permissions └── Members System-Level Resources: ├── Users ├── System Permissions └── Demo Operations ``` ## Authentication & Authorization All API endpoints require proper authentication. The API implements fine-grained authorization using role-based permissions: - **Admin**: Full access to all resources within scope - **Modeler**: Can create and modify data models and packages - **Viewer**: Read-only access to resources - **Manager**: Workspace management capabilities - **Editor**: Document editing permissions ## Rate Limiting & Best Practices - API requests are rate-limited to ensure system stability - Implement proper error handling and retry logic - Cache responses when appropriate to reduce API calls ## Support & Documentation For additional support, examples, and integration guides, visit our developer documentation or contact our support team.
|
|
6
6
|
*
|
|
7
7
|
* The version of the OpenAPI document: v0
|
|
8
8
|
* Contact: support@credibledata.com
|
|
@@ -22,8 +22,21 @@ describe("ClientConfiguration", () => {
|
|
|
22
22
|
let clientConfig: ClientConfiguration;
|
|
23
23
|
let readFileSyncStub: sinon.SinonStub;
|
|
24
24
|
let writeFileSyncStub: sinon.SinonStub;
|
|
25
|
+
let renameSyncStub: sinon.SinonStub;
|
|
25
26
|
let customConfigPath: string;
|
|
26
27
|
|
|
28
|
+
// Simulate a real ENOENT from readFileSync (has `.code = "ENOENT"`).
|
|
29
|
+
// A bare `Error("File not found")` no longer triggers first-time-setup —
|
|
30
|
+
// loadConfig now rethrows non-ENOENT errors instead of silently masking them.
|
|
31
|
+
const enoent = () => Object.assign(new Error("ENOENT"), { code: "ENOENT" });
|
|
32
|
+
|
|
33
|
+
// Pull the most-recent persisted config payload off the stubs. Atomic writes
|
|
34
|
+
// go through writeFileSync(tmpPath, json) followed by renameSync(tmp, path).
|
|
35
|
+
const lastWrittenConfig = () => {
|
|
36
|
+
const args = writeFileSyncStub.lastCall.args;
|
|
37
|
+
return JSON.parse(args[1] as string);
|
|
38
|
+
};
|
|
39
|
+
|
|
27
40
|
beforeEach(() => {
|
|
28
41
|
customConfigPath = join(os.homedir(), ".cred_test");
|
|
29
42
|
clientConfig = new ClientConfiguration(customConfigPath);
|
|
@@ -32,6 +45,7 @@ describe("ClientConfiguration", () => {
|
|
|
32
45
|
|
|
33
46
|
readFileSyncStub = sinon.stub(fs, "readFileSync");
|
|
34
47
|
writeFileSyncStub = sinon.stub(fs, "writeFileSync");
|
|
48
|
+
renameSyncStub = sinon.stub(fs, "renameSync");
|
|
35
49
|
});
|
|
36
50
|
|
|
37
51
|
afterEach(() => {
|
|
@@ -43,7 +57,7 @@ describe("ClientConfiguration", () => {
|
|
|
43
57
|
});
|
|
44
58
|
|
|
45
59
|
it("should load the default config if the file does not exist", () => {
|
|
46
|
-
readFileSyncStub.throws(
|
|
60
|
+
readFileSyncStub.throws(enoent());
|
|
47
61
|
clientConfig.loadConfig();
|
|
48
62
|
expect(clientConfig["config"]).to.deep.equal({
|
|
49
63
|
configPerEnvironment: fullPerEnv(),
|
|
@@ -51,6 +65,21 @@ describe("ClientConfiguration", () => {
|
|
|
51
65
|
});
|
|
52
66
|
});
|
|
53
67
|
|
|
68
|
+
it("should throw loudly when the config file is unparseable", () => {
|
|
69
|
+
// Non-atomic writes from older binaries can leave `.cred` truncated.
|
|
70
|
+
// loadConfig must fail loud instead of silently overwriting — a silent
|
|
71
|
+
// reset erases the access token for every subsequent caller.
|
|
72
|
+
readFileSyncStub.returns("{ not json");
|
|
73
|
+
expect(() => clientConfig.loadConfig()).to.throw(/may be corrupt/);
|
|
74
|
+
expect(writeFileSyncStub.called).to.be.false;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should throw when readFileSync fails with a non-ENOENT error", () => {
|
|
78
|
+
const eacces = Object.assign(new Error("EACCES"), { code: "EACCES" });
|
|
79
|
+
readFileSyncStub.throws(eacces);
|
|
80
|
+
expect(() => clientConfig.loadConfig()).to.throw(/EACCES/);
|
|
81
|
+
});
|
|
82
|
+
|
|
54
83
|
it("should load the config file correctly", () => {
|
|
55
84
|
const mockConfig = {
|
|
56
85
|
configPerEnvironment: {
|
|
@@ -92,134 +121,106 @@ describe("ClientConfiguration", () => {
|
|
|
92
121
|
});
|
|
93
122
|
|
|
94
123
|
it("should set and get the project correctly", () => {
|
|
95
|
-
readFileSyncStub.throws(
|
|
124
|
+
readFileSyncStub.throws(enoent());
|
|
96
125
|
clientConfig.setProject("new-project");
|
|
97
126
|
|
|
98
|
-
expect(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
activeEnvironment: "production",
|
|
106
|
-
}),
|
|
107
|
-
),
|
|
108
|
-
).to.be.true;
|
|
127
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
128
|
+
configPerEnvironment: fullPerEnv({
|
|
129
|
+
production: { project: "new-project" },
|
|
130
|
+
}),
|
|
131
|
+
activeEnvironment: "production",
|
|
132
|
+
});
|
|
133
|
+
expect(renameSyncStub.lastCall.args[1]).to.equal(customConfigPath);
|
|
109
134
|
});
|
|
110
135
|
|
|
111
136
|
it("should set and get the access token correctly", () => {
|
|
112
|
-
readFileSyncStub.throws(
|
|
137
|
+
readFileSyncStub.throws(enoent());
|
|
113
138
|
clientConfig.setAccessToken(false, "token-123");
|
|
114
139
|
|
|
115
|
-
expect(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}),
|
|
125
|
-
activeEnvironment: "production",
|
|
126
|
-
}),
|
|
127
|
-
),
|
|
128
|
-
).to.be.true;
|
|
140
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
141
|
+
configPerEnvironment: fullPerEnv({
|
|
142
|
+
production: {
|
|
143
|
+
isServiceAccountToken: true,
|
|
144
|
+
accessToken: "token-123",
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
activeEnvironment: "production",
|
|
148
|
+
});
|
|
129
149
|
});
|
|
130
150
|
|
|
131
|
-
it("should
|
|
151
|
+
it("should preserve other per-env fields when setting access token", () => {
|
|
152
|
+
// Valid initial config (with an activeEnvironment so loadConfig accepts it).
|
|
132
153
|
readFileSyncStub.returns(
|
|
133
|
-
JSON.stringify({
|
|
154
|
+
JSON.stringify({
|
|
155
|
+
configPerEnvironment: {
|
|
156
|
+
production: {
|
|
157
|
+
auth: { username: "user", password: "pass" },
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
activeEnvironment: "production",
|
|
161
|
+
}),
|
|
134
162
|
);
|
|
135
163
|
clientConfig.setAccessToken(true, "new-token");
|
|
136
|
-
expect(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
accessToken: "new-token",
|
|
144
|
-
},
|
|
145
|
-
}),
|
|
146
|
-
activeEnvironment: "production",
|
|
147
|
-
}),
|
|
148
|
-
),
|
|
149
|
-
).to.be.true;
|
|
164
|
+
expect(lastWrittenConfig().configPerEnvironment.production).to.deep.equal(
|
|
165
|
+
{
|
|
166
|
+
auth: { username: "user", password: "pass" },
|
|
167
|
+
isServiceAccountToken: false,
|
|
168
|
+
accessToken: "new-token",
|
|
169
|
+
},
|
|
170
|
+
);
|
|
150
171
|
});
|
|
151
172
|
|
|
152
173
|
it("should set and get organization", () => {
|
|
153
|
-
readFileSyncStub.throws(
|
|
174
|
+
readFileSyncStub.throws(enoent());
|
|
154
175
|
clientConfig.setOrganization("my-org");
|
|
155
176
|
|
|
156
|
-
expect(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}),
|
|
163
|
-
activeEnvironment: "production",
|
|
164
|
-
}),
|
|
165
|
-
),
|
|
166
|
-
).to.be.true;
|
|
177
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
178
|
+
configPerEnvironment: fullPerEnv({
|
|
179
|
+
production: { organization: "my-org" },
|
|
180
|
+
}),
|
|
181
|
+
activeEnvironment: "production",
|
|
182
|
+
});
|
|
167
183
|
});
|
|
168
184
|
|
|
169
185
|
it("should set and get refresh token", () => {
|
|
170
|
-
readFileSyncStub.throws(
|
|
186
|
+
readFileSyncStub.throws(enoent());
|
|
171
187
|
clientConfig.setRefreshToken("refresh-token-123");
|
|
172
188
|
|
|
173
|
-
expect(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}),
|
|
180
|
-
activeEnvironment: "production",
|
|
181
|
-
}),
|
|
182
|
-
),
|
|
183
|
-
).to.be.true;
|
|
189
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
190
|
+
configPerEnvironment: fullPerEnv({
|
|
191
|
+
production: { refreshToken: "refresh-token-123" },
|
|
192
|
+
}),
|
|
193
|
+
activeEnvironment: "production",
|
|
194
|
+
});
|
|
184
195
|
});
|
|
185
196
|
|
|
186
197
|
it("should set and get VSCode user", () => {
|
|
187
|
-
readFileSyncStub.throws(
|
|
198
|
+
readFileSyncStub.throws(enoent());
|
|
188
199
|
clientConfig.setVSCodeUser("testuser", "test@example.com");
|
|
189
200
|
|
|
190
|
-
expect(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}),
|
|
202
|
-
activeEnvironment: "production",
|
|
203
|
-
}),
|
|
204
|
-
),
|
|
205
|
-
).to.be.true;
|
|
201
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
202
|
+
configPerEnvironment: fullPerEnv({
|
|
203
|
+
production: {
|
|
204
|
+
vsCodeUser: {
|
|
205
|
+
username: "testuser",
|
|
206
|
+
email: "test@example.com",
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
}),
|
|
210
|
+
activeEnvironment: "production",
|
|
211
|
+
});
|
|
206
212
|
});
|
|
207
213
|
|
|
208
214
|
it("should set and get JWT access token", () => {
|
|
209
|
-
readFileSyncStub.throws(
|
|
215
|
+
readFileSyncStub.throws(enoent());
|
|
210
216
|
clientConfig.setJwtAccessToken("jwt-token-abc");
|
|
211
217
|
|
|
212
|
-
expect(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}),
|
|
219
|
-
activeEnvironment: "production",
|
|
220
|
-
}),
|
|
221
|
-
),
|
|
222
|
-
).to.be.true;
|
|
218
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
219
|
+
configPerEnvironment: fullPerEnv({
|
|
220
|
+
production: { jwtAccessToken: "jwt-token-abc" },
|
|
221
|
+
}),
|
|
222
|
+
activeEnvironment: "production",
|
|
223
|
+
});
|
|
223
224
|
});
|
|
224
225
|
|
|
225
226
|
it("should return true for doesConfigExists when environment config exists", () => {
|
|
@@ -248,26 +249,20 @@ describe("ClientConfiguration", () => {
|
|
|
248
249
|
readFileSyncStub.returns(JSON.stringify(mockConfig));
|
|
249
250
|
clientConfig.destroyConfig();
|
|
250
251
|
|
|
251
|
-
|
|
252
|
-
expect(JSON.parse(lastWrite)).to.deep.equal({
|
|
252
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
253
253
|
configPerEnvironment: fullPerEnv(),
|
|
254
254
|
activeEnvironment: "production",
|
|
255
255
|
});
|
|
256
256
|
});
|
|
257
257
|
|
|
258
258
|
it("should set and get environment", () => {
|
|
259
|
-
readFileSyncStub.throws(
|
|
259
|
+
readFileSyncStub.throws(enoent());
|
|
260
260
|
clientConfig.setEnvironment("staging");
|
|
261
261
|
|
|
262
|
-
expect(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
configPerEnvironment: fullPerEnv(),
|
|
267
|
-
activeEnvironment: "staging",
|
|
268
|
-
}),
|
|
269
|
-
),
|
|
270
|
-
).to.be.true;
|
|
262
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
263
|
+
configPerEnvironment: fullPerEnv(),
|
|
264
|
+
activeEnvironment: "staging",
|
|
265
|
+
});
|
|
271
266
|
});
|
|
272
267
|
|
|
273
268
|
it("should return headers with Bearer token for user tokens", () => {
|
|
@@ -308,11 +303,82 @@ describe("ClientConfiguration", () => {
|
|
|
308
303
|
expect(headers.Authorization).to.equal("ApiKey service-token");
|
|
309
304
|
});
|
|
310
305
|
|
|
311
|
-
it("should
|
|
306
|
+
it("should throw when config file is missing activeEnvironment", () => {
|
|
307
|
+
// Previously loadConfig silently reset to defaults — that turned one
|
|
308
|
+
// corrupt read into permanent state loss for every caller. Now we fail loud.
|
|
312
309
|
readFileSyncStub.returns(JSON.stringify({ configPerEnvironment: {} }));
|
|
313
|
-
clientConfig.loadConfig()
|
|
310
|
+
expect(() => clientConfig.loadConfig()).to.throw(
|
|
311
|
+
/Invalid config structure/,
|
|
312
|
+
);
|
|
313
|
+
expect(writeFileSyncStub.called).to.be.false;
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
describe("recoverIfCorrupt", () => {
|
|
317
|
+
it("returns null and writes nothing when the config is already valid", () => {
|
|
318
|
+
readFileSyncStub.returns(
|
|
319
|
+
JSON.stringify({
|
|
320
|
+
configPerEnvironment: {},
|
|
321
|
+
activeEnvironment: "staging",
|
|
322
|
+
}),
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
expect(clientConfig.recoverIfCorrupt()).to.be.null;
|
|
326
|
+
expect(renameSyncStub.called).to.be.false;
|
|
327
|
+
// Valid config preserved — active environment untouched.
|
|
328
|
+
expect(clientConfig.getEnvironment()).to.equal("staging");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("backs up an unparseable file and resets to defaults", () => {
|
|
332
|
+
readFileSyncStub.returns("{ not json");
|
|
333
|
+
|
|
334
|
+
const backupPath = clientConfig.recoverIfCorrupt();
|
|
335
|
+
|
|
336
|
+
expect(backupPath).to.match(
|
|
337
|
+
new RegExp(`${customConfigPath}\\.corrupt-[0-9a-f]{16}$`),
|
|
338
|
+
);
|
|
339
|
+
// Renamed aside, never deleted, so the bad file is recoverable.
|
|
340
|
+
expect(renameSyncStub.calledWith(customConfigPath, backupPath!)).to.be
|
|
341
|
+
.true;
|
|
342
|
+
expect(lastWrittenConfig()).to.deep.equal({
|
|
343
|
+
configPerEnvironment: fullPerEnv(),
|
|
344
|
+
activeEnvironment: "production",
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("backs up a structurally-invalid file and resets to defaults", () => {
|
|
349
|
+
readFileSyncStub.returns(JSON.stringify({ configPerEnvironment: {} }));
|
|
350
|
+
|
|
351
|
+
const backupPath = clientConfig.recoverIfCorrupt();
|
|
352
|
+
|
|
353
|
+
expect(backupPath).to.be.a("string");
|
|
354
|
+
expect(renameSyncStub.calledWith(customConfigPath, backupPath!)).to.be
|
|
355
|
+
.true;
|
|
356
|
+
expect(lastWrittenConfig().activeEnvironment).to.equal("production");
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("rethrows fs errors (e.g. EACCES) instead of masking them as a reset", () => {
|
|
360
|
+
// A permissions problem must surface — resetting would just fail to
|
|
361
|
+
// write anyway, and silently "recovering" would hide the real cause.
|
|
362
|
+
const eacces = Object.assign(new Error("EACCES"), { code: "EACCES" });
|
|
363
|
+
readFileSyncStub.throws(eacces);
|
|
364
|
+
|
|
365
|
+
expect(() => clientConfig.recoverIfCorrupt()).to.throw(/EACCES/);
|
|
366
|
+
expect(renameSyncStub.called).to.be.false;
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("creates a fresh default when the file is absent (ENOENT)", () => {
|
|
370
|
+
readFileSyncStub.throws(enoent());
|
|
314
371
|
|
|
315
|
-
|
|
372
|
+
// First-time setup is not corruption — nothing to back up. (The atomic
|
|
373
|
+
// write of the new default does call renameSync, but never to a
|
|
374
|
+
// `.corrupt-` backup path.)
|
|
375
|
+
expect(clientConfig.recoverIfCorrupt()).to.be.null;
|
|
376
|
+
expect(
|
|
377
|
+
renameSyncStub
|
|
378
|
+
.getCalls()
|
|
379
|
+
.some((c) => String(c.args[1]).includes(".corrupt-")),
|
|
380
|
+
).to.be.false;
|
|
381
|
+
});
|
|
316
382
|
});
|
|
317
383
|
|
|
318
384
|
describe("isTokenValid", () => {
|
|
@@ -466,7 +532,66 @@ describe("ClientConfiguration", () => {
|
|
|
466
532
|
|
|
467
533
|
expect(loggerStub.info.calledWith(sinon.match("Organization:"))).to.be
|
|
468
534
|
.true;
|
|
469
|
-
expect(loggerStub.info.calledWith(sinon.match("
|
|
535
|
+
expect(loggerStub.info.calledWith(sinon.match("Environment:"))).to.be
|
|
536
|
+
.true;
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
it("should name the targeted cell when the token is valid", () => {
|
|
540
|
+
const payload = { exp: Math.floor(Date.now() / 1000) + 3600 };
|
|
541
|
+
const fakeJwt =
|
|
542
|
+
Buffer.from(JSON.stringify({ alg: "HS256" })).toString(
|
|
543
|
+
"base64url",
|
|
544
|
+
) +
|
|
545
|
+
"." +
|
|
546
|
+
Buffer.from(JSON.stringify(payload)).toString("base64url") +
|
|
547
|
+
".signature";
|
|
548
|
+
|
|
549
|
+
const mockConfig = {
|
|
550
|
+
configPerEnvironment: {
|
|
551
|
+
production: {},
|
|
552
|
+
staging: {},
|
|
553
|
+
localhost: {},
|
|
554
|
+
dev: {
|
|
555
|
+
accessToken: fakeJwt,
|
|
556
|
+
isServiceAccountToken: false,
|
|
557
|
+
organization: "demo",
|
|
558
|
+
project: "demo",
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
activeEnvironment: "dev",
|
|
562
|
+
};
|
|
563
|
+
readFileSyncStub.returns(JSON.stringify(mockConfig));
|
|
564
|
+
|
|
565
|
+
clientConfig.printStatus();
|
|
566
|
+
|
|
567
|
+
expect(loggerStub.info.calledWith(sinon.match("Cell:"))).to.be.true;
|
|
568
|
+
expect(loggerStub.info.calledWith(sinon.match("dev"))).to.be.true;
|
|
569
|
+
expect(
|
|
570
|
+
loggerStub.info.calledWith(
|
|
571
|
+
sinon.match("https://dev-admin.credibledata.com/api/v0"),
|
|
572
|
+
),
|
|
573
|
+
).to.be.true;
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
it("should name the targeted cell even when the token is invalid", () => {
|
|
577
|
+
const mockConfig = {
|
|
578
|
+
configPerEnvironment: {
|
|
579
|
+
production: {},
|
|
580
|
+
staging: {},
|
|
581
|
+
localhost: {},
|
|
582
|
+
},
|
|
583
|
+
activeEnvironment: "localhost",
|
|
584
|
+
};
|
|
585
|
+
readFileSyncStub.returns(JSON.stringify(mockConfig));
|
|
586
|
+
|
|
587
|
+
clientConfig.printStatus();
|
|
588
|
+
|
|
589
|
+
expect(loggerStub.info.calledWith(sinon.match("Cell:"))).to.be.true;
|
|
590
|
+
expect(
|
|
591
|
+
loggerStub.info.calledWith(
|
|
592
|
+
sinon.match("http://admin.ms2.localhost/api/v0"),
|
|
593
|
+
),
|
|
594
|
+
).to.be.true;
|
|
470
595
|
});
|
|
471
596
|
|
|
472
597
|
it("should print error when token is invalid", () => {
|