@credibledata/cred-cli 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/.prettierignore +2 -1
  2. package/README.md +0 -2
  3. package/bun.lock +182 -283
  4. package/dist/client/api.js +796 -111
  5. package/dist/client/api.js.map +1 -1
  6. package/dist/clientconfiguration.js +55 -13
  7. package/dist/clientconfiguration.js.map +1 -1
  8. package/dist/clientconfiguration.spec.js +305 -16
  9. package/dist/clientconfiguration.spec.js.map +1 -1
  10. package/dist/commands/add.js +6 -3
  11. package/dist/commands/add.js.map +1 -1
  12. package/dist/commands/connection/createconnections.js +18 -3
  13. package/dist/commands/connection/createconnections.js.map +1 -1
  14. package/dist/commands/connection/createconnections.spec.js +219 -0
  15. package/dist/commands/connection/createconnections.spec.js.map +1 -0
  16. package/dist/commands/connection/deleteconnection.spec.js +130 -0
  17. package/dist/commands/connection/deleteconnection.spec.js.map +1 -0
  18. package/dist/commands/connection/listconnections.js +9 -3
  19. package/dist/commands/connection/listconnections.js.map +1 -1
  20. package/dist/commands/connection/listconnections.spec.js +117 -0
  21. package/dist/commands/connection/listconnections.spec.js.map +1 -0
  22. package/dist/commands/group/addmember.js +2 -0
  23. package/dist/commands/group/addmember.js.map +1 -1
  24. package/dist/commands/group/addmember.spec.js +148 -0
  25. package/dist/commands/group/addmember.spec.js.map +1 -0
  26. package/dist/commands/group/creategroup.spec.js +122 -0
  27. package/dist/commands/group/creategroup.spec.js.map +1 -0
  28. package/dist/commands/group/deletegroup.spec.js +104 -0
  29. package/dist/commands/group/deletegroup.spec.js.map +1 -0
  30. package/dist/commands/group/getgroup.spec.js +111 -0
  31. package/dist/commands/group/getgroup.spec.js.map +1 -0
  32. package/dist/commands/group/listgroups.spec.js +118 -0
  33. package/dist/commands/group/listgroups.spec.js.map +1 -0
  34. package/dist/commands/group/removemember.js +1 -0
  35. package/dist/commands/group/removemember.js.map +1 -1
  36. package/dist/commands/group/removemember.spec.js +138 -0
  37. package/dist/commands/group/removemember.spec.js.map +1 -0
  38. package/dist/commands/groupaccesstoken/createToken.js +6 -2
  39. package/dist/commands/groupaccesstoken/createToken.js.map +1 -1
  40. package/dist/commands/groupaccesstoken/createToken.spec.js +127 -0
  41. package/dist/commands/groupaccesstoken/createToken.spec.js.map +1 -0
  42. package/dist/commands/groupaccesstoken/deleteToken.js.map +1 -1
  43. package/dist/commands/groupaccesstoken/deleteToken.spec.js +103 -0
  44. package/dist/commands/groupaccesstoken/deleteToken.spec.js.map +1 -0
  45. package/dist/commands/groupaccesstoken/groupContainer.js.map +1 -1
  46. package/dist/commands/groupaccesstoken/listTokens.js.map +1 -1
  47. package/dist/commands/groupaccesstoken/listTokens.spec.js +115 -0
  48. package/dist/commands/groupaccesstoken/listTokens.spec.js.map +1 -0
  49. package/dist/commands/list.js +10 -3
  50. package/dist/commands/list.js.map +1 -1
  51. package/dist/commands/misc/login.js +146 -22
  52. package/dist/commands/misc/login.js.map +1 -1
  53. package/dist/commands/misc/login.spec.js +111 -6
  54. package/dist/commands/misc/login.spec.js.map +1 -1
  55. package/dist/commands/misc/logout.spec.js +30 -0
  56. package/dist/commands/misc/logout.spec.js.map +1 -0
  57. package/dist/commands/misc/loopbackOAuth.js +110 -0
  58. package/dist/commands/misc/loopbackOAuth.js.map +1 -0
  59. package/dist/commands/misc/set-access-token.js.map +1 -1
  60. package/dist/commands/misc/set-access-token.spec.js +65 -0
  61. package/dist/commands/misc/set-access-token.spec.js.map +1 -0
  62. package/dist/commands/package/deletepackage.spec.js +136 -0
  63. package/dist/commands/package/deletepackage.spec.js.map +1 -0
  64. package/dist/commands/package/listpackages.js +10 -5
  65. package/dist/commands/package/listpackages.js.map +1 -1
  66. package/dist/commands/package/listpackages.spec.js +129 -0
  67. package/dist/commands/package/listpackages.spec.js.map +1 -0
  68. package/dist/commands/package/publish.js +23 -0
  69. package/dist/commands/package/publish.js.map +1 -1
  70. package/dist/commands/package/publish.spec.js +511 -0
  71. package/dist/commands/package/publish.spec.js.map +1 -0
  72. package/dist/commands/package/updatepackage.spec.js +50 -0
  73. package/dist/commands/package/updatepackage.spec.js.map +1 -1
  74. package/dist/commands/project/createproject.js +11 -1
  75. package/dist/commands/project/createproject.js.map +1 -1
  76. package/dist/commands/project/createproject.spec.js +154 -0
  77. package/dist/commands/project/createproject.spec.js.map +1 -0
  78. package/dist/commands/project/deleteproject.spec.js +106 -0
  79. package/dist/commands/project/deleteproject.spec.js.map +1 -0
  80. package/dist/commands/project/getproject.spec.js +99 -0
  81. package/dist/commands/project/getproject.spec.js.map +1 -0
  82. package/dist/commands/project/listprojects.js +13 -7
  83. package/dist/commands/project/listprojects.js.map +1 -1
  84. package/dist/commands/project/listprojects.spec.js +111 -0
  85. package/dist/commands/project/listprojects.spec.js.map +1 -0
  86. package/dist/commands/project/setproject.spec.js +58 -0
  87. package/dist/commands/project/setproject.spec.js.map +1 -0
  88. package/dist/commands/project/updateproject.js +68 -0
  89. package/dist/commands/project/updateproject.js.map +1 -0
  90. package/dist/commands/project/updateproject.spec.js +129 -0
  91. package/dist/commands/project/updateproject.spec.js.map +1 -0
  92. package/dist/commands/rm.js.map +1 -1
  93. package/dist/commands/update.js +13 -0
  94. package/dist/commands/update.js.map +1 -1
  95. package/dist/commands/version/listversions.spec.js +121 -0
  96. package/dist/commands/version/listversions.spec.js.map +1 -0
  97. package/dist/common/UserGroupId.spec.js +92 -0
  98. package/dist/common/UserGroupId.spec.js.map +1 -0
  99. package/dist/constants.js +49 -13
  100. package/dist/constants.js.map +1 -1
  101. package/dist/index.js +40 -18
  102. package/dist/index.js.map +1 -1
  103. package/dist/logger.spec.js +125 -0
  104. package/dist/logger.spec.js.map +1 -0
  105. package/dist/polyfills/file.polyfill.js.map +1 -1
  106. package/dist/utils.js +59 -0
  107. package/dist/utils.js.map +1 -1
  108. package/dist/utils.spec.js +158 -0
  109. package/dist/utils.spec.js.map +1 -0
  110. package/docker/Dockerfile.ci +11 -3
  111. package/eslint.config.mjs +45 -0
  112. package/generate-client.sh +3 -0
  113. package/package.json +24 -16
  114. package/src/client/.openapi-generator/FILES +1 -0
  115. package/src/client/api.ts +1347 -161
  116. package/src/clientconfiguration.spec.ts +394 -20
  117. package/src/clientconfiguration.ts +74 -15
  118. package/src/commands/add.ts +15 -6
  119. package/src/commands/connection/createconnections.spec.ts +403 -0
  120. package/src/commands/connection/createconnections.ts +30 -5
  121. package/src/commands/connection/deleteconnection.spec.ts +189 -0
  122. package/src/commands/connection/listconnections.spec.ts +132 -0
  123. package/src/commands/connection/listconnections.ts +22 -3
  124. package/src/commands/group/addmember.spec.ts +257 -0
  125. package/src/commands/group/addmember.ts +2 -0
  126. package/src/commands/group/creategroup.spec.ts +146 -0
  127. package/src/commands/group/deletegroup.spec.ts +120 -0
  128. package/src/commands/group/getgroup.spec.ts +129 -0
  129. package/src/commands/group/listgroups.spec.ts +137 -0
  130. package/src/commands/group/removemember.spec.ts +224 -0
  131. package/src/commands/group/removemember.ts +1 -0
  132. package/src/commands/groupaccesstoken/createToken.spec.ts +211 -0
  133. package/src/commands/groupaccesstoken/createToken.ts +55 -51
  134. package/src/commands/groupaccesstoken/deleteToken.spec.ts +147 -0
  135. package/src/commands/groupaccesstoken/deleteToken.ts +16 -11
  136. package/src/commands/groupaccesstoken/groupContainer.ts +51 -51
  137. package/src/commands/groupaccesstoken/listTokens.spec.ts +147 -0
  138. package/src/commands/groupaccesstoken/listTokens.ts +16 -11
  139. package/src/commands/list.ts +50 -9
  140. package/src/commands/misc/login.spec.ts +91 -6
  141. package/src/commands/misc/login.ts +208 -25
  142. package/src/commands/misc/logout.spec.ts +32 -0
  143. package/src/commands/misc/loopbackOAuth.ts +127 -0
  144. package/src/commands/misc/set-access-token.spec.ts +95 -0
  145. package/src/commands/misc/set-access-token.ts +16 -16
  146. package/src/commands/package/deletepackage.spec.ts +164 -0
  147. package/src/commands/package/listpackages.spec.ts +147 -0
  148. package/src/commands/package/listpackages.ts +28 -5
  149. package/src/commands/package/publish.spec.ts +597 -0
  150. package/src/commands/package/publish.ts +32 -0
  151. package/src/commands/package/updatepackage.spec.ts +98 -0
  152. package/src/commands/project/createproject.spec.ts +247 -0
  153. package/src/commands/project/createproject.ts +12 -1
  154. package/src/commands/project/deleteproject.spec.ts +123 -0
  155. package/src/commands/project/getproject.spec.ts +109 -0
  156. package/src/commands/project/listprojects.spec.ts +121 -0
  157. package/src/commands/project/listprojects.ts +33 -7
  158. package/src/commands/project/setproject.spec.ts +63 -0
  159. package/src/commands/project/updateproject.spec.ts +217 -0
  160. package/src/commands/project/updateproject.ts +82 -0
  161. package/src/commands/rm.ts +1 -6
  162. package/src/commands/update.ts +24 -1
  163. package/src/commands/version/listversions.spec.ts +138 -0
  164. package/src/common/UserGroupId.spec.ts +117 -0
  165. package/src/constants.ts +59 -13
  166. package/src/index.ts +46 -20
  167. package/src/logger.spec.ts +158 -0
  168. package/src/polyfills/file.polyfill.ts +1 -0
  169. package/src/utils.spec.ts +135 -0
  170. package/src/utils.ts +81 -0
  171. package/tsconfig.json +15 -18
  172. package/.eslintrc +0 -33
