kubernetes-fluent-client 1.7.0 → 1.8.1

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.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Get an environment variable (Node, Deno or Bun), or throw an error if it's not set.
3
+ *
4
+ * @example
5
+ * const value = fromEnv("MY_ENV_VAR");
6
+ * console.log(value);
7
+ * // => "my-value"
8
+ *
9
+ * @example
10
+ * const value = fromEnv("MY_MISSING_ENV_VAR");
11
+ * // => Error: Environment variable MY_MISSING_ENV_VAR is not set
12
+ *
13
+ * @param name The name of the environment variable to get.
14
+ * @returns The value of the environment variable.
15
+ * @throws An error if the environment variable is not set.
16
+ */
17
+ export declare function fromEnv(name: string): string;
18
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqB5C"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.fromEnv = void 0;
6
+ /**
7
+ * Get an environment variable (Node, Deno or Bun), or throw an error if it's not set.
8
+ *
9
+ * @example
10
+ * const value = fromEnv("MY_ENV_VAR");
11
+ * console.log(value);
12
+ * // => "my-value"
13
+ *
14
+ * @example
15
+ * const value = fromEnv("MY_MISSING_ENV_VAR");
16
+ * // => Error: Environment variable MY_MISSING_ENV_VAR is not set
17
+ *
18
+ * @param name The name of the environment variable to get.
19
+ * @returns The value of the environment variable.
20
+ * @throws An error if the environment variable is not set.
21
+ */
22
+ function fromEnv(name) {
23
+ let envValue;
24
+ // Check for Node.js or Bun
25
+ if (typeof process !== "undefined" && typeof process.env !== "undefined") {
26
+ envValue = process.env[name];
27
+ }
28
+ // Check for Deno
29
+ else if (typeof Deno !== "undefined") {
30
+ envValue = Deno.env.get(name);
31
+ }
32
+ // Otherwise, throw an error
33
+ else {
34
+ throw new Error("Unknown runtime environment");
35
+ }
36
+ if (typeof envValue === "undefined") {
37
+ throw new Error(`Environment variable ${name} is not set`);
38
+ }
39
+ return envValue;
40
+ }
41
+ exports.fromEnv = fromEnv;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=helpers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.test.d.ts","sourceRoot":"","sources":["../src/helpers.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const globals_1 = require("@jest/globals");
6
+ const helpers_1 = require("./helpers");
7
+ (0, globals_1.describe)("helpers", () => {
8
+ (0, globals_1.test)("fromEnv for NodeJS", () => {
9
+ (0, globals_1.expect)(() => {
10
+ (0, helpers_1.fromEnv)("MY_MISSING_ENV_VAR");
11
+ }).toThrowError("Environment variable MY_MISSING_ENV_VAR is not set");
12
+ process.env.MY_ENV_VAR = "my-value";
13
+ (0, globals_1.expect)((0, helpers_1.fromEnv)("MY_ENV_VAR")).toEqual("my-value");
14
+ delete process.env.MY_ENV_VAR;
15
+ });
16
+ });
package/dist/index.d.ts CHANGED
@@ -8,4 +8,5 @@ export { RegisterKind, modelToGroupVersionKind } from "./kinds";
8
8
  export { GenericKind } from "./types";
9
9
  export * from "./types";
10
10
  export * as K8sClientNode from "@kubernetes/client-node";
11
+ export { fromEnv } from "./helpers";
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,oGAAoG;AACpG,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,cAAc,SAAS,CAAC;AAExB,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,oGAAoG;AACpG,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,cAAc,SAAS,CAAC;AAExB,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
28
28
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.K8sClientNode = exports.GenericKind = exports.modelToGroupVersionKind = exports.RegisterKind = exports.K8s = exports.fetchStatus = exports.fetch = exports.kind = void 0;
31
+ exports.fromEnv = exports.K8sClientNode = exports.GenericKind = exports.modelToGroupVersionKind = exports.RegisterKind = exports.K8s = exports.fetchStatus = exports.fetch = exports.kind = void 0;
32
32
  // Export kinds as a single object
33
33
  const kind = __importStar(require("./upstream"));
34
34
  exports.kind = kind;
@@ -50,3 +50,5 @@ var types_1 = require("./types");
50
50
  Object.defineProperty(exports, "GenericKind", { enumerable: true, get: function () { return types_1.GenericKind; } });
51
51
  __exportStar(require("./types"), exports);
52
52
  exports.K8sClientNode = __importStar(require("@kubernetes/client-node"));
