@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.
Files changed (68) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +122 -0
  3. package/dist/client.d.ts +86 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +167 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/connect-api-client.d.ts +82 -0
  8. package/dist/connect-api-client.d.ts.map +1 -0
  9. package/dist/connect-api-client.js +106 -0
  10. package/dist/connect-api-client.js.map +1 -0
  11. package/dist/constants.d.ts +64 -0
  12. package/dist/constants.d.ts.map +1 -0
  13. package/dist/constants.js +68 -0
  14. package/dist/constants.js.map +1 -0
  15. package/dist/errors/api.d.ts +79 -0
  16. package/dist/errors/api.d.ts.map +1 -0
  17. package/dist/errors/api.js +128 -0
  18. package/dist/errors/api.js.map +1 -0
  19. package/dist/errors/auth.d.ts +35 -0
  20. package/dist/errors/auth.d.ts.map +1 -0
  21. package/dist/errors/auth.js +50 -0
  22. package/dist/errors/auth.js.map +1 -0
  23. package/dist/errors/base.d.ts +103 -0
  24. package/dist/errors/base.d.ts.map +1 -0
  25. package/dist/errors/base.js +162 -0
  26. package/dist/errors/base.js.map +1 -0
  27. package/dist/errors/hub-org.d.ts +108 -0
  28. package/dist/errors/hub-org.d.ts.map +1 -0
  29. package/dist/errors/hub-org.js +144 -0
  30. package/dist/errors/hub-org.js.map +1 -0
  31. package/dist/errors/index.d.ts +33 -0
  32. package/dist/errors/index.d.ts.map +1 -0
  33. package/dist/errors/index.js +42 -0
  34. package/dist/errors/index.js.map +1 -0
  35. package/dist/errors/network.d.ts +53 -0
  36. package/dist/errors/network.d.ts.map +1 -0
  37. package/dist/errors/network.js +77 -0
  38. package/dist/errors/network.js.map +1 -0
  39. package/dist/errors/validation.d.ts +69 -0
  40. package/dist/errors/validation.d.ts.map +1 -0
  41. package/dist/errors/validation.js +96 -0
  42. package/dist/errors/validation.js.map +1 -0
  43. package/dist/index.d.ts +16 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +28 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/org-pref-checker.d.ts +129 -0
  48. package/dist/org-pref-checker.d.ts.map +1 -0
  49. package/dist/org-pref-checker.js +193 -0
  50. package/dist/org-pref-checker.js.map +1 -0
  51. package/dist/policy-fetcher.d.ts +144 -0
  52. package/dist/policy-fetcher.d.ts.map +1 -0
  53. package/dist/policy-fetcher.js +241 -0
  54. package/dist/policy-fetcher.js.map +1 -0
  55. package/dist/tsconfig.tsbuildinfo +1 -0
  56. package/dist/types/index.d.ts +532 -0
  57. package/dist/types/index.d.ts.map +1 -0
  58. package/dist/types/index.js +6 -0
  59. package/dist/types/index.js.map +1 -0
  60. package/dist/types/result.d.ts +282 -0
  61. package/dist/types/result.d.ts.map +1 -0
  62. package/dist/types/result.js +351 -0
  63. package/dist/types/result.js.map +1 -0
  64. package/dist/utils/error-classifier.d.ts +55 -0
  65. package/dist/utils/error-classifier.d.ts.map +1 -0
  66. package/dist/utils/error-classifier.js +90 -0
  67. package/dist/utils/error-classifier.js.map +1 -0
  68. package/package.json +143 -0