@@ -0,0 +1,135 @@
1
+ import axios from "axios";
2
+ import { expect } from "chai";
3
+ import inquirer from "inquirer";
4
+ import sinon from "sinon";
5
+ import * as loggerModule from "./logger";
6
+ import { getConfirmation, prettifyJson, printOutError, sleep } from "./utils";
7
+
8
+ describe("utils", () => {
9
+ let sandbox: sinon.SinonSandbox;
10
+ let loggerStub: sinon.SinonStubbedInstance<typeof loggerModule.logger>;
11
+ let logAxiosErrorStub: sinon.SinonStub;
12
+
13
+ beforeEach(() => {
14
+ sandbox = sinon.createSandbox();
15
+ loggerStub = sandbox.stub(loggerModule.logger);
16
+ logAxiosErrorStub = sandbox.stub(loggerModule, "logAxiosError");
17
+ });
18
+
19
+ afterEach(() => {
20
+ sandbox.restore();
21
+ });
22
+
23
+ describe("sleep", () => {
24
+ it("should wait for the specified time", async function () {
25
+ this.timeout(100);
26
+ const start = Date.now();
27
+ await sleep(50);
28
+ const elapsed = Date.now() - start;
29
+ expect(elapsed).to.be.at.least(45);
30
+ });
31
+ });
32
+
33
+ describe("prettifyJson", () => {
34
+ it("should format JSON with 2-space indentation", () => {
35
+ const obj = { name: "test", value: 123 };
36
+ const result = prettifyJson(obj);
37
+ expect(result).to.equal('{\n "name": "test",\n "value": 123\n}');
38
+ });
39
+
40
+ it("should handle empty objects", () => {
41
+ const result = prettifyJson({});
42
+ expect(result).to.equal("{}");
43
+ });
44
+
45
+ it("should handle nested objects", () => {
46
+ const obj = { nested: { key: "value" } };
47
+ const result = prettifyJson(obj);
48
+ expect(result).to.include("nested");
49
+ expect(result).to.include("key");
50
+ expect(result).to.include("value");
51
+ });
52
+ });
53
+
54
+ describe("printOutError", () => {
55
+ it("should handle axios errors", () => {
56
+ const axiosError = {
57
+ isAxiosError: true,
58
+ response: {
59
+ status: 404,
60
+ data: { message: "Not found" },
61
+ },
62
+ config: {},
63
+ name: "AxiosError",
64
+ message: "Request failed",
65
+ };
66
+ sandbox.stub(axios, "isAxiosError").returns(true);
67
+
68
+ printOutError(axiosError as any, false);
69
+
70
+ expect(logAxiosErrorStub.calledOnce).to.be.true;
71
+ expect(logAxiosErrorStub.firstCall.args[0]).to.equal(axiosError);
72
+ expect(logAxiosErrorStub.firstCall.args[1]).to.equal(false);
73
+ });
74
+
75
+ it("should handle non-axios errors", () => {
76
+ const error = new Error("Generic error");
77
+ sandbox.stub(axios, "isAxiosError").returns(false);
78
+
79
+ printOutError(error, false);
80
+
81
+ expect(loggerStub.error.calledOnce).to.be.true;
82
+ expect(loggerStub.error.calledWith(sinon.match("Unexpected error"))).to
83
+ .be.true;
84
+ // Check that error was passed as second argument (Winston accepts Error objects)
85
+ const errorCall = loggerStub.error.getCall(0);
86
+ expect(errorCall.args.length).to.be.at.least(2);
87
+ expect((errorCall.args as any)[1]).to.equal(error);
88
+ });
89
+
90
+ it("should log debug info when debug is true", () => {
91
+ const error = new Error("Test error");
92
+ sandbox.stub(axios, "isAxiosError").returns(false);
93
+
94
+ printOutError(error, true);
95
+
96
+ expect(loggerStub.debug.calledWith(error)).to.be.true;
97
+ });
98
+
99
+ it("should not log debug info when debug is false", () => {
100
+ const error = new Error("Test error");
101
+ sandbox.stub(axios, "isAxiosError").returns(false);
102
+
103
+ printOutError(error, false);
104
+
105
+ expect(loggerStub.debug.called).to.be.false;
106
+ });
107
+ });
108
+
109
+ describe("getConfirmation", () => {
110
+ it("should return true when user confirms", async () => {
111
+ const promptStub = sandbox
112
+ .stub(inquirer, "prompt")
113
+ .resolves({ confirm: true });
114
+
115
+ const result = await getConfirmation("Are you sure?");
116
+
117
+ expect(result).to.be.true;
118
+ expect(promptStub.calledOnce).to.be.true;
119
+ expect(promptStub.firstCall.args[0][0].message).to.equal(
120
+ "Are you sure?",
121
+ );
122
+ });
123
+
124
+ it("should return false when user denies", async () => {
125
+ const promptStub = sandbox
126
+ .stub(inquirer, "prompt")
127
+ .resolves({ confirm: false });
128
+
129
+ const result = await getConfirmation("Are you sure?");
130
+
131
+ expect(result).to.be.false;
132
+ expect(promptStub.calledOnce).to.be.true;
133
+ });
134
+ });
135
+ });
package/src/utils.ts CHANGED
@@ -32,3 +32,84 @@ export async function getConfirmation(message: string): Promise<boolean> {
32
32
  ]);
