@aglyn/shared-util-errors 1.0.0-beta.143

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @aglyn/shared-util-errors
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test shared-util-errors` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@aglyn/shared-util-errors",
3
+ "version": "1.0.0-beta.143",
4
+ "license": "Apache-2.0",
5
+ "homepage": "https://aglyn.com",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/aglyn/aglyn.git",
9
+ "directory": "libs/shared/util/errors"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "provenance": true
14
+ },
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./src/index.d.ts",
19
+ "default": "./src/index.js"
20
+ },
21
+ "./*": {
22
+ "types": "./src/lib/*.d.ts",
23
+ "default": "./src/lib/*.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "dependencies": {
28
+ "@aglyn/shared-data-enums": "1.0.0-beta.143",
29
+ "@aglyn/shared-util-tools": "1.0.0-beta.143",
30
+ "@swc/helpers": "0.5.23"
31
+ },
32
+ "sideEffects": false,
33
+ "types": "./src/index.d.ts",
34
+ "module": "./src/index.js",
35
+ "main": "./src/index.js"
36
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export * from './lib/errors';
package/src/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ export * from "./lib/errors.js";
17
+
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/shared/util/errors/src/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './lib/errors'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,kBAAc"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export * from './http-response-error';
18
+ export * from './upstream-service-error';
19
+ export * from './ns-error';
20
+ export * from './ns-error-factory';
21
+ export * from './tools';
22
+ export * from './types';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ export * from "./http-response-error.js";
17
+ export * from "./upstream-service-error.js";
18
+ export * from "./ns-error.js";
19
+ export * from "./ns-error-factory.js";
20
+ export * from "./tools.js";
21
+ export * from "./types.js";
22
+
23
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/errors/src/lib/errors.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nexport * from './http-response-error'\nexport * from './upstream-service-error'\nexport * from './ns-error'\nexport * from './ns-error-factory'\nexport * from './tools'\nexport * from './types'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,cAAc,2BAAuB;AACrC,cAAc,8BAA0B;AACxC,cAAc,gBAAY;AAC1B,cAAc,wBAAoB;AAClC,cAAc,aAAS;AACvB,cAAc,aAAS"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { HttpStatusCode } from '@aglyn/shared-data-enums/http';
18
+ export declare class HttpResponseError extends Error {
19
+ readonly code: HttpStatusCode;
20
+ readonly name = "HttpResponseError";
21
+ message: string;
22
+ constructor(code: HttpStatusCode, message: string);
23
+ }
24
+ export default HttpResponseError;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { HttpStatusCode } from "@aglyn/shared-data-enums/http";
17
+ export class HttpResponseError extends Error {
18
+ constructor(code = HttpStatusCode.OK, message){
19
+ super(message), this.code = code, this.name = 'HttpResponseError';
20
+ this.message = message;
21
+ // Fix For ES5
22
+ // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
23
+ Object.setPrototypeOf(this, HttpResponseError.prototype);
24
+ // Maintains proper stack trace for where our error was thrown.
25
+ // Only available on V8.
26
+ if (Error.captureStackTrace) {
27
+ Error.captureStackTrace(this, HttpResponseError);
28
+ }
29
+ }
30
+ }
31
+ export default HttpResponseError;
32
+
33
+ //# sourceMappingURL=http-response-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/errors/src/lib/http-response-error.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {HttpStatusCode} from '@aglyn/shared-data-enums/http'\n\n\nexport class HttpResponseError extends Error {\n override readonly name = 'HttpResponseError'\n\n override message: string\n\n constructor(\n public readonly code: HttpStatusCode = HttpStatusCode.OK,\n message: string,\n ) {\n super(message)\n this.message = message\n\n // Fix For ES5\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, HttpResponseError.prototype)\n\n // Maintains proper stack trace for where our error was thrown.\n // Only available on V8.\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, HttpResponseError)\n }\n }\n}\n\nexport default HttpResponseError\n"],"names":["HttpStatusCode","HttpResponseError","Error","code","OK","message","name","Object","setPrototypeOf","prototype","captureStackTrace"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAAQA,cAAc,QAAO,gCAA+B;AAG5D,OAAO,MAAMC,0BAA0BC;IAKrC,YACE,AAAgBC,OAAuBH,eAAeI,EAAE,EACxDC,OAAe,CACf;QACA,KAAK,CAACA,eAHUF,OAAAA,WALAG,OAAO;QASvB,IAAI,CAACD,OAAO,GAAGA;QAEf,cAAc;QACd,+IAA+I;QAC/IE,OAAOC,cAAc,CAAC,IAAI,EAAEP,kBAAkBQ,SAAS;QAEvD,+DAA+D;QAC/D,wBAAwB;QACxB,IAAIP,MAAMQ,iBAAiB,EAAE;YAC3BR,MAAMQ,iBAAiB,CAAC,IAAI,EAAET;QAChC;IACF;AACF;AAEA,eAAeA,kBAAiB"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { NsError } from './ns-error';
18
+ import type { ErrorPayload, ErrorTagMessages, ErrorTagPayloads, EventFlag } from './types';
19
+ /**
20
+ * Standardized App Errors
21
+ *
22
+ * Usage:
23
+ * ```typescript
24
+ * // Typescript string literals for type-safe codes
25
+ * type Err =
26
+ * 'unknown' |
27
+ * 'object-not-found'
28
+ * ;
29
+ *
30
+ * // Closure enum for type-safe error codes
31
+ * // at-enum {string}
32
+ * var Err = {
33
+ * UNKNOWN: 'unknown',
34
+ * OBJECT_NOT_FOUND: 'object-not-found',
35
+ * }
36
+ *
37
+ * let : Map<Err, string> = {
38
+ * 'generic-error': "Unknown error",
39
+ * 'file-not-found': "Could not find file: {$file}",
40
+ * };
41
+ *
42
+ * // Type-safe function - must pass a valid error code as param.
43
+ * let error = new ErrorFactory<Err>('scope', 'Service', presets);
44
+ *
45
+ * ...
46
+ * throw error.create(Err.GENERIC);
47
+ * ...
48
+ * throw error.create(Err.FILE_NOT_FOUND, {'file': fileName});
49
+ * ...
50
+ * // Service: Could not file file: foo.txt (scope/file-not-found).
51
+ *
52
+ * catch (e) {
53
+ * assert(e.message === "Could not find file: foo.txt.");
54
+ * if (e.code === 'scope/file-not-found') {
55
+ * console.log("Could not read file: " + e['file']);
56
+ * }
57
+ * }
58
+ * ```
59
+ * @see inspired by:
60
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
61
+ */
62
+ export declare class NsErrorFactory<T extends string = EventFlag, U extends ErrorTagPayloads = ErrorTagPayloads> {
63
+ private readonly scope;
64
+ private readonly namespace;
65
+ private readonly templates;
66
+ private readonly nsDelimiter;
67
+ private readonly scopeDelimiter;
68
+ private readonly defaultMessage;
69
+ private buildNamespace;
70
+ constructor(scope: string, namespace: string, templates: ErrorTagMessages<T>, nsDelimiter?: string, scopeDelimiter?: string, defaultMessage?: string);
71
+ protected makeShortCode<K extends T>(flag: K): string;
72
+ protected makeFullCode(shortCode: string): string;
73
+ protected makeShortMessage<K extends T>(flag: K, payload?: ErrorPayload): string;
74
+ protected makeFullMessage(shortCode: string, shortMessage: string): string;
75
+ /**
76
+ * Build a new throwable
77
+ * @example
78
+ * ```
79
+ * let age: string | number = 101
80
+ * const errorFactory = new NsErrorFactory('domain', 'my-lib', {
81
+ * ['bad-string']: "Provided an invalid string '{$str}'"
82
+ * })
83
+ * if (typeof age !== 'string') {
84
+ * throw errorFactory.create('bad-string', {str: age})
85
+ * // Out = domain - Provided an invalid string '101' (my-lib/bad-string)
86
+ * // Full Code = domain::my-lib/bad-string
87
+ * }
88
+ * ```
89
+ *
90
+ * @param flag - error event identifier
91
+ * @param payload - payload data to set template variable values
92
+ * @returns NsError
93
+ */
94
+ create<K extends T>(flag: K, ...payload: K extends keyof U ? [U[K]] : []): NsError;
95
+ childFactory<T extends string, U extends ErrorTagPayloads<T>>(childNamespace: string, templates?: ErrorTagMessages<T>): NsErrorFactory<T, U>;
96
+ }
@@ -0,0 +1,160 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { _isArr } from "@aglyn/shared-util-tools";
17
+ import { NsError } from "./ns-error.js";
18
+ import { replaceTemplate } from "./tools.js";
19
+ const DEFAULT_TEMPLATE = `{$scope} {$code} {$message}`;
20
+ function namespaceFactory(options) {
21
+ const { scope, namespace, nsDelimiter, scopeDelimiter, template, defaultMessage } = options;
22
+ function makeShortCode(flag) {
23
+ return [
24
+ namespace,
25
+ flag
26
+ ].join(nsDelimiter);
27
+ }
28
+ function makeFullCode(flag) {
29
+ return [
30
+ scope,
31
+ makeShortCode(flag)
32
+ ].join(scopeDelimiter);
33
+ }
34
+ function buildNamespace(message, code) {
35
+ const tmp = template || DEFAULT_TEMPLATE;
36
+ return replaceTemplate(tmp, {
37
+ scope,
38
+ code
39
+ });
40
+ }
41
+ const builders = new Map();
42
+ return (flag, msg = defaultMessage)=>{
43
+ if (!builders.has(flag)) {
44
+ const code = makeFullCode(flag);
45
+ builders.set(flag, code);
46
+ }
47
+ return buildNamespace(msg, builders.get(flag));
48
+ };
49
+ }
50
+ /**
51
+ * Standardized App Errors
52
+ *
53
+ * Usage:
54
+ * ```typescript
55
+ * // Typescript string literals for type-safe codes
56
+ * type Err =
57
+ * 'unknown' |
58
+ * 'object-not-found'
59
+ * ;
60
+ *
61
+ * // Closure enum for type-safe error codes
62
+ * // at-enum {string}
63
+ * var Err = {
64
+ * UNKNOWN: 'unknown',
65
+ * OBJECT_NOT_FOUND: 'object-not-found',
66
+ * }
67
+ *
68
+ * let : Map<Err, string> = {
69
+ * 'generic-error': "Unknown error",
70
+ * 'file-not-found': "Could not find file: {$file}",
71
+ * };
72
+ *
73
+ * // Type-safe function - must pass a valid error code as param.
74
+ * let error = new ErrorFactory<Err>('scope', 'Service', presets);
75
+ *
76
+ * ...
77
+ * throw error.create(Err.GENERIC);
78
+ * ...
79
+ * throw error.create(Err.FILE_NOT_FOUND, {'file': fileName});
80
+ * ...
81
+ * // Service: Could not file file: foo.txt (scope/file-not-found).
82
+ *
83
+ * catch (e) {
84
+ * assert(e.message === "Could not find file: foo.txt.");
85
+ * if (e.code === 'scope/file-not-found') {
86
+ * console.log("Could not read file: " + e['file']);
87
+ * }
88
+ * }
89
+ * ```
90
+ * @see inspired by:
91
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
92
+ */ export class NsErrorFactory {
93
+ makeShortCode(flag) {
94
+ return [
95
+ this.namespace,
96
+ flag
97
+ ].join(this.nsDelimiter);
98
+ }
99
+ makeFullCode(shortCode) {
100
+ return [
101
+ this.scope,
102
+ shortCode
103
+ ].join(this.scopeDelimiter);
104
+ }
105
+ makeShortMessage(flag, payload) {
106
+ const template = this.templates[flag];
107
+ return template ? replaceTemplate(template, payload) : this.defaultMessage;
108
+ }
109
+ makeFullMessage(shortCode, shortMessage) {
110
+ // Scope - Error message (namespace/flag).
111
+ // return `[${this.scope}] - ${shortMessage} (${shortCode}).`
112
+ return this.buildNamespace(shortCode, shortMessage);
113
+ }
114
+ /**
115
+ * Build a new throwable
116
+ * @example
117
+ * ```
118
+ * let age: string | number = 101
119
+ * const errorFactory = new NsErrorFactory('domain', 'my-lib', {
120
+ * ['bad-string']: "Provided an invalid string '{$str}'"
121
+ * })
122
+ * if (typeof age !== 'string') {
123
+ * throw errorFactory.create('bad-string', {str: age})
124
+ * // Out = domain - Provided an invalid string '101' (my-lib/bad-string)
125
+ * // Full Code = domain::my-lib/bad-string
126
+ * }
127
+ * ```
128
+ *
129
+ * @param flag - error event identifier
130
+ * @param payload - payload data to set template variable values
131
+ * @returns NsError
132
+ */ create(flag, ...payload) {
133
+ const data = _isArr(payload) && payload[0] || {}, shortCode = this.makeShortCode(flag), fullCode = this.makeFullCode(shortCode), shortMessage = this.makeShortMessage(flag, data), fullMessage = this.makeFullMessage(fullCode, shortMessage);
134
+ return new NsError(shortCode, fullMessage, data);
135
+ }
136
+ childFactory(childNamespace, templates) {
137
+ return new NsErrorFactory(this.scope, [
138
+ this.namespace,
139
+ childNamespace
140
+ ].join(this.nsDelimiter), templates || this.templates, this.nsDelimiter, this.scopeDelimiter, this.defaultMessage);
141
+ }
142
+ constructor(scope, namespace, templates, nsDelimiter = '/', scopeDelimiter = ':', defaultMessage = 'Error'){
143
+ this.scope = scope;
144
+ this.namespace = namespace;
145
+ this.templates = templates;
146
+ this.nsDelimiter = nsDelimiter;
147
+ this.scopeDelimiter = scopeDelimiter;
148
+ this.defaultMessage = defaultMessage;
149
+ this.create = this.create.bind(this);
150
+ this.buildNamespace = namespaceFactory({
151
+ scope,
152
+ namespace,
153
+ nsDelimiter,
154
+ scopeDelimiter,
155
+ defaultMessage
156
+ });
157
+ }
158
+ }
159
+
160
+ //# sourceMappingURL=ns-error-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/errors/src/lib/ns-error-factory.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { _isArr } from '@aglyn/shared-util-tools'\nimport { NsError } from './ns-error'\nimport { replaceTemplate } from './tools'\nimport type {\n ErrorPayload,\n ErrorTagMessages,\n ErrorTagPayloads,\n EventFlag,\n} from './types'\n\nconst DEFAULT_TEMPLATE = `{$scope} {$code} {$message}`\ntype DEFAULT_TEMPLATE = string & typeof DEFAULT_TEMPLATE\ninterface NamespaceOptions {\n scope: string\n namespace: string\n nsDelimiter: string\n scopeDelimiter: string\n template?: string | DEFAULT_TEMPLATE\n defaultMessage?: string\n}\n\nfunction namespaceFactory(options?: NamespaceOptions) {\n const {\n scope,\n namespace,\n nsDelimiter,\n scopeDelimiter,\n template,\n defaultMessage,\n } = options\n function makeShortCode<K extends string>(flag: K): string {\n return [namespace, flag].join(nsDelimiter)\n }\n function makeFullCode<K extends string>(flag: K): string {\n return [scope, makeShortCode(flag)].join(scopeDelimiter)\n }\n function buildNamespace(message: string, code: string) {\n const tmp = template || DEFAULT_TEMPLATE\n return replaceTemplate(tmp, {\n scope,\n code,\n })\n }\n const builders = new Map<string, string>()\n\n return <T extends string>(flag: T, msg: string = defaultMessage) => {\n if (!builders.has(flag)) {\n const code = makeFullCode(flag)\n builders.set(flag, code)\n }\n return buildNamespace(msg, builders.get(flag))\n }\n}\n\n/**\n * Standardized App Errors\n *\n * Usage:\n * ```typescript\n * // Typescript string literals for type-safe codes\n * type Err =\n * 'unknown' |\n * 'object-not-found'\n * ;\n *\n * // Closure enum for type-safe error codes\n * // at-enum {string}\n * var Err = {\n * UNKNOWN: 'unknown',\n * OBJECT_NOT_FOUND: 'object-not-found',\n * }\n *\n * let : Map<Err, string> = {\n * 'generic-error': \"Unknown error\",\n * 'file-not-found': \"Could not find file: {$file}\",\n * };\n *\n * // Type-safe function - must pass a valid error code as param.\n * let error = new ErrorFactory<Err>('scope', 'Service', presets);\n *\n * ...\n * throw error.create(Err.GENERIC);\n * ...\n * throw error.create(Err.FILE_NOT_FOUND, {'file': fileName});\n * ...\n * // Service: Could not file file: foo.txt (scope/file-not-found).\n *\n * catch (e) {\n * assert(e.message === \"Could not find file: foo.txt.\");\n * if (e.code === 'scope/file-not-found') {\n * console.log(\"Could not read file: \" + e['file']);\n * }\n * }\n * ```\n * @see inspired by:\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types\n */\nexport class NsErrorFactory<\n T extends string = EventFlag,\n U extends ErrorTagPayloads = ErrorTagPayloads,\n> {\n private buildNamespace: <T extends string>(flag: T, msg?: string) => string\n\n constructor(\n private readonly scope: string,\n private readonly namespace: string,\n private readonly templates: ErrorTagMessages<T>,\n private readonly nsDelimiter = '/',\n private readonly scopeDelimiter = ':',\n private readonly defaultMessage = 'Error',\n ) {\n this.create = this.create.bind(this)\n this.buildNamespace = namespaceFactory({\n scope,\n namespace,\n nsDelimiter,\n scopeDelimiter,\n defaultMessage,\n })\n }\n\n protected makeShortCode<K extends T>(flag: K): string {\n return [this.namespace, flag].join(this.nsDelimiter)\n }\n protected makeFullCode(shortCode: string): string {\n return [this.scope, shortCode].join(this.scopeDelimiter)\n }\n protected makeShortMessage<K extends T>(\n flag: K,\n payload?: ErrorPayload,\n ): string {\n const template = this.templates[flag]\n return template ? replaceTemplate(template, payload) : this.defaultMessage\n }\n protected makeFullMessage(shortCode: string, shortMessage: string): string {\n // Scope - Error message (namespace/flag).\n // return `[${this.scope}] - ${shortMessage} (${shortCode}).`\n return this.buildNamespace(shortCode, shortMessage)\n }\n\n /**\n * Build a new throwable\n * @example\n * ```\n * let age: string | number = 101\n * const errorFactory = new NsErrorFactory('domain', 'my-lib', {\n * ['bad-string']: \"Provided an invalid string '{$str}'\"\n * })\n * if (typeof age !== 'string') {\n * throw errorFactory.create('bad-string', {str: age})\n * // Out = domain - Provided an invalid string '101' (my-lib/bad-string)\n * // Full Code = domain::my-lib/bad-string\n * }\n * ```\n *\n * @param flag - error event identifier\n * @param payload - payload data to set template variable values\n * @returns NsError\n */\n public create<K extends T>(\n flag: K,\n ...payload: K extends keyof U ? [U[K]] : []\n ): NsError {\n const data: ErrorPayload = (_isArr(payload) && payload[0]) || {},\n shortCode = this.makeShortCode(flag),\n fullCode = this.makeFullCode(shortCode),\n shortMessage = this.makeShortMessage(flag, data),\n fullMessage = this.makeFullMessage(fullCode, shortMessage)\n\n return new NsError(shortCode, fullMessage, data)\n }\n\n public childFactory<T extends string, U extends ErrorTagPayloads<T>>(\n childNamespace: string,\n templates?: ErrorTagMessages<T>,\n ) {\n return new NsErrorFactory<T, U>(\n this.scope,\n [this.namespace, childNamespace].join(this.nsDelimiter),\n (templates || this.templates) as ErrorTagMessages<T>,\n this.nsDelimiter,\n this.scopeDelimiter,\n this.defaultMessage,\n )\n }\n}\n"],"names":["_isArr","NsError","replaceTemplate","DEFAULT_TEMPLATE","namespaceFactory","options","scope","namespace","nsDelimiter","scopeDelimiter","template","defaultMessage","makeShortCode","flag","join","makeFullCode","buildNamespace","message","code","tmp","builders","Map","msg","has","set","get","NsErrorFactory","shortCode","makeShortMessage","payload","templates","makeFullMessage","shortMessage","create","data","fullCode","fullMessage","childFactory","childNamespace","bind"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,MAAM,QAAQ,2BAA0B;AACjD,SAASC,OAAO,QAAQ,gBAAY;AACpC,SAASC,eAAe,QAAQ,aAAS;AAQzC,MAAMC,mBAAmB,CAAC,2BAA2B,CAAC;AAWtD,SAASC,iBAAiBC,OAA0B;IAClD,MAAM,EACJC,KAAK,EACLC,SAAS,EACTC,WAAW,EACXC,cAAc,EACdC,QAAQ,EACRC,cAAc,EACf,GAAGN;IACJ,SAASO,cAAgCC,IAAO;QAC9C,OAAO;YAACN;YAAWM;SAAK,CAACC,IAAI,CAACN;IAChC;IACA,SAASO,aAA+BF,IAAO;QAC7C,OAAO;YAACP;YAAOM,cAAcC;SAAM,CAACC,IAAI,CAACL;IAC3C;IACA,SAASO,eAAeC,OAAe,EAAEC,IAAY;QACnD,MAAMC,MAAMT,YAAYP;QACxB,OAAOD,gBAAgBiB,KAAK;YAC1Bb;YACAY;QACF;IACF;IACA,MAAME,WAAW,IAAIC;IAErB,OAAO,CAAmBR,MAASS,MAAcX,cAAc;QAC7D,IAAI,CAACS,SAASG,GAAG,CAACV,OAAO;YACvB,MAAMK,OAAOH,aAAaF;YAC1BO,SAASI,GAAG,CAACX,MAAMK;QACrB;QACA,OAAOF,eAAeM,KAAKF,SAASK,GAAG,CAACZ;IAC1C;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CC,GACD,OAAO,MAAMa;IAwBDd,cAA2BC,IAAO,EAAU;QACpD,OAAO;YAAC,IAAI,CAACN,SAAS;YAAEM;SAAK,CAACC,IAAI,CAAC,IAAI,CAACN,WAAW;IACrD;IACUO,aAAaY,SAAiB,EAAU;QAChD,OAAO;YAAC,IAAI,CAACrB,KAAK;YAAEqB;SAAU,CAACb,IAAI,CAAC,IAAI,CAACL,cAAc;IACzD;IACUmB,iBACRf,IAAO,EACPgB,OAAsB,EACd;QACR,MAAMnB,WAAW,IAAI,CAACoB,SAAS,CAACjB,KAAK;QACrC,OAAOH,WAAWR,gBAAgBQ,UAAUmB,WAAW,IAAI,CAAClB,cAAc;IAC5E;IACUoB,gBAAgBJ,SAAiB,EAAEK,YAAoB,EAAU;QACzE,0CAA0C;QAC1C,6DAA6D;QAC7D,OAAO,IAAI,CAAChB,cAAc,CAACW,WAAWK;IACxC;IAEA;;;;;;;;;;;;;;;;;;GAkBC,GACD,AAAOC,OACLpB,IAAO,EACP,GAAGgB,OAAwC,EAClC;QACT,MAAMK,OAAqB,AAAClC,OAAO6B,YAAYA,OAAO,CAAC,EAAE,IAAK,CAAC,GAC7DF,YAAY,IAAI,CAACf,aAAa,CAACC,OAC/BsB,WAAW,IAAI,CAACpB,YAAY,CAACY,YAC7BK,eAAe,IAAI,CAACJ,gBAAgB,CAACf,MAAMqB,OAC3CE,cAAc,IAAI,CAACL,eAAe,CAACI,UAAUH;QAE/C,OAAO,IAAI/B,QAAQ0B,WAAWS,aAAaF;IAC7C;IAEOG,aACLC,cAAsB,EACtBR,SAA+B,EAC/B;QACA,OAAO,IAAIJ,eACT,IAAI,CAACpB,KAAK,EACV;YAAC,IAAI,CAACC,SAAS;YAAE+B;SAAe,CAACxB,IAAI,CAAC,IAAI,CAACN,WAAW,GACrDsB,aAAa,IAAI,CAACA,SAAS,EAC5B,IAAI,CAACtB,WAAW,EAChB,IAAI,CAACC,cAAc,EACnB,IAAI,CAACE,cAAc;IAEvB;IAjFA,YACE,AAAiBL,KAAa,EAC9B,AAAiBC,SAAiB,EAClC,AAAiBuB,SAA8B,EAC/C,AAAiBtB,cAAc,GAAG,EAClC,AAAiBC,iBAAiB,GAAG,EACrC,AAAiBE,iBAAiB,OAAO,CACzC;aANiBL,QAAAA;aACAC,YAAAA;aACAuB,YAAAA;aACAtB,cAAAA;aACAC,iBAAAA;aACAE,iBAAAA;QAEjB,IAAI,CAACsB,MAAM,GAAG,IAAI,CAACA,MAAM,CAACM,IAAI,CAAC,IAAI;QACnC,IAAI,CAACvB,cAAc,GAAGZ,iBAAiB;YACrCE;YACAC;YACAC;YACAC;YACAE;QACF;IACF;AAkEF"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { ErrorPayload } from './types';
18
+ export declare class NsError extends Error {
19
+ readonly code: string;
20
+ payload: ErrorPayload;
21
+ readonly name = "NsError";
22
+ message: string;
23
+ constructor(code: string, message: string, payload: ErrorPayload);
24
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { NsErrorFactory } from "./ns-error-factory.js";
17
+ export class NsError extends Error {
18
+ constructor(code, message, payload){
19
+ super(message), this.code = code, this.payload = payload, this.name = 'NsError';
20
+ this.message = message;
21
+ // Fix For ES5
22
+ // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
23
+ Object.setPrototypeOf(this, NsError.prototype);
24
+ // Maintains proper stack trace for where our error was thrown.
25
+ // Only available on V8.
26
+ if (Error.captureStackTrace) {
27
+ Error.captureStackTrace(this, NsErrorFactory.prototype.create);
28
+ }
29
+ }
30
+ }
31
+
32
+ //# sourceMappingURL=ns-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/errors/src/lib/ns-error.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { NsErrorFactory } from './ns-error-factory'\nimport type { ErrorPayload } from './types'\n\nexport class NsError extends Error {\n override readonly name = 'NsError'\n override message: string\n\n constructor(\n public readonly code: string,\n message: string,\n public payload: ErrorPayload,\n ) {\n super(message)\n this.message = message\n // Fix For ES5\n // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, NsError.prototype)\n\n // Maintains proper stack trace for where our error was thrown.\n // Only available on V8.\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, NsErrorFactory.prototype.create)\n }\n }\n}\n"],"names":["NsErrorFactory","NsError","Error","code","message","payload","name","Object","setPrototypeOf","prototype","captureStackTrace","create"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,cAAc,QAAQ,wBAAoB;AAGnD,OAAO,MAAMC,gBAAgBC;IAI3B,YACE,AAAgBC,IAAY,EAC5BC,OAAe,EACf,AAAOC,OAAqB,CAC5B;QACA,KAAK,CAACD,eAJUD,OAAAA,WAETE,UAAAA,cANSC,OAAO;QASvB,IAAI,CAACF,OAAO,GAAGA;QACf,cAAc;QACd,+IAA+I;QAC/IG,OAAOC,cAAc,CAAC,IAAI,EAAEP,QAAQQ,SAAS;QAE7C,+DAA+D;QAC/D,wBAAwB;QACxB,IAAIP,MAAMQ,iBAAiB,EAAE;YAC3BR,MAAMQ,iBAAiB,CAAC,IAAI,EAAEV,eAAeS,SAAS,CAACE,MAAM;QAC/D;IACF;AACF"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { ErrorPayload } from './types';
18
+ export type ReplaceTemplateOptions = {
19
+ pattern?: RegExp | string;
20
+ };
21
+ export declare const DEFAULT_REPLACER_REGEX: RegExp;
22
+ /**
23
+ * Replaces var placeholders in template string with matching keys in payload
24
+ * @example
25
+ * replaceTemplate("Illegal app name: '{$appName}'", {appName: "Foo App"})
26
+ * @param template - template to replace e.g., "Illegal app name: '{$appName}'"
27
+ * @param payload - dictionary of placeholder keys mapped to dynamic values
28
+ * @param options - override replacement pattern strategy
29
+ */
30
+ export declare function replaceTemplate(template: string, payload?: ErrorPayload, options?: ReplaceTemplateOptions): string;
31
+ export default replaceTemplate;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ export const DEFAULT_REPLACER_REGEX = /\{\$([^}]+)}/g;
17
+ /**
18
+ * Replaces var placeholders in template string with matching keys in payload
19
+ * @example
20
+ * replaceTemplate("Illegal app name: '{$appName}'", {appName: "Foo App"})
21
+ * @param template - template to replace e.g., "Illegal app name: '{$appName}'"
22
+ * @param payload - dictionary of placeholder keys mapped to dynamic values
23
+ * @param options - override replacement pattern strategy
24
+ */ export function replaceTemplate(template, payload, options) {
25
+ const { pattern = DEFAULT_REPLACER_REGEX } = options || {};
26
+ return String(template).replace(pattern, (_, key)=>{
27
+ const value = payload == null ? void 0 : payload[key];
28
+ return value !== null ? String(value) : `<${key}?>`;
29
+ });
30
+ }
31
+ export default replaceTemplate;
32
+
33
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/errors/src/lib/tools.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {ErrorPayload} from './types'\n\n\nexport type ReplaceTemplateOptions = {\n pattern?: RegExp | string\n}\n\nexport const DEFAULT_REPLACER_REGEX = /\\{\\$([^}]+)}/g\n\n/**\n * Replaces var placeholders in template string with matching keys in payload\n * @example\n * replaceTemplate(\"Illegal app name: '{$appName}'\", {appName: \"Foo App\"})\n * @param template - template to replace e.g., \"Illegal app name: '{$appName}'\"\n * @param payload - dictionary of placeholder keys mapped to dynamic values\n * @param options - override replacement pattern strategy\n */\nexport function replaceTemplate(\n template: string,\n payload?: ErrorPayload,\n options?: ReplaceTemplateOptions,\n): string {\n const {pattern = DEFAULT_REPLACER_REGEX} = options || {}\n return String(template).replace(pattern, (_, key) => {\n const value = payload?.[key]\n return value !== null ? String(value) : `<${key}?>`\n })\n}\n\nexport default replaceTemplate\n"],"names":["DEFAULT_REPLACER_REGEX","replaceTemplate","template","payload","options","pattern","String","replace","_","key","value"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GASD,OAAO,MAAMA,yBAAyB,gBAAe;AAErD;;;;;;;CAOC,GACD,OAAO,SAASC,gBACdC,QAAgB,EAChBC,OAAsB,EACtBC,OAAgC;IAEhC,MAAM,EAACC,UAAUL,sBAAsB,EAAC,GAAGI,WAAW,CAAC;IACvD,OAAOE,OAAOJ,UAAUK,OAAO,CAACF,SAAS,CAACG,GAAGC;QAC3C,MAAMC,QAAQP,2BAAAA,OAAS,CAACM,IAAI;QAC5B,OAAOC,UAAU,OAAOJ,OAAOI,SAAS,CAAC,CAAC,EAAED,IAAI,EAAE,CAAC;IACrD;AACF;AAEA,eAAeR,gBAAe"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export type EventFlag = string;
18
+ export type EventMessage = string;
19
+ export type Key = string;
20
+ export type VarSyntax<T extends Key> = `{$${T}}`;
21
+ export type ErrorPayload<K extends keyof any = keyof any, T = unknown> = Partial<Record<K, T>>;
22
+ export type ErrorTagMessages<T extends EventFlag = string> = Record<T, EventMessage>;
23
+ export type ErrorTagPayloads<T extends Key = string> = Record<T, ErrorPayload>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ export { };
17
+
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/errors/src/lib/types.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2021 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type EventFlag = string\nexport type EventMessage = string\nexport type Key = string\nexport type VarSyntax<T extends Key> = `{$${T}}`\nexport type ErrorPayload<K extends keyof any = keyof any, T = unknown> = Partial<Record<K, T>>\n\nexport type ErrorTagMessages<T extends EventFlag = string> = Record<T, EventMessage>\nexport type ErrorTagPayloads<T extends Key = string> = Record<T, ErrorPayload>\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GASD,WAA8E"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * A non-2xx answer from a vendor the platform calls on a customer's behalf
19
+ * — a model provider, a payment processor, a mail relay.
20
+ *
21
+ * `message` is a fixed, customer-safe sentence the caller chose; the
22
+ * vendor's own words describe OUR account with them (a key, a rate limit, a
23
+ * balance) and name the vendor to a white-label org's users, so they go to
24
+ * the log beside `requestId` and never travel in this object.
25
+ */
26
+ export declare class UpstreamServiceError extends Error {
27
+ readonly name: string;
28
+ /** The vendor's HTTP status, or null when the failure had none. */
29
+ readonly status: number | null;
30
+ /**
31
+ * Whether the vendor said "come back later" rather than "this request is
32
+ * wrong": a rate limit or an overload. Everything else — a bad request,
33
+ * an authentication failure, a vendor fault — is not, and a caller must
34
+ * not retry it in a loop.
35
+ */
36
+ readonly retryable: boolean;
37
+ /** The vendor's request id, when it sent one — the log's join key. */
38
+ readonly requestId: string | null;
39
+ constructor(message: string, options: {
40
+ status: number | null;
41
+ retryable: boolean;
42
+ requestId?: string | null;
43
+ });
44
+ }
45
+ export default UpstreamServiceError;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ /**
17
+ * A non-2xx answer from a vendor the platform calls on a customer's behalf
18
+ * — a model provider, a payment processor, a mail relay.
19
+ *
20
+ * `message` is a fixed, customer-safe sentence the caller chose; the
21
+ * vendor's own words describe OUR account with them (a key, a rate limit, a
22
+ * balance) and name the vendor to a white-label org's users, so they go to
23
+ * the log beside `requestId` and never travel in this object.
24
+ */ export class UpstreamServiceError extends Error {
25
+ constructor(message, options){
26
+ var _options_requestId;
27
+ super(message), this.name = 'UpstreamServiceError';
28
+ this.status = options.status;
29
+ this.retryable = options.retryable;
30
+ this.requestId = (_options_requestId = options.requestId) != null ? _options_requestId : null;
31
+ Object.setPrototypeOf(this, new.target.prototype);
32
+ if (Error.captureStackTrace) Error.captureStackTrace(this, new.target);
33
+ }
34
+ }
35
+ export default UpstreamServiceError;
36
+
37
+ //# sourceMappingURL=upstream-service-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/shared/util/errors/src/lib/upstream-service-error.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A non-2xx answer from a vendor the platform calls on a customer's behalf\n * — a model provider, a payment processor, a mail relay.\n *\n * `message` is a fixed, customer-safe sentence the caller chose; the\n * vendor's own words describe OUR account with them (a key, a rate limit, a\n * balance) and name the vendor to a white-label org's users, so they go to\n * the log beside `requestId` and never travel in this object.\n */\nexport class UpstreamServiceError extends Error {\n override readonly name: string = 'UpstreamServiceError'\n /** The vendor's HTTP status, or null when the failure had none. */\n readonly status: number | null\n /**\n * Whether the vendor said \"come back later\" rather than \"this request is\n * wrong\": a rate limit or an overload. Everything else — a bad request,\n * an authentication failure, a vendor fault — is not, and a caller must\n * not retry it in a loop.\n */\n readonly retryable: boolean\n /** The vendor's request id, when it sent one — the log's join key. */\n readonly requestId: string | null\n\n constructor(\n message: string,\n options: { status: number | null; retryable: boolean; requestId?: string | null },\n ) {\n super(message)\n this.status = options.status\n this.retryable = options.retryable\n this.requestId = options.requestId ?? null\n Object.setPrototypeOf(this, new.target.prototype)\n if (Error.captureStackTrace) Error.captureStackTrace(this, new.target)\n }\n}\n\nexport default UpstreamServiceError\n"],"names":["UpstreamServiceError","Error","message","options","name","status","retryable","requestId","Object","setPrototypeOf","prototype","captureStackTrace"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;CAQC,GACD,OAAO,MAAMA,6BAA6BC;IAcxC,YACEC,OAAe,EACfC,OAAiF,CACjF;YAIiBA;QAHjB,KAAK,CAACD,eAjBUE,OAAe;QAkB/B,IAAI,CAACC,MAAM,GAAGF,QAAQE,MAAM;QAC5B,IAAI,CAACC,SAAS,GAAGH,QAAQG,SAAS;QAClC,IAAI,CAACC,SAAS,IAAGJ,qBAAAA,QAAQI,SAAS,YAAjBJ,qBAAqB;QACtCK,OAAOC,cAAc,CAAC,IAAI,EAAE,WAAWC,SAAS;QAChD,IAAIT,MAAMU,iBAAiB,EAAEV,MAAMU,iBAAiB,CAAC,IAAI,EAAE;IAC7D;AACF;AAEA,eAAeX,qBAAoB"}