@tenonhq/dovetail-servicenow 0.0.20 → 0.0.21

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,29 @@
1
+ import type { ServiceNowClient } from "./client";
2
+ import type { ServiceNowClientConfig } from "./types";
3
+ /**
4
+ * Build a ServiceNowClientConfig from a `.env`-style file WITHOUT mutating the
5
+ * global process.env.
6
+ *
7
+ * Unlike `loadEnvFile` (which calls `dotenv.config()` and is correct for a
8
+ * one-shot CLI), this reads the file into a local object via `dotenv.parse` so
9
+ * it is safe to call repeatedly inside a long-lived process — e.g. a per-call
10
+ * retarget in the MCP server, where a global dotenv mutation would race across
11
+ * concurrent reads.
12
+ *
13
+ * Instance/auth precedence within the file mirrors `createClient`'s env
14
+ * precedence (SN_* > SN_DEV_* > SN_PROD_*) so a file written for either the
15
+ * dev-style or prod-style variable names resolves the same way. The resolved
16
+ * values are returned as an explicit config object — they are never read from
17
+ * the surrounding process.env, so the file fully determines the target.
18
+ *
19
+ * Throws if the file cannot be read, or if it does not define an instance and
20
+ * a complete credential pair — failing loudly rather than silently falling
21
+ * back to whatever instance the host process happens to be pointed at.
22
+ */
23
+ export declare function resolveConfigFromEnvFile(envPath: string): ServiceNowClientConfig;
24
+ /**
25
+ * Construct a ServiceNowClient bound to the instance/credentials defined in a
26
+ * `.env`-style file, without touching the global process.env. See
27
+ * `resolveConfigFromEnvFile` for the precedence and failure rules.
28
+ */
29
+ export declare function createClientFromEnvFile(envPath: string): ServiceNowClient;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveConfigFromEnvFile = resolveConfigFromEnvFile;
7
+ exports.createClientFromEnvFile = createClientFromEnvFile;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const dotenv_1 = __importDefault(require("dotenv"));
10
+ const client_1 = require("./client");
11
+ /**
12
+ * Build a ServiceNowClientConfig from a `.env`-style file WITHOUT mutating the
13
+ * global process.env.
14
+ *
15
+ * Unlike `loadEnvFile` (which calls `dotenv.config()` and is correct for a
16
+ * one-shot CLI), this reads the file into a local object via `dotenv.parse` so
17
+ * it is safe to call repeatedly inside a long-lived process — e.g. a per-call
18
+ * retarget in the MCP server, where a global dotenv mutation would race across
19
+ * concurrent reads.
20
+ *
21
+ * Instance/auth precedence within the file mirrors `createClient`'s env
22
+ * precedence (SN_* > SN_DEV_* > SN_PROD_*) so a file written for either the
23
+ * dev-style or prod-style variable names resolves the same way. The resolved
24
+ * values are returned as an explicit config object — they are never read from
25
+ * the surrounding process.env, so the file fully determines the target.
26
+ *
27
+ * Throws if the file cannot be read, or if it does not define an instance and
28
+ * a complete credential pair — failing loudly rather than silently falling
29
+ * back to whatever instance the host process happens to be pointed at.
30
+ */
31
+ function resolveConfigFromEnvFile(envPath) {
32
+ if (typeof envPath !== "string" || envPath.length === 0) {
33
+ throw new Error("resolveConfigFromEnvFile: envPath must be a non-empty string.");
34
+ }
35
+ var raw;
36
+ try {
37
+ raw = fs_1.default.readFileSync(envPath, "utf8");
38
+ }
39
+ catch (e) {
40
+ throw new Error("Cannot read env file '" + envPath + "': " + (e && e.message ? e.message : String(e)));
41
+ }
42
+ var parsed = dotenv_1.default.parse(raw);
43
+ var instance = parsed.SN_INSTANCE || parsed.SN_DEV_INSTANCE || parsed.SN_PROD_INSTANCE || "";
44
+ var user = parsed.SN_USER || parsed.SN_DEV_USERNAME || parsed.SN_PROD_USERNAME || "";
45
+ var password = parsed.SN_PASSWORD || parsed.SN_DEV_PASSWORD || parsed.SN_PROD_PASSWORD || "";
46
+ if (!instance) {
47
+ throw new Error("env file '" + envPath + "' does not define a ServiceNow instance — " +
48
+ "set SN_INSTANCE (preferred) or SN_DEV_INSTANCE / SN_PROD_INSTANCE.");
49
+ }
50
+ if (!user || !password) {
51
+ throw new Error("env file '" + envPath + "' is missing ServiceNow credentials — " +
52
+ "set SN_USER/SN_PASSWORD (preferred) or SN_DEV_USERNAME/SN_DEV_PASSWORD (or SN_PROD_*).");
53
+ }
54
+ return { instance: instance, user: user, password: password };
55
+ }
56
+ /**
57
+ * Construct a ServiceNowClient bound to the instance/credentials defined in a
58
+ * `.env`-style file, without touching the global process.env. See
59
+ * `resolveConfigFromEnvFile` for the precedence and failure rules.
60
+ */
61
+ function createClientFromEnvFile(envPath) {
62
+ return (0, client_1.createClient)(resolveConfigFromEnvFile(envPath));
63
+ }
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * REST API so every change lands in the target update set and scope.
6
6
  */