33
33
  return answer.confirm;
34
34
  }
35
+
36
+ export const DEFAULT_PAGE_SIZE = -1; // -1 means return all records
37
+ export const DEFAULT_PAGE = 1;
38
+ export const MAX_PAGE_SIZE = 500;
39
+
40
+ export interface PaginationOptions {
41
+ page?: number;
42
+ pageSize?: number;
43
+ }
44
+
45
+ export function parsePaginationParams(
46
+ page?: string | number,
47
+ pageSize?: string | number,
48
+ ): { limit: number; offset: number } {
49
+ // If no page AND no pageSize specified, return all records
50
+ if (page === undefined && pageSize === undefined) {
51
+ logger.info("--page-size not passed, returning all records");
52
+ return { limit: -1, offset: 0 };
53
+ }
54
+
55
+ // Parse pageSize
56
+ const parsedPageSize =
57
+ typeof pageSize === "string" ? parseInt(pageSize, 10) : pageSize;
58
+
59
+ // If pageSize is explicitly -1, return all records
60
+ if (parsedPageSize === -1) {
61
+ return { limit: -1, offset: 0 };
62
+ }
63
+
64
+ // If page OR pageSize is provided, use pagination
65
+ // Default pageSize to 100 when page is provided but pageSize is not
66
+ const effectivePageSize =
67
+ parsedPageSize !== undefined && !isNaN(parsedPageSize)
68
+ ? parsedPageSize
69
+ : page !== undefined
70
+ ? 100
71
+ : DEFAULT_PAGE_SIZE;
72
+
73
+ // If we still have -1 (shouldn't happen, but safety check), return all
74
+ if (effectivePageSize === -1) {
75
+ return { limit: -1, offset: 0 };
76
+ }
77
+
78
+ // Use pagination logic
79
+ const parsedPage =
80
+ typeof page === "string" ? parseInt(page, 10) : page || DEFAULT_PAGE;
81
+ const validPage = Math.max(1, isNaN(parsedPage) ? DEFAULT_PAGE : parsedPage);
82
+
83
+ const validPageSize = Math.min(
84
+ Math.max(1, effectivePageSize),
85
+ MAX_PAGE_SIZE,
86
+ );
87
+
88
+ const offset = (validPage - 1) * validPageSize;
89
+
90
+ return {
91
+ limit: validPageSize,
92
+ offset: offset,
93
+ };
94
+ }
95
+
96
+ export function extractTotalCount(headers: unknown): number | undefined {
97
+ if (!headers || typeof headers !== "object") {
98
+ return undefined;
99
+ }
100
+ const h = headers as Record<string, unknown>;
101
+ const candidates = [h["x-total-count"], h["Total-Count"], h["total-count"]];
102
+ for (const totalCountHeader of candidates) {
103
+ if (totalCountHeader == null) {
104
+ continue;
105
+ }
106
+ const raw = Array.isArray(totalCountHeader)
107
+ ? totalCountHeader[0]
108
+ : totalCountHeader;
109
+ const count = parseInt(String(raw), 10);
110
+ if (!isNaN(count)) {
111
+ return count;
112
+ }
113
+ }
114
+ return undefined;
115
+ }
package/tsconfig.json CHANGED
@@ -1,20 +1,17 @@
1
1
  {
2
- "compilerOptions": {
3
- "outDir": "dist",
4
- "rootDir": "src",
5
- "strict": false,
6
- "target": "es6",
7
- "module": "commonjs",
8
- "sourceMap": true,
9
- "esModuleInterop": true,
10
- "moduleResolution": "node",
11
- "resolveJsonModule": true
12
- },
13
- "include": [
14
- "src/**/*"
15
- ],
16
- "exclude": [
17
- "node_modules",
18
- "dist"
19
- ]
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "rootDir": "src",
5
+ "strict": false,
6
+ "target": "es6",
7
+ "module": "commonjs",
8
+ "sourceMap": true,
9
+ "esModuleInterop": true,
10
+ "moduleResolution": "node",
11
+ "resolveJsonModule": true,
12
+ "skipLibCheck": true,
13
+ "typeRoots": ["./node_modules/@types"]
14
+ },
15
+ "include": ["src/**/*"],
16
+ "exclude": ["node_modules", "dist"]
20
17
  }
package/.eslintrc DELETED
@@ -1,33 +0,0 @@
1
- {
2
- // Specify the environments where the code will run
3
- "env": {
4
- "jest": true, // Enable Jest for testing
5
- "browser": true, // Enable browser environment
6
- },
7
-
8
- // Stop ESLint from searching for configuration in parent folders
9
- "root": true,
10
-
11
- // Specify the parser for TypeScript (using @typescript-eslint/parser)
12
- "parser": "@typescript-eslint/parser", // Leverages TS ESTree to lint TypeScript
13
-
14
- // Add additional rules and configuration options
15
- "plugins": ["@typescript-eslint"],
16
-
17
- // Extend various ESLint configurations and plugins
18
- "extends": [
19
- "eslint:recommended", // ESLint recommended rules
20
- "plugin:react/recommended", // React recommended rules
21
- "plugin:@typescript-eslint/recommended", // TypeScript recommended rules
22
- "plugin:@typescript-eslint/eslint-recommended", // ESLint overrides for TypeScript
23
- "prettier", // Prettier rules
24
- "plugin:prettier/recommended", // Prettier plugin integration
25
- "plugin:react-hooks/recommended", // Recommended rules for React hooks
26
- "plugin:storybook/recommended", // Recommended rules for Storybook
27
- ],
28
- "rules": {
29
- "react/react-in-jsx-scope": "off",
30
- "@typescript-eslint/no-unused-expressions": "off",
31
- "no-constant-condition": "off",
32
- },
33
- }