53
+ var helpers_1 = require("./helpers");
54
+ Object.defineProperty(exports, "fromEnv", { enumerable: true, get: function () { return helpers_1.fromEnv; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubernetes-fluent-client",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "A @kubernetes/client-node fluent API wrapper that leverages K8s Server Side Apply",
5
5
  "bin": "./dist/cli.js",
6
6
  "main": "dist/index.js",
@@ -41,26 +41,29 @@
41
41
  "http-status-codes": "2.3.0",
42
42
  "node-fetch": "2.7.0",
43
43
  "quicktype-core": "23.0.76",
44
- "type-fest": "4.4.0",
44
+ "type-fest": "4.5.0",
45
45
  "yargs": "17.7.2"
46
46
  },
47
47
  "devDependencies": {
48
- "@commitlint/cli": "17.7.2",
49
- "@commitlint/config-conventional": "17.7.0",
48
+ "@commitlint/cli": "18.0.0",
49
+ "@commitlint/config-conventional": "18.0.0",
50
50
  "@jest/globals": "29.7.0",
51
- "@types/byline": "4.2.34",
52
- "@types/readable-stream": "4.0.3",
53
- "@types/yargs": "17.0.28",
54
- "@typescript-eslint/eslint-plugin": "6.7.5",
55
- "@typescript-eslint/parser": "6.7.5",
51
+ "@types/byline": "4.2.35",
52
+ "@types/readable-stream": "4.0.4",
53
+ "@types/yargs": "17.0.29",
54
+ "@typescript-eslint/eslint-plugin": "6.9.0",
55
+ "@typescript-eslint/parser": "6.9.0",
56
56
  "eslint-plugin-jsdoc": "46.8.2",
57
57
  "jest": "29.7.0",
58
- "nock": "13.3.4",
58
+ "nock": "13.3.6",
59
59
  "prettier": "3.0.3",
60
60
  "semantic-release": "22.0.5",
61
61
  "ts-jest": "29.1.1",
62
62
  "typescript": "5.2.2"
63
63
  },
64
+ "overrides": {
65
+ "browser-or-node": "github:defenseunicorns/browser-or-node#master"
66
+ },
64
67
  "release": {
65
68
  "branches": [
66
69
  "main",
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
3
+
4
+ import { describe, expect, test } from "@jest/globals";
5
+
6
+ import { fromEnv } from "./helpers";
7
+
8
+ describe("helpers", () => {
9
+ test("fromEnv for NodeJS", () => {
10
+ expect(() => {
11
+ fromEnv("MY_MISSING_ENV_VAR");
12
+ }).toThrowError("Environment variable MY_MISSING_ENV_VAR is not set");
13
+
14
+ process.env.MY_ENV_VAR = "my-value";
15
+ expect(fromEnv("MY_ENV_VAR")).toEqual("my-value");
16
+ delete process.env.MY_ENV_VAR;
17
+ });
18
+ });
package/src/helpers.ts ADDED
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
3
+
4
+ declare const Deno: {
5
+ env: {
6
+ get(name: string): string | undefined;
7
+ };
8
+ };
9
+
10
+ /**
11
+ * Get an environment variable (Node, Deno or Bun), or throw an error if it's not set.
12
+ *
13
+ * @example
14
+ * const value = fromEnv("MY_ENV_VAR");
15
+ * console.log(value);
16
+ * // => "my-value"
17
+ *
18
+ * @example
19
+ * const value = fromEnv("MY_MISSING_ENV_VAR");
20
+ * // => Error: Environment variable MY_MISSING_ENV_VAR is not set
21
+ *
22
+ * @param name The name of the environment variable to get.
23
+ * @returns The value of the environment variable.
24
+ * @throws An error if the environment variable is not set.
25
+ */
26
+ export function fromEnv(name: string): string {
27
+ let envValue: string | undefined;
28
+
29
+ // Check for Node.js or Bun
30
+ if (typeof process !== "undefined" && typeof process.env !== "undefined") {
31
+ envValue = process.env[name];
32
+ }
33
+ // Check for Deno
34
+ else if (typeof Deno !== "undefined") {
35
+ envValue = Deno.env.get(name);
36
+ }
37
+ // Otherwise, throw an error
38
+ else {
39
+ throw new Error("Unknown runtime environment");
40
+ }
41
+
42
+ if (typeof envValue === "undefined") {
43
+ throw new Error(`Environment variable ${name} is not set`);
44
+ }
45
+
46
+ return envValue;
47
+ }
package/src/index.ts CHANGED
@@ -25,3 +25,5 @@ export { GenericKind } from "./types";
25
25
  export * from "./types";
26
26
 
27
27
  export * as K8sClientNode from "@kubernetes/client-node";
28
+
29
+ export { fromEnv } from "./helpers";