@@ -0,0 +1,64 @@
1
+ /**
2
+ * CAPG Client Library Constants
3
+ *
4
+ * Centralized constants for BPO names, field names, and query strings.
5
+ * These constants ensure consistency across the library and make it easier
6
+ * to update if Salesforce schema changes.
7
+ *
8
+ * @packageDocumentation
9
+ * @since v1.0.0
10
+ */
11
+ /**
12
+ * Salesforce Business Process Object (BPO) Names
13
+ */
14
+ export declare const BPO_NAMES: {
15
+ /**
16
+ * DevopsGovernancePolicy - Core governance policy object
17
+ *
18
+ * This BPO stores all CAPG governance policies. When this object does not exist
19
+ * in an org, governance is considered disabled for that org.
20
+ */
21
+ readonly GOVERNANCE_POLICY: "DevopsGovernancePolicy";
22
+ };
23
+ /**
24
+ * SOQL Query Templates
25
+ *
26
+ * Hardcoded SOQL queries to prevent injection vulnerabilities.
27
+ * All queries use string constants - NO dynamic string construction.
28
+ *
29
+ * NOTE: These must be plain string literals (not template literals) to ensure
30
+ * they are fully evaluated at compile time and can be verified in builds.
31
+ */
32
+ export declare const SOQL_QUERIES: {
33
+ /**
34
+ * Check if governance is enabled by querying for BPO existence
35
+ *
36
+ * Returns:
37
+ * - Query succeeds (totalSize >= 0): governance enabled
38
+ * - Query throws INVALID_TYPE: governance disabled (BPO doesn't exist)
39
+ */
40
+ readonly CHECK_GOVERNANCE_ENABLED: "SELECT Id FROM DevopsGovernancePolicy LIMIT 1";
41
+ /**
42
+ * Fetch all policy fields
43
+ *
44
+ * Used by PolicyFetcher to retrieve complete policy data.
45
+ * WHERE clause and ORDER BY are appended dynamically but safely
46
+ * (using parameterized queries, not string concatenation).
47
+ */
48
+ readonly FETCH_POLICIES_BASE: "SELECT Id, PolicyCode, Name, Description, Category, Status, RuleContent, PolicySource, GlobalPolicyVersion, CreatedDate, LastModifiedDate FROM DevopsGovernancePolicy";
49
+ };
50
+ /**
51
+ * Error Codes
52
+ *
53
+ * Salesforce error codes that have special handling in the library.
54
+ */
55
+ export declare const SALESFORCE_ERROR_CODES: {
56
+ /**
57
+ * INVALID_TYPE - Thrown when querying a non-existent sObject
58
+ *
59
+ * For CAPG Client, this error means the DevopsGovernancePolicy BPO does not
60
+ * exist in the org, indicating governance is disabled (not a real error).
61
+ */
62
+ readonly INVALID_TYPE: "INVALID_TYPE";
63
+ };
64
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AAEH;;GAEG;AACH,eAAO,MAAM,SAAS;IACpB;;;;;OAKG;;CAEK,CAAC;AAEX;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY;IACvB;;;;;;OAMG;;IAGH;;;;;;OAMG;;CAGK,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;IACjC;;;;;OAKG;;CAEK,CAAC"}
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc. All rights reserved.
3
+ * See LICENSE.txt for license terms.
4
+ */
5
+ /**
6
+ * CAPG Client Library Constants
7
+ *
8
+ * Centralized constants for BPO names, field names, and query strings.
9
+ * These constants ensure consistency across the library and make it easier
10
+ * to update if Salesforce schema changes.
11
+ *
12
+ * @packageDocumentation
13
+ * @since v1.0.0
14
+ */
15
+ /**
16
+ * Salesforce Business Process Object (BPO) Names
17
+ */
18
+ export const BPO_NAMES = {
19
+ /**
20
+ * DevopsGovernancePolicy - Core governance policy object
21
+ *
22
+ * This BPO stores all CAPG governance policies. When this object does not exist
23
+ * in an org, governance is considered disabled for that org.
24
+ */
25
+ GOVERNANCE_POLICY: 'DevopsGovernancePolicy',
26
+ };
27
+ /**
28
+ * SOQL Query Templates
29
+ *
30
+ * Hardcoded SOQL queries to prevent injection vulnerabilities.
31
+ * All queries use string constants - NO dynamic string construction.
32
+ *
33
+ * NOTE: These must be plain string literals (not template literals) to ensure
34
+ * they are fully evaluated at compile time and can be verified in builds.
35
+ */
36
+ export const SOQL_QUERIES = {
37
+ /**
38
+ * Check if governance is enabled by querying for BPO existence
39
+ *
40
+ * Returns:
41
+ * - Query succeeds (totalSize >= 0): governance enabled
42
+ * - Query throws INVALID_TYPE: governance disabled (BPO doesn't exist)
43
+ */
44
+ CHECK_GOVERNANCE_ENABLED: 'SELECT Id FROM DevopsGovernancePolicy LIMIT 1',
45
+ /**
46
+ * Fetch all policy fields
47
+ *
48
+ * Used by PolicyFetcher to retrieve complete policy data.
49
+ * WHERE clause and ORDER BY are appended dynamically but safely
50
+ * (using parameterized queries, not string concatenation).
51
+ */
52
+ FETCH_POLICIES_BASE: 'SELECT Id, PolicyCode, Name, Description, Category, Status, RuleContent, PolicySource, GlobalPolicyVersion, CreatedDate, LastModifiedDate FROM DevopsGovernancePolicy',
53
+ };
54
+ /**
55
+ * Error Codes
56
+ *
57
+ * Salesforce error codes that have special handling in the library.
58
+ */
59
+ export const SALESFORCE_ERROR_CODES = {
60
+ /**
61
+ * INVALID_TYPE - Thrown when querying a non-existent sObject
62
+ *
63
+ * For CAPG Client, this error means the DevopsGovernancePolicy BPO does not
64
+ * exist in the org, indicating governance is disabled (not a real error).
65
+ */
66
+ INVALID_TYPE: 'INVALID_TYPE',
67
+ };
68
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;;;;OAKG;IACH,iBAAiB,EAAE,wBAAwB;CACnC,CAAC;AAEX;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B;;;;;;OAMG;IACH,wBAAwB,EAAE,+CAA+C;IAEzE;;;;;;OAMG;IACH,mBAAmB,EACjB,uKAAuK;CACjK,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC;;;;;OAKG;IACH,YAAY,EAAE,cAAc;CACpB,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * API Error Class
3
+ *
4
+ * Thrown when HTTP API calls return error responses (4xx, 5xx).
5
+ * This error has dynamic behavior based on the HTTP status code:
6
+ * - 4xx (Client Errors): Not retryable, user actionable
7
+ * - 5xx (Server Errors): Retryable, not user actionable
8
+ *
9
+ * Properties:
10
+ * - code: 'API_ERROR'
11
+ * - statusCode: HTTP status code (400-599)
12
+ * - responseBody: Optional response body for debugging
13
+ * - isRetryable: true for 5xx, false for 4xx
14
+ * - isUserActionable: true for 4xx, false for 5xx
15
+ * - suggestedAction: Dynamic based on status code
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * throw new CAPGAPIError(404, 'Policy not found');
20
+ * throw new CAPGAPIError(500, 'Internal Server Error');
21
+ * ```
22
+ */
23
+ import { CAPGError } from './base.js';
24
+ export declare class CAPGAPIError extends CAPGError {
25
+ /**
26
+ * HTTP status code (400-599)
27
+ *
28
+ * @readonly
29
+ */
30
+ readonly statusCode: number;
31
+ /**
32
+ * Optional response body for debugging
33
+ *
34
+ * @readonly
35
+ */
36
+ readonly responseBody?: unknown;
37
+ /**
38
+ * Creates a new CAPGAPIError instance
39
+ *
40
+ * @param statusCode - HTTP status code (400-599)
41
+ * @param message - Human-readable error message
42
+ * @param responseBody - Optional response body for debugging
43
+ * @param cause - Optional underlying error that caused this API error
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // 404 error (client error - not retryable)
48
+ * const error404 = new CAPGAPIError(404, 'Policy not found');
49
+ * console.log(error404.isRetryable); // false
50
+ * console.log(error404.isUserActionable); // true
51
+ *
52
+ * // 500 error (server error - retryable)
53
+ * const error500 = new CAPGAPIError(500, 'Internal Server Error');
54
+ * console.log(error500.isRetryable); // true
55
+ * console.log(error500.isUserActionable); // false
56
+ *
57
+ * // With response body
58
+ * const errorWithBody = new CAPGAPIError(
59
+ * 400,
60
+ * 'Invalid surface',
61
+ * { error: 'INVALID_SURFACE', message: 'Surface must be one of: vibes, vaas, codey' }
62
+ * );
63
+ * ```
64
+ */
65
+ constructor(statusCode: number, message: string, responseBody?: unknown, cause?: Error);
66
+ /**
67
+ * Get suggested action based on HTTP status code
68
+ *
69
+ * @param statusCode - HTTP status code
70
+ * @returns Suggested action string
71
+ */
72
+ private static getSuggestedAction;
73
+ /**
74
+ * Serializes the API error to JSON
75
+ * Includes statusCode and responseBody properties
76
+ */
77
+ toJSON(): Record<string, unknown>;
78
+ }
79
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/errors/api.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,qBAAa,YAAa,SAAQ,SAAS;IACzC;;;;OAIG;IACH,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC;;;;OAIG;IACH,SAAgB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;gBACgB,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK;IAgC7F;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAajC;;;OAGG;IACI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAazC"}
@@ -0,0 +1,128 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc. All rights reserved.
3
+ * See LICENSE.txt for license terms.
4
+ */
5
+ /**
6
+ * API Error Class
7
+ *
8
+ * Thrown when HTTP API calls return error responses (4xx, 5xx).
9
+ * This error has dynamic behavior based on the HTTP status code:
10
+ * - 4xx (Client Errors): Not retryable, user actionable
11
+ * - 5xx (Server Errors): Retryable, not user actionable
12
+ *
13
+ * Properties:
14
+ * - code: 'API_ERROR'
15
+ * - statusCode: HTTP status code (400-599)
16
+ * - responseBody: Optional response body for debugging
17
+ * - isRetryable: true for 5xx, false for 4xx
18
+ * - isUserActionable: true for 4xx, false for 5xx
19
+ * - suggestedAction: Dynamic based on status code
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * throw new CAPGAPIError(404, 'Policy not found');
24
+ * throw new CAPGAPIError(500, 'Internal Server Error');
25
+ * ```
26
+ */
27
+ import { CAPGError } from './base.js';
28
+ export class CAPGAPIError extends CAPGError {
29
+ /**
30
+ * HTTP status code (400-599)
31
+ *
32
+ * @readonly
33
+ */
34
+ statusCode;
35
+ /**
36
+ * Optional response body for debugging
37
+ *
38
+ * @readonly
39
+ */
40
+ responseBody;
41
+ /**
42
+ * Creates a new CAPGAPIError instance
43
+ *
44
+ * @param statusCode - HTTP status code (400-599)
45
+ * @param message - Human-readable error message
46
+ * @param responseBody - Optional response body for debugging
47
+ * @param cause - Optional underlying error that caused this API error
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // 404 error (client error - not retryable)
52
+ * const error404 = new CAPGAPIError(404, 'Policy not found');
53
+ * console.log(error404.isRetryable); // false
54
+ * console.log(error404.isUserActionable); // true
55
+ *
56
+ * // 500 error (server error - retryable)
57
+ * const error500 = new CAPGAPIError(500, 'Internal Server Error');
58
+ * console.log(error500.isRetryable); // true
59
+ * console.log(error500.isUserActionable); // false
60
+ *
61
+ * // With response body
62
+ * const errorWithBody = new CAPGAPIError(
63
+ * 400,
64
+ * 'Invalid surface',
65
+ * { error: 'INVALID_SURFACE', message: 'Surface must be one of: vibes, vaas, codey' }
66
+ * );
67
+ * ```
68
+ */
69
+ constructor(statusCode, message, responseBody, cause) {
70
+ // Determine if error is retryable based on status code
71
+ // 5xx errors are server errors and should be retried
72
+ // 4xx errors are client errors and should not be retried
73
+ const isRetryable = statusCode >= 500 && statusCode < 600;
74
+ // Determine if error is user actionable based on status code
75
+ // 4xx errors require user action to fix (bad request, auth, etc.)
76
+ // 5xx errors are server issues that users cannot fix
77
+ const isUserActionable = statusCode >= 400 && statusCode < 500;
78
+ // Generate suggested action based on status code
79
+ const suggestedAction = CAPGAPIError.getSuggestedAction(statusCode);
80
+ super('API_ERROR', message, suggestedAction, cause, isRetryable, isUserActionable);
81
+ // Set error name to class name for better stack traces
82
+ this.name = 'CAPGAPIError';
83
+ // Store status code and response body
84
+ this.statusCode = statusCode;
85
+ this.responseBody = responseBody;
86
+ // Maintain proper prototype chain for instanceof checks
87
+ Object.setPrototypeOf(this, CAPGAPIError.prototype);
88
+ // Capture stack trace for debugging
89
+ if (Error.captureStackTrace) {
90
+ Error.captureStackTrace(this, this.constructor);
91
+ }
92
+ }
93
+ /**
94
+ * Get suggested action based on HTTP status code
95
+ *
96
+ * @param statusCode - HTTP status code
97
+ * @returns Suggested action string
98
+ */
99
+ static getSuggestedAction(statusCode) {
100
+ if (statusCode >= 400 && statusCode < 500) {
101
+ // 4xx - Client errors
102
+ return 'Check your request parameters and try again';
103
+ }
104
+ else if (statusCode >= 500 && statusCode < 600) {
105
+ // 5xx - Server errors
106
+ return 'The server encountered an error. Try again later';
107
+ }
108
+ else {
109
+ // Other status codes (shouldn't normally happen)
110
+ return 'Check the error details and try again';
111
+ }
112
+ }
113
+ /**
114
+ * Serializes the API error to JSON
115
+ * Includes statusCode and responseBody properties
116
+ */
117
+ toJSON() {
118
+ const json = super.toJSON();
119
+ // Always include statusCode
120
+ json.statusCode = this.statusCode;
121
+ // Include responseBody if present
122
+ if (this.responseBody !== undefined) {
123
+ json.responseBody = this.responseBody;
124
+ }
125
+ return json;
126
+ }
127
+ }
128
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/errors/api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,OAAO,YAAa,SAAQ,SAAS;IACzC;;;;OAIG;IACa,UAAU,CAAS;IAEnC;;;;OAIG;IACa,YAAY,CAAW;IAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,YAAmB,UAAkB,EAAE,OAAe,EAAE,YAAsB,EAAE,KAAa;QAC3F,uDAAuD;QACvD,qDAAqD;QACrD,yDAAyD;QACzD,MAAM,WAAW,GAAG,UAAU,IAAI,GAAG,IAAI,UAAU,GAAG,GAAG,CAAC;QAE1D,6DAA6D;QAC7D,kEAAkE;QAClE,qDAAqD;QACrD,MAAM,gBAAgB,GAAG,UAAU,IAAI,GAAG,IAAI,UAAU,GAAG,GAAG,CAAC;QAE/D,iDAAiD;QACjD,MAAM,eAAe,GAAG,YAAY,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAEpE,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC;QAEnF,uDAAuD;QACvD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAE3B,sCAAsC;QACtC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,wDAAwD;QACxD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;QAEpD,oCAAoC;QACpC,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,kBAAkB,CAAC,UAAkB;QAClD,IAAI,UAAU,IAAI,GAAG,IAAI,UAAU,GAAG,GAAG,EAAE,CAAC;YAC1C,sBAAsB;YACtB,OAAO,6CAA6C,CAAC;QACvD,CAAC;aAAM,IAAI,UAAU,IAAI,GAAG,IAAI,UAAU,GAAG,GAAG,EAAE,CAAC;YACjD,sBAAsB;YACtB,OAAO,kDAAkD,CAAC;QAC5D,CAAC;aAAM,CAAC;YACN,iDAAiD;YACjD,OAAO,uCAAuC,CAAC;QACjD,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,MAAM;QACX,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAE5B,4BAA4B;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAElC,kCAAkC;QAClC,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACxC,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Authentication Error Class
3
+ *
4
+ * Thrown when authentication fails (HTTP 401 Unauthorized).
5
+ * This error indicates that the user needs to re-authenticate with the Hub Org.
6
+ *
7
+ * Properties:
8
+ * - code: 'AUTH_ERROR'
9
+ * - isRetryable: false (user must re-authenticate)
10
+ * - isUserActionable: true (user can fix by logging in)
11
+ * - suggestedAction: CLI command to re-authenticate
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * throw new CAPGAuthError('Session expired');
16
+ * ```
17
+ */
18
+ import { CAPGError } from './base.js';
19
+ export declare class CAPGAuthError extends CAPGError {
20
+ /**
21
+ * Creates a new CAPGAuthError instance
22
+ *
23
+ * @param message - Human-readable error message
24
+ * @param cause - Optional underlying error that caused this auth error
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const httpError = new Error('401 Unauthorized');
29
+ * const authError = new CAPGAuthError('Authentication failed', httpError);
30
+ * console.error(authError.suggestedAction); // "Re-login to Hub Org: sf org login web"
31
+ * ```
32
+ */
33
+ constructor(message: string, cause?: Error);
34
+ }
35
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/errors/auth.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,qBAAa,aAAc,SAAQ,SAAS;IAC1C;;;;;;;;;;;;OAYG;gBACgB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAqBlD"}
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc. All rights reserved.
3
+ * See LICENSE.txt for license terms.
4
+ */
5
+ /**
6
+ * Authentication Error Class
7
+ *
8
+ * Thrown when authentication fails (HTTP 401 Unauthorized).
9
+ * This error indicates that the user needs to re-authenticate with the Hub Org.
10
+ *
11
+ * Properties:
12
+ * - code: 'AUTH_ERROR'
13
+ * - isRetryable: false (user must re-authenticate)
14
+ * - isUserActionable: true (user can fix by logging in)
15
+ * - suggestedAction: CLI command to re-authenticate
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * throw new CAPGAuthError('Session expired');
20
+ * ```
21
+ */
22
+ import { CAPGError } from './base.js';
23
+ export class CAPGAuthError extends CAPGError {
24
+ /**
25
+ * Creates a new CAPGAuthError instance
26
+ *
27
+ * @param message - Human-readable error message
28
+ * @param cause - Optional underlying error that caused this auth error
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const httpError = new Error('401 Unauthorized');
33
+ * const authError = new CAPGAuthError('Authentication failed', httpError);
34
+ * console.error(authError.suggestedAction); // "Re-login to Hub Org: sf org login web"
35
+ * ```
36
+ */
37
+ constructor(message, cause) {
38
+ super('AUTH_ERROR', message, 'Re-login to Hub Org: sf org login web', cause, false, // Not retryable - user must re-authenticate
39
+ true);
40
+ // Set error name to class name for better stack traces
41
+ this.name = 'CAPGAuthError';
42
+ // Maintain proper prototype chain for instanceof checks
43
+ Object.setPrototypeOf(this, CAPGAuthError.prototype);
44
+ // Capture stack trace for debugging
45
+ if (Error.captureStackTrace) {
46
+ Error.captureStackTrace(this, this.constructor);
47
+ }
48
+ }
49
+ }
50
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/errors/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C;;;;;;;;;;;;OAYG;IACH,YAAmB,OAAe,EAAE,KAAa;QAC/C,KAAK,CACH,YAAY,EACZ,OAAO,EACP,uCAAuC,EACvC,KAAK,EACL,KAAK,EAAE,4CAA4C;QACnD,IAAI,CACL,CAAC;QAEF,uDAAuD;QACvD,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAE5B,wDAAwD;QACxD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;QAErD,oCAAoC;QACpC,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Base Error Class for CAPG Client
3
+ *
4
+ * This is the foundation error class for all CAPG-specific errors.
5
+ * All other error classes should extend this base class.
6
+ *
7
+ * Features:
8
+ * - Error code for programmatic error type identification
9
+ * - Error cause chaining for tracking root causes
10
+ * - Retry flags for automatic retry logic
11
+ * - User actionability flags for UX decisions
12
+ * - Request ID for distributed tracing
13
+ * - Suggested actions for user guidance
14
+ * - Stack trace preservation
15
+ * - JSON serialization support
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const error = new CAPGError(
20
+ * 'OPERATION_FAILED',
21
+ * 'Failed to complete operation',
22
+ * 'Try again later'
23
+ * );
24
+ * console.error(error.toJSON());
25
+ * ```
26
+ */
27
+ export declare class CAPGError extends Error {
28
+ /**
29
+ * Error code for programmatic identification
30
+ *
31
+ * @readonly
32
+ */
33
+ readonly code: string;
34
+ /**
35
+ * The underlying error that caused this error (if any)
36
+ *
37
+ * @readonly
38
+ */
39
+ readonly cause?: Error;
40
+ /**
41
+ * Whether this error is retryable (transient failure)
42
+ *
43
+ * @readonly
44
+ */
45
+ readonly isRetryable: boolean;
46
+ /**
47
+ * Whether user action can resolve this error
48
+ *
49
+ * @readonly
50
+ */
51
+ readonly isUserActionable: boolean;
52
+ /**
53
+ * Request ID for distributed tracing (optional)
54
+ */
55
+ requestId?: string;
56
+ /**
57
+ * Suggested action to resolve the error (optional)
58
+ *
59
+ * @readonly
60
+ */
61
+ readonly suggestedAction?: string;
62
+ /**
63
+ * Creates a new CAPGError instance
64
+ *
65
+ * @param code - Error code for programmatic identification
66
+ * @param message - Human-readable error message
67
+ * @param suggestedAction - Optional suggested action to resolve the error
68
+ * @param cause - Optional underlying error that caused this error
69
+ * @param isRetryable - Whether this error is retryable (default: false)
70
+ * @param isUserActionable - Whether user action can resolve this error (default: true)
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const error = new CAPGError(
75
+ * 'CONFIG_ERROR',
76
+ * 'Invalid configuration',
77
+ * 'Check your config file',
78
+ * originalError,
79
+ * false,
80
+ * true
81
+ * );
82
+ * ```
83
+ */
84
+ constructor(code: string, message: string, suggestedAction?: string, cause?: Error, isRetryable?: boolean, isUserActionable?: boolean);
85
+ /**
86
+ * Serializes the error to a JSON object
87
+ *
88
+ * This method is called automatically by JSON.stringify().
89
+ * It includes all error properties and recursively serializes
90
+ * the cause chain.
91
+ *
92
+ * @returns JSON representation of the error
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const error = new CAPGError('TEST_ERROR', 'Test message');
97
+ * const json = error.toJSON();
98
+ * console.log(JSON.stringify(json, null, 2));
99
+ * ```
100
+ */
101
+ toJSON(): Record<string, unknown>;
102
+ }
103
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/errors/base.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC;;;;OAIG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;;;OAIG;IACH,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;IAE9B;;;;OAIG;IACH,SAAgB,WAAW,EAAE,OAAO,CAAC;IAErC;;;;OAIG;IACH,SAAgB,gBAAgB,EAAE,OAAO,CAAC;IAE1C;;OAEG;IACI,SAAS,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,SAAgB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzC;;;;;;;;;;;;;;;;;;;;;OAqBG;gBAED,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,MAAM,EACxB,KAAK,CAAC,EAAE,KAAK,EACb,WAAW,GAAE,OAAe,EAC5B,gBAAgB,GAAE,OAAc;IA0BlC;;;;;;;;;;;;;;;OAeG;IACI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAuCzC"}