@salesforce/capg-client 0.1.0-beta.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.
- package/LICENSE.txt +21 -0
- package/README.md +122 -0
- package/dist/client.d.ts +86 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +167 -0
- package/dist/client.js.map +1 -0
- package/dist/connect-api-client.d.ts +82 -0
- package/dist/connect-api-client.d.ts.map +1 -0
- package/dist/connect-api-client.js +106 -0
- package/dist/connect-api-client.js.map +1 -0
- package/dist/constants.d.ts +64 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +68 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors/api.d.ts +79 -0
- package/dist/errors/api.d.ts.map +1 -0
- package/dist/errors/api.js +128 -0
- package/dist/errors/api.js.map +1 -0
- package/dist/errors/auth.d.ts +35 -0
- package/dist/errors/auth.d.ts.map +1 -0
- package/dist/errors/auth.js +50 -0
- package/dist/errors/auth.js.map +1 -0
- package/dist/errors/base.d.ts +103 -0
- package/dist/errors/base.d.ts.map +1 -0
- package/dist/errors/base.js +162 -0
- package/dist/errors/base.js.map +1 -0
- package/dist/errors/hub-org.d.ts +108 -0
- package/dist/errors/hub-org.d.ts.map +1 -0
- package/dist/errors/hub-org.js +144 -0
- package/dist/errors/hub-org.js.map +1 -0
- package/dist/errors/index.d.ts +33 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +42 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/network.d.ts +53 -0
- package/dist/errors/network.d.ts.map +1 -0
- package/dist/errors/network.js +77 -0
- package/dist/errors/network.js.map +1 -0
- package/dist/errors/validation.d.ts +69 -0
- package/dist/errors/validation.d.ts.map +1 -0
- package/dist/errors/validation.js +96 -0
- package/dist/errors/validation.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/org-pref-checker.d.ts +129 -0
- package/dist/org-pref-checker.d.ts.map +1 -0
- package/dist/org-pref-checker.js +193 -0
- package/dist/org-pref-checker.js.map +1 -0
- package/dist/policy-fetcher.d.ts +144 -0
- package/dist/policy-fetcher.d.ts.map +1 -0
- package/dist/policy-fetcher.js +241 -0
- package/dist/policy-fetcher.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/index.d.ts +532 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/result.d.ts +282 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +351 -0
- package/dist/types/result.js.map +1 -0
- package/dist/utils/error-classifier.d.ts +55 -0
- package/dist/utils/error-classifier.d.ts.map +1 -0
- package/dist/utils/error-classifier.js +90 -0
- package/dist/utils/error-classifier.js.map +1 -0
- package/package.json +143 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, Salesforce, Inc. All rights reserved.
|
|
3
|
+
* See LICENSE.txt for license terms.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Error Classification Utility
|
|
7
|
+
*
|
|
8
|
+
* Classifies unknown errors into appropriate CAPG error types based on
|
|
9
|
+
* status codes, error codes, and other error properties.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
* @since v1.0.0
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
import { CAPGError, CAPGAuthError, CAPGNetworkError, CAPGAPIError } from '../errors/index.js';
|
|
16
|
+
/**
|
|
17
|
+
* Redact credentials from a string to prevent leakage in logs/errors
|
|
18
|
+
*
|
|
19
|
+
* Removes:
|
|
20
|
+
* - Bearer tokens: 'Bearer abc123...' → 'Bearer ***'
|
|
21
|
+
* - Authorization headers: 'Authorization: Bearer xyz' → 'Authorization: ***'
|
|
22
|
+
* - Access tokens: 'access_token=abc123' → 'access_token=***'
|
|
23
|
+
*
|
|
24
|
+
* @param message - String that may contain credentials
|
|
25
|
+
* @returns Redacted string with credentials replaced by ***
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export function redactCredentials(message) {
|
|
30
|
+
return message
|
|
31
|
+
.replace(/Bearer\s+[A-Za-z0-9_\-.!]+/gi, 'Bearer ***')
|
|
32
|
+
.replace(/Authorization:\s*[^\s]+/gi, 'Authorization: ***')
|
|
33
|
+
.replace(/access_token[=:]\s*[^\s&]+/gi, 'access_token=***');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Classify unknown error into appropriate CAPG error type
|
|
37
|
+
*
|
|
38
|
+
* Classifies errors by type:
|
|
39
|
+
* - 401 → CAPGAuthError (not retryable)
|
|
40
|
+
* - ETIMEDOUT, ECONNREFUSED, ENOTFOUND → CAPGNetworkError (retryable)
|
|
41
|
+
* - 4xx/5xx → CAPGAPIError with status code
|
|
42
|
+
* - Unknown → CAPGError
|
|
43
|
+
*
|
|
44
|
+
* @param error - Error from external operation (query, network, etc.)
|
|
45
|
+
* @param context - Context information (username, operation name, etc.)
|
|
46
|
+
* @returns CAPGError or subclass
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* try {
|
|
51
|
+
* await connection.query(soql);
|
|
52
|
+
* } catch (error: unknown) {
|
|
53
|
+
* const capgError = classifyError(error, { username: 'user@example.com' });
|
|
54
|
+
* return err(capgError);
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export function classifyError(error, context) {
|
|
61
|
+
// Type guard: ensure error is an object before accessing properties
|
|
62
|
+
if (error == null || typeof error !== 'object') {
|
|
63
|
+
return new CAPGError('UNKNOWN_ERROR', `Unexpected error during ${context?.operation ?? 'operation'}`, 'Check the error details and try again', undefined, false);
|
|
64
|
+
}
|
|
65
|
+
const errorObj = error;
|
|
66
|
+
// Handle axios error format (error.response.status) and direct status codes
|
|
67
|
+
const statusCode = errorObj?.response?.status ?? errorObj?.statusCode ?? errorObj?.status;
|
|
68
|
+
const errorCode = errorObj?.code;
|
|
69
|
+
const errorMessage = errorObj?.response?.data?.message;
|
|
70
|
+
// Redact credentials from username before using in error messages
|
|
71
|
+
const username = redactCredentials(context?.username ?? 'unknown');
|
|
72
|
+
const operation = context?.operation ?? 'operation';
|
|
73
|
+
// Authentication errors (401, 403)
|
|
74
|
+
if (statusCode === 401 || statusCode === 403) {
|
|
75
|
+
return new CAPGAuthError(`Authentication failed for org '${username}'. Please re-authenticate.`, error instanceof Error ? error : undefined);
|
|
76
|
+
}
|
|
77
|
+
// Network errors (timeout, connection refused, DNS failure)
|
|
78
|
+
if (errorCode === 'ETIMEDOUT' || errorCode === 'ECONNREFUSED' || errorCode === 'ENOTFOUND') {
|
|
79
|
+
return new CAPGNetworkError(`Network error while ${operation}`, undefined, error instanceof Error ? error : undefined);
|
|
80
|
+
}
|
|
81
|
+
// API errors (4xx, 5xx)
|
|
82
|
+
if (statusCode && statusCode >= 400) {
|
|
83
|
+
// Include error message from response data if available
|
|
84
|
+
const message = errorMessage ? `${errorMessage}` : `API error while ${operation} (HTTP ${statusCode})`;
|
|
85
|
+
return new CAPGAPIError(statusCode, message, undefined, error instanceof Error ? error : undefined);
|
|
86
|
+
}
|
|
87
|
+
// Unknown error
|
|
88
|
+
return new CAPGError('UNKNOWN_ERROR', `Unexpected error while ${operation}`, 'Check the error details and try again', error instanceof Error ? error : undefined, false);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=error-classifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-classifier.js","sourceRoot":"","sources":["../../src/utils/error-classifier.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM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C,SAAS,CAC3C,CAAC;IACJ,CAAC;IAED,4DAA4D;IAC5D,IAAI,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,cAAc,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;QAC3F,OAAO,IAAI,gBAAgB,CACzB,uBAAuB,SAAS,EAAE,EAClC,SAAS,EACT,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAC;IACJ,CAAC;IAED,wBAAwB;IACxB,IAAI,UAAU,IAAI,UAAU,IAAI,GAAG,EAAE,CAAC;QACpC,wDAAwD;QACxD,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC,mBAAmB,SAAS,UAAU,UAAU,GAAG,CAAC;QACvG,OAAO,IAAI,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACtG,CAAC;IAED,gBAAgB;IAChB,OAAO,IAAI,SAAS,CAClB,eAAe,EACf,0BAA0B,SAAS,EAAE,EACrC,uCAAuC,EACvC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAC1C,KAAK,CACN,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/capg-client",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"description": "TypeScript client library for CAPG (Coding Agent Policy Governance) data fetching",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "wireit",
|
|
10
|
+
"test": "vitest",
|
|
11
|
+
"test:run": "wireit",
|
|
12
|
+
"test:unit": "wireit",
|
|
13
|
+
"test:coverage": "wireit",
|
|
14
|
+
"lint": "wireit",
|
|
15
|
+
"format": "wireit",
|
|
16
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
17
|
+
"docs": "typedoc src/index.ts --out api-docs",
|
|
18
|
+
"clean": "rm -rf dist coverage .wireit .eslintcache* *.tsbuildinfo api-docs",
|
|
19
|
+
"prepare": "husky",
|
|
20
|
+
"prepublishOnly": "npm run build && npm run test:run && npm run lint"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"salesforce",
|
|
24
|
+
"capg",
|
|
25
|
+
"governance",
|
|
26
|
+
"policy",
|
|
27
|
+
"devops"
|
|
28
|
+
],
|
|
29
|
+
"author": "DX Command Center Team",
|
|
30
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist/**",
|
|
33
|
+
"LICENSE.txt",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"registry": "https://registry.npmjs.org/"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@salesforce/core": "^8.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@salesforce/prettier-config": "^0.0.3",
|
|
45
|
+
"@types/node": "^20.0.0",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
47
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
48
|
+
"@vitest/coverage-v8": "^3.0.7",
|
|
49
|
+
"eslint": "^8.57.0",
|
|
50
|
+
"eslint-config-prettier": "^9.1.0",
|
|
51
|
+
"eslint-config-salesforce-typescript": "^3.4.0",
|
|
52
|
+
"eslint-plugin-jsdoc": "^46.10.1",
|
|
53
|
+
"eslint-plugin-security": "^3.0.0",
|
|
54
|
+
"husky": "^9.1.6",
|
|
55
|
+
"prettier": "^3.3.3",
|
|
56
|
+
"pretty-quick": "^4.0.0",
|
|
57
|
+
"typedoc": "^0.27.0",
|
|
58
|
+
"typescript": "^5.6.2",
|
|
59
|
+
"vitest": "^3.0.7",
|
|
60
|
+
"wireit": "^0.14.9"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"axios": "^1.6.0",
|
|
64
|
+
"zod": "^3.22.0"
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=18.0.0"
|
|
68
|
+
},
|
|
69
|
+
"wireit": {
|
|
70
|
+
"build": {
|
|
71
|
+
"command": "tsc --build --incremental",
|
|
72
|
+
"files": [
|
|
73
|
+
"src/**/*.ts",
|
|
74
|
+
"tsconfig.json"
|
|
75
|
+
],
|
|
76
|
+
"output": [
|
|
77
|
+
"dist/**",
|
|
78
|
+
"tsconfig.tsbuildinfo"
|
|
79
|
+
],
|
|
80
|
+
"clean": "if-file-deleted",
|
|
81
|
+
"dependencies": [
|
|
82
|
+
"lint"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"format": {
|
|
86
|
+
"command": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
87
|
+
"files": [
|
|
88
|
+
"src/**/*.ts",
|
|
89
|
+
"test/**/*.ts",
|
|
90
|
+
".prettierrc.cjs"
|
|
91
|
+
],
|
|
92
|
+
"output": []
|
|
93
|
+
},
|
|
94
|
+
"lint": {
|
|
95
|
+
"command": "eslint --fix ./src ./test --ext .ts --cache --cache-location .eslintcache",
|
|
96
|
+
"files": [
|
|
97
|
+
"src/**/*.ts",
|
|
98
|
+
"test/**/*.ts",
|
|
99
|
+
".eslintrc.json",
|
|
100
|
+
"tsconfig.json"
|
|
101
|
+
],
|
|
102
|
+
"output": [],
|
|
103
|
+
"dependencies": [
|
|
104
|
+
"format"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"test:unit": {
|
|
108
|
+
"command": "vitest run --dir ./test/unit",
|
|
109
|
+
"files": [
|
|
110
|
+
"src/**/*.ts",
|
|
111
|
+
"test/unit/**/*.ts",
|
|
112
|
+
"vitest.config.ts"
|
|
113
|
+
],
|
|
114
|
+
"output": [
|
|
115
|
+
"coverage/**"
|
|
116
|
+
],
|
|
117
|
+
"dependencies": [
|
|
118
|
+
"build"
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
"test:run": {
|
|
122
|
+
"description": "Run all tests and exit",
|
|
123
|
+
"dependencies": [
|
|
124
|
+
"test:unit",
|
|
125
|
+
"lint"
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
"test:coverage": {
|
|
129
|
+
"command": "vitest run --coverage --dir ./test/unit",
|
|
130
|
+
"files": [
|
|
131
|
+
"src/**/*.ts",
|
|
132
|
+
"test/unit/**/*.ts",
|
|
133
|
+
"vitest.config.ts"
|
|
134
|
+
],
|
|
135
|
+
"output": [
|
|
136
|
+
"coverage/**"
|
|
137
|
+
],
|
|
138
|
+
"dependencies": [
|
|
139
|
+
"build"
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|