7
7
  export { createClient } from "./client";
8
+ export { createClientFromEnvFile, resolveConfigFromEnvFile } from "./createClientFromEnvFile";
8
9
  export type { ServiceNowClient, TableQueryOptions, TableSchema, TableSchemaField } from "./client";
9
10
  export { addChoicesToField } from "./choices";
10
11
  export { formatAddChoicesResult } from "./formatter";
package/dist/index.js CHANGED
@@ -6,9 +6,12 @@
6
6
  * REST API so every change lands in the target update set and scope.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.DEFAULT_SAVE_ACTION = exports.DEFAULT_SUPER_CLASS = exports.TYPE_MAP = exports.defaultAccessFlags = exports.applyTableSaveOverlay = exports.resolveType = exports.normalizeColumns = exports.buildColumnXml = exports.projectTableGraph = exports.createTable = exports.WriteOrderError = exports.executeWritePlan = exports.topoSort = exports.generateSysId = exports.DEFAULT_RUN_FLOW_PATH = exports.testFlow = exports.editFlow = exports.buildPublishModel = exports.createFlow = exports.copyFlow = exports.publishFlow = exports.readActionType = exports.readFlow = exports.editActionType = exports.publishActionType = exports.triggerPublication = exports.cloneActionType = exports.cloneSubflow = exports.verifyArtifact = exports.listTemplates = exports.sincPlugin = exports.formatCreateViewResult = exports.formatLayoutResult = exports.setRelatedLists = exports.setFormLayout = exports.setListLayout = exports.createView = exports.formatAddChoicesResult = exports.addChoicesToField = exports.createClient = void 0;
9
+ exports.DEFAULT_SAVE_ACTION = exports.DEFAULT_SUPER_CLASS = exports.TYPE_MAP = exports.defaultAccessFlags = exports.applyTableSaveOverlay = exports.resolveType = exports.normalizeColumns = exports.buildColumnXml = exports.projectTableGraph = exports.createTable = exports.WriteOrderError = exports.executeWritePlan = exports.topoSort = exports.generateSysId = exports.DEFAULT_RUN_FLOW_PATH = exports.testFlow = exports.editFlow = exports.buildPublishModel = exports.createFlow = exports.copyFlow = exports.publishFlow = exports.readActionType = exports.readFlow = exports.editActionType = exports.publishActionType = exports.triggerPublication = exports.cloneActionType = exports.cloneSubflow = exports.verifyArtifact = exports.listTemplates = exports.sincPlugin = exports.formatCreateViewResult = exports.formatLayoutResult = exports.setRelatedLists = exports.setFormLayout = exports.setListLayout = exports.createView = exports.formatAddChoicesResult = exports.addChoicesToField = exports.resolveConfigFromEnvFile = exports.createClientFromEnvFile = exports.createClient = void 0;
10
10
  var client_1 = require("./client");
11
11
  Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
12
+ var createClientFromEnvFile_1 = require("./createClientFromEnvFile");
13
+ Object.defineProperty(exports, "createClientFromEnvFile", { enumerable: true, get: function () { return createClientFromEnvFile_1.createClientFromEnvFile; } });
14
+ Object.defineProperty(exports, "resolveConfigFromEnvFile", { enumerable: true, get: function () { return createClientFromEnvFile_1.resolveConfigFromEnvFile; } });
12
15
  var choices_1 = require("./choices");
13
16
  Object.defineProperty(exports, "addChoicesToField", { enumerable: true, get: function () { return choices_1.addChoicesToField; } });
14
17
  var formatter_1 = require("./formatter");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/dovetail-servicenow",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },