@envoy/envoy-integrations-sdk 2.4.3 → 2.5.0
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/base/EnvoyAPI.d.ts +34 -1
- package/dist/base/EnvoyAPI.d.ts.map +1 -1
- package/dist/base/EnvoyAPI.js +45 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/EnvoyOptionsRouteParams.d.ts +4 -0
- package/dist/internal/EnvoyOptionsRouteParams.d.ts.map +1 -1
- package/dist/util/userAgent.d.ts +50 -0
- package/dist/util/userAgent.d.ts.map +1 -0
- package/dist/util/userAgent.js +132 -0
- package/package.json +1 -1
- package/src/base/EnvoyAPI.ts +62 -1
- package/src/index.ts +2 -0
- package/src/internal/EnvoyOptionsRouteParams.ts +4 -0
- package/src/util/userAgent.ts +144 -0
package/dist/base/EnvoyAPI.d.ts
CHANGED
|
@@ -3,6 +3,21 @@ import JSONAPIData from '../util/json-api/JSONAPIData';
|
|
|
3
3
|
interface EnvoyWebDataLoaderKey extends JSONAPIData {
|
|
4
4
|
include?: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Options for configuring EnvoyAPI client
|
|
8
|
+
*/
|
|
9
|
+
export interface EnvoyAPIOptions {
|
|
10
|
+
/** Access token for authentication */
|
|
11
|
+
accessToken: string;
|
|
12
|
+
/**
|
|
13
|
+
* Custom application identifier appended to User-Agent header.
|
|
14
|
+
* Format: "AppName/Version"
|
|
15
|
+
* Example: "MyCompanyApp/1.0.0"
|
|
16
|
+
*
|
|
17
|
+
* This identifier helps track API usage by application and aids in debugging.
|
|
18
|
+
*/
|
|
19
|
+
userAgent?: string;
|
|
20
|
+
}
|
|
6
21
|
/**
|
|
7
22
|
* Make typed API calls to Envoy.
|
|
8
23
|
* Uses a data loader to leverage JSONAPI's "include" functionality.
|
|
@@ -14,6 +29,7 @@ interface EnvoyWebDataLoaderKey extends JSONAPIData {
|
|
|
14
29
|
export default class EnvoyAPI {
|
|
15
30
|
/**
|
|
16
31
|
* HTTP Client with Envoy's defaults.
|
|
32
|
+
* User-Agent headers are set in the constructor after client instantiation.
|
|
17
33
|
*/
|
|
18
34
|
readonly axios: import("axios").AxiosInstance;
|
|
19
35
|
/**
|
|
@@ -22,7 +38,24 @@ export default class EnvoyAPI {
|
|
|
22
38
|
* unless they exist in cache (which they usually will).
|
|
23
39
|
*/
|
|
24
40
|
protected readonly dataLoader: DataLoader<EnvoyWebDataLoaderKey, any, string>;
|
|
25
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Create an EnvoyAPI client instance
|
|
43
|
+
*
|
|
44
|
+
* @param options - Either an access token string or an EnvoyAPIOptions object
|
|
45
|
+
* with accessToken and optional userAgent
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Simple usage with access token only
|
|
49
|
+
* const client = new EnvoyAPI('access-token-here');
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Usage with custom User-Agent for tracking and debugging
|
|
53
|
+
* const client = new EnvoyAPI({
|
|
54
|
+
* accessToken: 'access-token-here',
|
|
55
|
+
* userAgent: 'MyApp/1.0.0'
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
58
|
+
constructor(options: EnvoyAPIOptions | string);
|
|
26
59
|
}
|
|
27
60
|
export {};
|
|
28
61
|
//# sourceMappingURL=EnvoyAPI.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvoyAPI.d.ts","sourceRoot":"","sources":["../../src/base/EnvoyAPI.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,WAAW,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"EnvoyAPI.d.ts","sourceRoot":"","sources":["../../src/base/EnvoyAPI.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,WAAW,MAAM,8BAA8B,CAAC;AAMvD,UAAU,qBAAsB,SAAQ,WAAW;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AASD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B;;;OAGG;IACH,QAAQ,CAAC,KAAK,gCAWX;IAEH;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,iDAW3B;IAEF;;;;;;;;;;;;;;;;OAgBG;gBACS,OAAO,EAAE,eAAe,GAAG,MAAM;CAqD9C"}
|
package/dist/base/EnvoyAPI.js
CHANGED
|
@@ -44,6 +44,7 @@ var dataloader_1 = __importDefault(require("dataloader"));
|
|
|
44
44
|
var constants_1 = require("../constants");
|
|
45
45
|
var axiosConstructor_1 = require("../util/axiosConstructor");
|
|
46
46
|
var errorHandling_1 = require("../util/errorHandling");
|
|
47
|
+
var userAgent_1 = require("../util/userAgent");
|
|
47
48
|
/**
|
|
48
49
|
* Sometimes envoy-web will give us back some relationship data
|
|
49
50
|
* with the "type" set to the relationships name instead of the actual model's name.
|
|
@@ -59,10 +60,28 @@ var TYPE_ALIASES = new Map([['employee-screening-flows', 'flows']]);
|
|
|
59
60
|
* @category Base
|
|
60
61
|
*/
|
|
61
62
|
var EnvoyAPI = /** @class */ (function () {
|
|
62
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Create an EnvoyAPI client instance
|
|
65
|
+
*
|
|
66
|
+
* @param options - Either an access token string or an EnvoyAPIOptions object
|
|
67
|
+
* with accessToken and optional userAgent
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Simple usage with access token only
|
|
71
|
+
* const client = new EnvoyAPI('access-token-here');
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* // Usage with custom User-Agent for tracking and debugging
|
|
75
|
+
* const client = new EnvoyAPI({
|
|
76
|
+
* accessToken: 'access-token-here',
|
|
77
|
+
* userAgent: 'MyApp/1.0.0'
|
|
78
|
+
* });
|
|
79
|
+
*/
|
|
80
|
+
function EnvoyAPI(options) {
|
|
63
81
|
var _this = this;
|
|
64
82
|
/**
|
|
65
83
|
* HTTP Client with Envoy's defaults.
|
|
84
|
+
* User-Agent headers are set in the constructor after client instantiation.
|
|
66
85
|
*/
|
|
67
86
|
this.axios = axiosConstructor_1.createAxiosClient({
|
|
68
87
|
baseURL: constants_1.envoyBaseURL,
|
|
@@ -100,7 +119,32 @@ var EnvoyAPI = /** @class */ (function () {
|
|
|
100
119
|
}, {
|
|
101
120
|
cacheKeyFn: function (key) { return key.type + "_" + key.id; },
|
|
102
121
|
});
|
|
122
|
+
// Support both string and options object formats
|
|
123
|
+
var _a = typeof options === 'string'
|
|
124
|
+
? { accessToken: options, userAgent: undefined }
|
|
125
|
+
: options, accessToken = _a.accessToken, userAgent = _a.userAgent;
|
|
126
|
+
// Set authorization header (critical - must succeed)
|
|
103
127
|
this.axios.defaults.headers.authorization = "Bearer " + accessToken;
|
|
128
|
+
// Set User-Agent headers with absolute guarantee that failures won't break SDK
|
|
129
|
+
// GUARANTEE: This block will NEVER throw an exception, no matter what happens
|
|
130
|
+
// User-Agent headers are telemetry/debugging aids, not critical for SDK functionality
|
|
131
|
+
try {
|
|
132
|
+
// Primary attempt: Use full header generation functions
|
|
133
|
+
this.axios.defaults.headers['User-Agent'] = userAgent_1.buildUserAgent(userAgent);
|
|
134
|
+
this.axios.defaults.headers['X-Envoy-Client-Info'] = userAgent_1.buildClientInfoHeader(userAgent);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
// Secondary fallback: Set minimal valid headers
|
|
138
|
+
try {
|
|
139
|
+
this.axios.defaults.headers['User-Agent'] = 'envoy-integrations-sdk/unknown';
|
|
140
|
+
this.axios.defaults.headers['X-Envoy-Client-Info'] = '{"sdk":"envoy-integrations-sdk"}';
|
|
141
|
+
}
|
|
142
|
+
catch (fallbackError) {
|
|
143
|
+
// Tertiary fallback: Even setting minimal headers failed
|
|
144
|
+
// Continue without User-Agent headers - SDK remains fully functional
|
|
145
|
+
// This catch ensures absolute guarantee that SDK initialization succeeds
|
|
146
|
+
}
|
|
147
|
+
}
|
|
104
148
|
/**
|
|
105
149
|
* Saves every model that was "include"ed in the response,
|
|
106
150
|
* which saves us the trouble of fetching related data.
|
package/dist/index.d.ts
CHANGED
|
@@ -51,5 +51,6 @@ export * from './sdk/middleware';
|
|
|
51
51
|
export * from './util/EnvoySignatureVerifier';
|
|
52
52
|
export * from './util/axiosConstructor';
|
|
53
53
|
export * from './util/errorHandling';
|
|
54
|
+
export type { EnvoyAPIOptions } from './base/EnvoyAPI';
|
|
54
55
|
export { EntryPayload, InvitePayload, EnvoyJWT, EnvoyMeta, EnvoyPluginJob, EnvoyPluginJobMock, EnvoyPluginSDK, EnvoyPluginStorage, EnvoyPluginStoragePipeline, EnvoyPluginStoragePipelineMock, EnvoyRequest, EnvoyResponse, EnvoySignatureVerifier, EnvoyStorageItem, EnvoyPluginAPI, EnvoyUserAPI, EnvoyValidationRouteResponseBody, JSONAPIData, JSONAPIResponse, HttpStatus, entryEventBodyFactory, eventBodyFactory, inviteEventBodyFactory, routeBodyFactory, };
|
|
55
56
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,0BAA0B,MAAM,mCAAmC,CAAC;AAE3E,OAAO,qBAAqB,MAAM,mCAAmC,CAAC;AACtE,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,sBAAsB,MAAM,oCAAoC,CAAC;AACxE,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAE5D,OAAO,UAAU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AAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,0BAA0B,EAC1B,8BAA8B,EAC9B,YAAY,EACZ,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,gCAAgC,EAChC,WAAW,EACX,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,GACjB,CAAC"}
|
|
@@ -2,6 +2,10 @@ declare type EnvoyOptionsRouteParams = {
|
|
|
2
2
|
search?: string;
|
|
3
3
|
page?: number;
|
|
4
4
|
cursor?: string;
|
|
5
|
+
zone_id?: string;
|
|
6
|
+
location_id?: string;
|
|
7
|
+
/** ID of selected option when this is a mapped field. */
|
|
8
|
+
parent_resource_id?: string;
|
|
5
9
|
};
|
|
6
10
|
export default EnvoyOptionsRouteParams;
|
|
7
11
|
//# sourceMappingURL=EnvoyOptionsRouteParams.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvoyOptionsRouteParams.d.ts","sourceRoot":"","sources":["../../src/internal/EnvoyOptionsRouteParams.ts"],"names":[],"mappings":"AAAA,aAAK,uBAAuB,GAAG;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"EnvoyOptionsRouteParams.d.ts","sourceRoot":"","sources":["../../src/internal/EnvoyOptionsRouteParams.ts"],"names":[],"mappings":"AAAA,aAAK,uBAAuB,GAAG;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client information for detailed telemetry
|
|
3
|
+
*/
|
|
4
|
+
export interface ClientInfo {
|
|
5
|
+
/** SDK name */
|
|
6
|
+
sdk: string;
|
|
7
|
+
/** SDK version */
|
|
8
|
+
version: string;
|
|
9
|
+
/** Runtime (e.g., 'node') */
|
|
10
|
+
runtime: string;
|
|
11
|
+
/** Runtime version (e.g., '18.0.0') */
|
|
12
|
+
runtimeVersion: string;
|
|
13
|
+
/** Operating system platform */
|
|
14
|
+
platform: string;
|
|
15
|
+
/** Optional custom application identifier (e.g., 'MyApp/1.0.0') */
|
|
16
|
+
application?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build standard User-Agent header value
|
|
20
|
+
* Format: envoy-integrations-sdk/2.4.4 node/18.0.0
|
|
21
|
+
* With custom app: envoy-integrations-sdk/2.4.4 node/18.0.0 MyApp/1.0.0
|
|
22
|
+
*
|
|
23
|
+
* This function is designed to never throw exceptions. If any error occurs,
|
|
24
|
+
* it returns a safe fallback value to ensure SDK initialization succeeds.
|
|
25
|
+
*
|
|
26
|
+
* @param customUserAgent Optional custom application identifier
|
|
27
|
+
* @returns User-Agent header value (never throws)
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildUserAgent(customUserAgent?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Build detailed client info for X-Envoy-Client-Info header
|
|
32
|
+
*
|
|
33
|
+
* This function is designed to never throw exceptions. If any error occurs
|
|
34
|
+
* during info collection, it uses safe fallback values.
|
|
35
|
+
*
|
|
36
|
+
* @param customUserAgent Optional custom application identifier
|
|
37
|
+
* @returns ClientInfo object (never throws)
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildClientInfo(customUserAgent?: string): ClientInfo;
|
|
40
|
+
/**
|
|
41
|
+
* Build X-Envoy-Client-Info header value (JSON string)
|
|
42
|
+
*
|
|
43
|
+
* This function is designed to never throw exceptions. If JSON serialization
|
|
44
|
+
* fails, it returns a minimal safe JSON string.
|
|
45
|
+
*
|
|
46
|
+
* @param customUserAgent Optional custom application identifier
|
|
47
|
+
* @returns JSON string for X-Envoy-Client-Info header (never throws)
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildClientInfoHeader(customUserAgent?: string): string;
|
|
50
|
+
//# sourceMappingURL=userAgent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userAgent.d.ts","sourceRoot":"","sources":["../../src/util/userAgent.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,eAAe;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,kBAAkB;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA8BD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAU/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,UAAU,CA8BpE;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAUtE"}
|
|
@@ -0,0 +1,132 @@
|
|
|
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.buildClientInfoHeader = exports.buildClientInfo = exports.buildUserAgent = void 0;
|
|
7
|
+
var os_1 = __importDefault(require("os"));
|
|
8
|
+
// Safe version extraction with fallback
|
|
9
|
+
var version = 'unknown';
|
|
10
|
+
try {
|
|
11
|
+
// Import version from package.json
|
|
12
|
+
// Note: In compiled code, this resolves correctly
|
|
13
|
+
version = require('../../package.json').version;
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
// If package.json can't be loaded, use fallback version
|
|
17
|
+
// This ensures SDK initialization never fails
|
|
18
|
+
// Silently fail - User-Agent is telemetry, not critical functionality
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Safely get Node.js version, with fallback
|
|
22
|
+
* @returns Node.js version string without 'v' prefix
|
|
23
|
+
*/
|
|
24
|
+
function getNodeVersion() {
|
|
25
|
+
try {
|
|
26
|
+
if (process === null || process === void 0 ? void 0 : process.version) {
|
|
27
|
+
return process.version.replace('v', '');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
// Ignore error, use fallback
|
|
32
|
+
}
|
|
33
|
+
return 'unknown';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Safely get platform information, with fallback
|
|
37
|
+
* @returns Platform string (e.g., 'darwin', 'linux', 'win32')
|
|
38
|
+
*/
|
|
39
|
+
function getPlatform() {
|
|
40
|
+
try {
|
|
41
|
+
return os_1.default.platform();
|
|
42
|
+
}
|
|
43
|
+
catch (_a) {
|
|
44
|
+
// If os.platform() fails, return fallback
|
|
45
|
+
return 'unknown';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Build standard User-Agent header value
|
|
50
|
+
* Format: envoy-integrations-sdk/2.4.4 node/18.0.0
|
|
51
|
+
* With custom app: envoy-integrations-sdk/2.4.4 node/18.0.0 MyApp/1.0.0
|
|
52
|
+
*
|
|
53
|
+
* This function is designed to never throw exceptions. If any error occurs,
|
|
54
|
+
* it returns a safe fallback value to ensure SDK initialization succeeds.
|
|
55
|
+
*
|
|
56
|
+
* @param customUserAgent Optional custom application identifier
|
|
57
|
+
* @returns User-Agent header value (never throws)
|
|
58
|
+
*/
|
|
59
|
+
function buildUserAgent(customUserAgent) {
|
|
60
|
+
try {
|
|
61
|
+
var nodeVersion = getNodeVersion();
|
|
62
|
+
var baseUA = "envoy-integrations-sdk/" + version + " node/" + nodeVersion;
|
|
63
|
+
return customUserAgent ? baseUA + " " + customUserAgent : baseUA;
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
// Critical fallback - should never happen, but ensures SDK always works
|
|
67
|
+
// Silently fail - User-Agent is telemetry, not critical functionality
|
|
68
|
+
return 'envoy-integrations-sdk/unknown node/unknown';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.buildUserAgent = buildUserAgent;
|
|
72
|
+
/**
|
|
73
|
+
* Build detailed client info for X-Envoy-Client-Info header
|
|
74
|
+
*
|
|
75
|
+
* This function is designed to never throw exceptions. If any error occurs
|
|
76
|
+
* during info collection, it uses safe fallback values.
|
|
77
|
+
*
|
|
78
|
+
* @param customUserAgent Optional custom application identifier
|
|
79
|
+
* @returns ClientInfo object (never throws)
|
|
80
|
+
*/
|
|
81
|
+
function buildClientInfo(customUserAgent) {
|
|
82
|
+
try {
|
|
83
|
+
var nodeVersion = getNodeVersion();
|
|
84
|
+
var platform = getPlatform();
|
|
85
|
+
var clientInfo = {
|
|
86
|
+
sdk: 'envoy-integrations-sdk',
|
|
87
|
+
version: version,
|
|
88
|
+
runtime: 'node',
|
|
89
|
+
runtimeVersion: nodeVersion,
|
|
90
|
+
platform: platform,
|
|
91
|
+
};
|
|
92
|
+
// Only add application if it's a non-empty string
|
|
93
|
+
if (customUserAgent) {
|
|
94
|
+
clientInfo.application = customUserAgent;
|
|
95
|
+
}
|
|
96
|
+
return clientInfo;
|
|
97
|
+
}
|
|
98
|
+
catch (_a) {
|
|
99
|
+
// Critical fallback - return minimal safe info
|
|
100
|
+
// Silently fail - User-Agent is telemetry, not critical functionality
|
|
101
|
+
return {
|
|
102
|
+
sdk: 'envoy-integrations-sdk',
|
|
103
|
+
version: 'unknown',
|
|
104
|
+
runtime: 'node',
|
|
105
|
+
runtimeVersion: 'unknown',
|
|
106
|
+
platform: 'unknown',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.buildClientInfo = buildClientInfo;
|
|
111
|
+
/**
|
|
112
|
+
* Build X-Envoy-Client-Info header value (JSON string)
|
|
113
|
+
*
|
|
114
|
+
* This function is designed to never throw exceptions. If JSON serialization
|
|
115
|
+
* fails, it returns a minimal safe JSON string.
|
|
116
|
+
*
|
|
117
|
+
* @param customUserAgent Optional custom application identifier
|
|
118
|
+
* @returns JSON string for X-Envoy-Client-Info header (never throws)
|
|
119
|
+
*/
|
|
120
|
+
function buildClientInfoHeader(customUserAgent) {
|
|
121
|
+
try {
|
|
122
|
+
var clientInfo = buildClientInfo(customUserAgent);
|
|
123
|
+
return JSON.stringify(clientInfo);
|
|
124
|
+
}
|
|
125
|
+
catch (_a) {
|
|
126
|
+
// Critical fallback - return minimal valid JSON
|
|
127
|
+
// Silently fail - User-Agent is telemetry, not critical functionality
|
|
128
|
+
// Return minimal valid JSON that won't break parsing
|
|
129
|
+
return '{"sdk":"envoy-integrations-sdk","version":"unknown","runtime":"node","runtimeVersion":"unknown","platform":"unknown"}';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.buildClientInfoHeader = buildClientInfoHeader;
|
package/package.json
CHANGED
package/src/base/EnvoyAPI.ts
CHANGED
|
@@ -4,11 +4,28 @@ import JSONAPIData from '../util/json-api/JSONAPIData';
|
|
|
4
4
|
import { envoyBaseURL } from '../constants';
|
|
5
5
|
import { createAxiosClient } from '../util/axiosConstructor';
|
|
6
6
|
import { EMPTY_STORAGE_ERROR_MESSAGE } from '../util/errorHandling';
|
|
7
|
+
import { buildUserAgent, buildClientInfoHeader } from '../util/userAgent';
|
|
7
8
|
|
|
8
9
|
interface EnvoyWebDataLoaderKey extends JSONAPIData {
|
|
9
10
|
include?: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Options for configuring EnvoyAPI client
|
|
15
|
+
*/
|
|
16
|
+
export interface EnvoyAPIOptions {
|
|
17
|
+
/** Access token for authentication */
|
|
18
|
+
accessToken: string;
|
|
19
|
+
/**
|
|
20
|
+
* Custom application identifier appended to User-Agent header.
|
|
21
|
+
* Format: "AppName/Version"
|
|
22
|
+
* Example: "MyCompanyApp/1.0.0"
|
|
23
|
+
*
|
|
24
|
+
* This identifier helps track API usage by application and aids in debugging.
|
|
25
|
+
*/
|
|
26
|
+
userAgent?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
/**
|
|
13
30
|
* Sometimes envoy-web will give us back some relationship data
|
|
14
31
|
* with the "type" set to the relationships name instead of the actual model's name.
|
|
@@ -27,6 +44,7 @@ const TYPE_ALIASES = new Map<string, string>([['employee-screening-flows', 'flow
|
|
|
27
44
|
export default class EnvoyAPI {
|
|
28
45
|
/**
|
|
29
46
|
* HTTP Client with Envoy's defaults.
|
|
47
|
+
* User-Agent headers are set in the constructor after client instantiation.
|
|
30
48
|
*/
|
|
31
49
|
readonly axios = createAxiosClient({
|
|
32
50
|
baseURL: envoyBaseURL,
|
|
@@ -59,8 +77,51 @@ export default class EnvoyAPI {
|
|
|
59
77
|
},
|
|
60
78
|
);
|
|
61
79
|
|
|
62
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Create an EnvoyAPI client instance
|
|
82
|
+
*
|
|
83
|
+
* @param options - Either an access token string or an EnvoyAPIOptions object
|
|
84
|
+
* with accessToken and optional userAgent
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* // Simple usage with access token only
|
|
88
|
+
* const client = new EnvoyAPI('access-token-here');
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* // Usage with custom User-Agent for tracking and debugging
|
|
92
|
+
* const client = new EnvoyAPI({
|
|
93
|
+
* accessToken: 'access-token-here',
|
|
94
|
+
* userAgent: 'MyApp/1.0.0'
|
|
95
|
+
* });
|
|
96
|
+
*/
|
|
97
|
+
constructor(options: EnvoyAPIOptions | string) {
|
|
98
|
+
// Support both string and options object formats
|
|
99
|
+
const { accessToken, userAgent } = typeof options === 'string'
|
|
100
|
+
? { accessToken: options, userAgent: undefined }
|
|
101
|
+
: options;
|
|
102
|
+
|
|
103
|
+
// Set authorization header (critical - must succeed)
|
|
63
104
|
this.axios.defaults.headers.authorization = `Bearer ${accessToken}`;
|
|
105
|
+
|
|
106
|
+
// Set User-Agent headers with absolute guarantee that failures won't break SDK
|
|
107
|
+
// GUARANTEE: This block will NEVER throw an exception, no matter what happens
|
|
108
|
+
// User-Agent headers are telemetry/debugging aids, not critical for SDK functionality
|
|
109
|
+
try {
|
|
110
|
+
// Primary attempt: Use full header generation functions
|
|
111
|
+
this.axios.defaults.headers['User-Agent'] = buildUserAgent(userAgent);
|
|
112
|
+
this.axios.defaults.headers['X-Envoy-Client-Info'] = buildClientInfoHeader(userAgent);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
// Secondary fallback: Set minimal valid headers
|
|
115
|
+
try {
|
|
116
|
+
this.axios.defaults.headers['User-Agent'] = 'envoy-integrations-sdk/unknown';
|
|
117
|
+
this.axios.defaults.headers['X-Envoy-Client-Info'] = '{"sdk":"envoy-integrations-sdk"}';
|
|
118
|
+
} catch (fallbackError) {
|
|
119
|
+
// Tertiary fallback: Even setting minimal headers failed
|
|
120
|
+
// Continue without User-Agent headers - SDK remains fully functional
|
|
121
|
+
// This catch ensures absolute guarantee that SDK initialization succeeds
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
64
125
|
/**
|
|
65
126
|
* Saves every model that was "include"ed in the response,
|
|
66
127
|
* which saves us the trouble of fetching related data.
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,10 @@ type EnvoyOptionsRouteParams = {
|
|
|
2
2
|
search?: string;
|
|
3
3
|
page?: number;
|
|
4
4
|
cursor?: string;
|
|
5
|
+
zone_id?: string;
|
|
6
|
+
location_id?: string;
|
|
7
|
+
/** ID of selected option when this is a mapped field. */
|
|
8
|
+
parent_resource_id?: string;
|
|
5
9
|
};
|
|
6
10
|
|
|
7
11
|
export default EnvoyOptionsRouteParams;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
|
|
3
|
+
// Safe version extraction with fallback
|
|
4
|
+
let version = 'unknown';
|
|
5
|
+
try {
|
|
6
|
+
// Import version from package.json
|
|
7
|
+
// Note: In compiled code, this resolves correctly
|
|
8
|
+
version = require('../../package.json').version;
|
|
9
|
+
} catch {
|
|
10
|
+
// If package.json can't be loaded, use fallback version
|
|
11
|
+
// This ensures SDK initialization never fails
|
|
12
|
+
// Silently fail - User-Agent is telemetry, not critical functionality
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Client information for detailed telemetry
|
|
17
|
+
*/
|
|
18
|
+
export interface ClientInfo {
|
|
19
|
+
/** SDK name */
|
|
20
|
+
sdk: string;
|
|
21
|
+
/** SDK version */
|
|
22
|
+
version: string;
|
|
23
|
+
/** Runtime (e.g., 'node') */
|
|
24
|
+
runtime: string;
|
|
25
|
+
/** Runtime version (e.g., '18.0.0') */
|
|
26
|
+
runtimeVersion: string;
|
|
27
|
+
/** Operating system platform */
|
|
28
|
+
platform: string;
|
|
29
|
+
/** Optional custom application identifier (e.g., 'MyApp/1.0.0') */
|
|
30
|
+
application?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Safely get Node.js version, with fallback
|
|
35
|
+
* @returns Node.js version string without 'v' prefix
|
|
36
|
+
*/
|
|
37
|
+
function getNodeVersion(): string {
|
|
38
|
+
try {
|
|
39
|
+
if (process?.version) {
|
|
40
|
+
return process.version.replace('v', '');
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
// Ignore error, use fallback
|
|
44
|
+
}
|
|
45
|
+
return 'unknown';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Safely get platform information, with fallback
|
|
50
|
+
* @returns Platform string (e.g., 'darwin', 'linux', 'win32')
|
|
51
|
+
*/
|
|
52
|
+
function getPlatform(): string {
|
|
53
|
+
try {
|
|
54
|
+
return os.platform();
|
|
55
|
+
} catch {
|
|
56
|
+
// If os.platform() fails, return fallback
|
|
57
|
+
return 'unknown';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Build standard User-Agent header value
|
|
63
|
+
* Format: envoy-integrations-sdk/2.4.4 node/18.0.0
|
|
64
|
+
* With custom app: envoy-integrations-sdk/2.4.4 node/18.0.0 MyApp/1.0.0
|
|
65
|
+
*
|
|
66
|
+
* This function is designed to never throw exceptions. If any error occurs,
|
|
67
|
+
* it returns a safe fallback value to ensure SDK initialization succeeds.
|
|
68
|
+
*
|
|
69
|
+
* @param customUserAgent Optional custom application identifier
|
|
70
|
+
* @returns User-Agent header value (never throws)
|
|
71
|
+
*/
|
|
72
|
+
export function buildUserAgent(customUserAgent?: string): string {
|
|
73
|
+
try {
|
|
74
|
+
const nodeVersion = getNodeVersion();
|
|
75
|
+
const baseUA = `envoy-integrations-sdk/${version} node/${nodeVersion}`;
|
|
76
|
+
return customUserAgent ? `${baseUA} ${customUserAgent}` : baseUA;
|
|
77
|
+
} catch {
|
|
78
|
+
// Critical fallback - should never happen, but ensures SDK always works
|
|
79
|
+
// Silently fail - User-Agent is telemetry, not critical functionality
|
|
80
|
+
return 'envoy-integrations-sdk/unknown node/unknown';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Build detailed client info for X-Envoy-Client-Info header
|
|
86
|
+
*
|
|
87
|
+
* This function is designed to never throw exceptions. If any error occurs
|
|
88
|
+
* during info collection, it uses safe fallback values.
|
|
89
|
+
*
|
|
90
|
+
* @param customUserAgent Optional custom application identifier
|
|
91
|
+
* @returns ClientInfo object (never throws)
|
|
92
|
+
*/
|
|
93
|
+
export function buildClientInfo(customUserAgent?: string): ClientInfo {
|
|
94
|
+
try {
|
|
95
|
+
const nodeVersion = getNodeVersion();
|
|
96
|
+
const platform = getPlatform();
|
|
97
|
+
|
|
98
|
+
const clientInfo: ClientInfo = {
|
|
99
|
+
sdk: 'envoy-integrations-sdk',
|
|
100
|
+
version,
|
|
101
|
+
runtime: 'node',
|
|
102
|
+
runtimeVersion: nodeVersion,
|
|
103
|
+
platform,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Only add application if it's a non-empty string
|
|
107
|
+
if (customUserAgent) {
|
|
108
|
+
clientInfo.application = customUserAgent;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return clientInfo;
|
|
112
|
+
} catch {
|
|
113
|
+
// Critical fallback - return minimal safe info
|
|
114
|
+
// Silently fail - User-Agent is telemetry, not critical functionality
|
|
115
|
+
return {
|
|
116
|
+
sdk: 'envoy-integrations-sdk',
|
|
117
|
+
version: 'unknown',
|
|
118
|
+
runtime: 'node',
|
|
119
|
+
runtimeVersion: 'unknown',
|
|
120
|
+
platform: 'unknown',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Build X-Envoy-Client-Info header value (JSON string)
|
|
127
|
+
*
|
|
128
|
+
* This function is designed to never throw exceptions. If JSON serialization
|
|
129
|
+
* fails, it returns a minimal safe JSON string.
|
|
130
|
+
*
|
|
131
|
+
* @param customUserAgent Optional custom application identifier
|
|
132
|
+
* @returns JSON string for X-Envoy-Client-Info header (never throws)
|
|
133
|
+
*/
|
|
134
|
+
export function buildClientInfoHeader(customUserAgent?: string): string {
|
|
135
|
+
try {
|
|
136
|
+
const clientInfo = buildClientInfo(customUserAgent);
|
|
137
|
+
return JSON.stringify(clientInfo);
|
|
138
|
+
} catch {
|
|
139
|
+
// Critical fallback - return minimal valid JSON
|
|
140
|
+
// Silently fail - User-Agent is telemetry, not critical functionality
|
|
141
|
+
// Return minimal valid JSON that won't break parsing
|
|
142
|
+
return '{"sdk":"envoy-integrations-sdk","version":"unknown","runtime":"node","runtimeVersion":"unknown","platform":"unknown"}';
|
|
143
|
+
}
|
|
144
|
+
}
|