@nexussdk/contracts 0.0.1 → 0.0.3
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/README.md +32 -0
- package/dist/auth.cjs +1 -4
- package/dist/auth.mjs +0 -3
- package/dist/flags.cjs +1 -4
- package/dist/flags.mjs +0 -3
- package/dist/index.cjs +2 -8
- package/dist/index.mjs +2 -6
- package/dist/rfc7807.cjs +2 -8
- package/dist/rfc7807.mjs +2 -6
- package/dist/tracker.cjs +1 -4
- package/dist/tracker.mjs +0 -3
- package/package.json +29 -1
- package/.turbo/turbo-build.log +0 -52
- package/dist/auth.cjs.map +0 -1
- package/dist/auth.mjs.map +0 -1
- package/dist/flags.cjs.map +0 -1
- package/dist/flags.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/rfc7807.cjs.map +0 -1
- package/dist/rfc7807.mjs.map +0 -1
- package/dist/tracker.cjs.map +0 -1
- package/dist/tracker.mjs.map +0 -1
- package/src/auth.ts +0 -224
- package/src/flags.ts +0 -255
- package/src/index.ts +0 -12
- package/src/rfc7807.ts +0 -76
- package/src/tracker.ts +0 -205
- package/tsconfig.json +0 -8
- package/tsup.config.ts +0 -17
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @nexussdk/contracts
|
|
2
|
+
|
|
3
|
+
Single Source of Truth (SSOT) data contracts and TypeScript interfaces for the **Nexus Platform** ecosystem.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@nexussdk/contracts)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @nexussdk/contracts
|
|
14
|
+
# or
|
|
15
|
+
pnpm add @nexussdk/contracts
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Exports
|
|
21
|
+
|
|
22
|
+
- `@nexussdk/contracts`: Root unified types
|
|
23
|
+
- `@nexussdk/contracts/flags`: Feature flag, evaluation rule, and rollout segment definitions
|
|
24
|
+
- `@nexussdk/contracts/tracker`: Telemetry event, breadcrumb, and exception payload interfaces
|
|
25
|
+
- `@nexussdk/contracts/auth`: Client key and environment metadata definitions
|
|
26
|
+
- `@nexussdk/contracts/rfc7807`: Problem Details standard error structures
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT © [Nexus Platform](https://github.com/Huynhdung295/NexusSDK)
|
package/dist/auth.cjs
CHANGED
package/dist/auth.mjs
CHANGED
package/dist/flags.cjs
CHANGED
package/dist/flags.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/rfc7807.ts
|
|
4
|
-
var NEXUS_ERROR_BASE = "https://nexus.dev/errors";
|
|
5
|
-
|
|
6
|
-
exports.NEXUS_ERROR_BASE = NEXUS_ERROR_BASE;
|
|
7
|
-
//# sourceMappingURL=index.cjs.map
|
|
8
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var t="https://nexus.dev/errors";
|
|
2
|
+
exports.NEXUS_ERROR_BASE=t;
|
package/dist/index.mjs
CHANGED
package/dist/rfc7807.cjs
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/rfc7807.ts
|
|
4
|
-
var NEXUS_ERROR_BASE = "https://nexus.dev/errors";
|
|
5
|
-
|
|
6
|
-
exports.NEXUS_ERROR_BASE = NEXUS_ERROR_BASE;
|
|
7
|
-
//# sourceMappingURL=rfc7807.cjs.map
|
|
8
|
-
//# sourceMappingURL=rfc7807.cjs.map
|
|
1
|
+
'use strict';var t="https://nexus.dev/errors";
|
|
2
|
+
exports.NEXUS_ERROR_BASE=t;
|
package/dist/rfc7807.mjs
CHANGED
package/dist/tracker.cjs
CHANGED
package/dist/tracker.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexussdk/contracts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"description": "Single Source of Truth (SSOT) data contracts for the Nexus Platform ecosystem",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Nexus",
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Hồ Huỳnh Dũng",
|
|
14
|
+
"email": "hohuynhdung@gmail.com",
|
|
15
|
+
"url": "https://github.com/Huynhdung295"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/Huynhdung295/NexusSDK.git",
|
|
21
|
+
"directory": "packages/contracts"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/Huynhdung295/NexusSDK#readme",
|
|
24
|
+
"keywords": [
|
|
25
|
+
"nexus",
|
|
26
|
+
"nexussdk",
|
|
27
|
+
"contracts",
|
|
28
|
+
"typescript",
|
|
29
|
+
"feature-flags",
|
|
30
|
+
"telemetry",
|
|
31
|
+
"rfc7807"
|
|
32
|
+
],
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
9
37
|
"main": "./dist/index.cjs",
|
|
10
38
|
"module": "./dist/index.mjs",
|
|
11
39
|
"types": "./dist/index.d.ts",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @nexussdk/contracts@0.0.1 build /home/runner/work/NexusSDK/NexusSDK/packages/contracts
|
|
3
|
-
> tsup
|
|
4
|
-
|
|
5
|
-
[34mCLI[39m Building entry: src/auth.ts, src/flags.ts, src/index.ts, src/rfc7807.ts, src/tracker.ts
|
|
6
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.5.1
|
|
8
|
-
[34mCLI[39m Using tsup config: /home/runner/work/NexusSDK/NexusSDK/packages/contracts/tsup.config.ts
|
|
9
|
-
[34mCLI[39m Target: es2022
|
|
10
|
-
[34mCLI[39m Cleaning output folder
|
|
11
|
-
[34mESM[39m Build start
|
|
12
|
-
[34mCJS[39m Build start
|
|
13
|
-
Generated an empty chunk: "auth".
|
|
14
|
-
Generated an empty chunk: "flags".
|
|
15
|
-
Generated an empty chunk: "tracker".
|
|
16
|
-
Generated an empty chunk: "auth".
|
|
17
|
-
Generated an empty chunk: "flags".
|
|
18
|
-
Generated an empty chunk: "tracker".
|
|
19
|
-
[32mCJS[39m [1mdist/auth.cjs [22m[32m82.00 B[39m
|
|
20
|
-
[32mCJS[39m [1mdist/flags.cjs [22m[32m84.00 B[39m
|
|
21
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m199.00 B[39m
|
|
22
|
-
[32mCJS[39m [1mdist/rfc7807.cjs [22m[32m203.00 B[39m
|
|
23
|
-
[32mCJS[39m [1mdist/tracker.cjs [22m[32m88.00 B[39m
|
|
24
|
-
[32mCJS[39m [1mdist/auth.cjs.map [22m[32m69.00 B[39m
|
|
25
|
-
[32mCJS[39m [1mdist/flags.cjs.map [22m[32m70.00 B[39m
|
|
26
|
-
[32mCJS[39m [1mdist/index.cjs.map [22m[32m2.58 KB[39m
|
|
27
|
-
[32mCJS[39m [1mdist/rfc7807.cjs.map [22m[32m2.58 KB[39m
|
|
28
|
-
[32mCJS[39m [1mdist/tracker.cjs.map [22m[32m72.00 B[39m
|
|
29
|
-
[32mCJS[39m ⚡️ Build success in 111ms
|
|
30
|
-
[32mESM[39m [1mdist/auth.mjs [22m[32m68.00 B[39m
|
|
31
|
-
[32mESM[39m [1mdist/flags.mjs [22m[32m70.00 B[39m
|
|
32
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m168.00 B[39m
|
|
33
|
-
[32mESM[39m [1mdist/rfc7807.mjs [22m[32m172.00 B[39m
|
|
34
|
-
[32mESM[39m [1mdist/tracker.mjs [22m[32m74.00 B[39m
|
|
35
|
-
[32mESM[39m [1mdist/auth.mjs.map [22m[32m69.00 B[39m
|
|
36
|
-
[32mESM[39m [1mdist/flags.mjs.map [22m[32m70.00 B[39m
|
|
37
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[32m2.57 KB[39m
|
|
38
|
-
[32mESM[39m [1mdist/rfc7807.mjs.map [22m[32m2.58 KB[39m
|
|
39
|
-
[32mESM[39m [1mdist/tracker.mjs.map [22m[32m72.00 B[39m
|
|
40
|
-
[32mESM[39m ⚡️ Build success in 113ms
|
|
41
|
-
[34mDTS[39m Build start
|
|
42
|
-
[32mDTS[39m ⚡️ Build success in 1002ms
|
|
43
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m607.00 B[39m
|
|
44
|
-
[32mDTS[39m [1mdist/rfc7807.d.mts [22m[32m2.49 KB[39m
|
|
45
|
-
[32mDTS[39m [1mdist/tracker.d.mts [22m[32m6.48 KB[39m
|
|
46
|
-
[32mDTS[39m [1mdist/flags.d.mts [22m[32m7.17 KB[39m
|
|
47
|
-
[32mDTS[39m [1mdist/auth.d.mts [22m[32m6.21 KB[39m
|
|
48
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m603.00 B[39m
|
|
49
|
-
[32mDTS[39m [1mdist/rfc7807.d.ts [22m[32m2.49 KB[39m
|
|
50
|
-
[32mDTS[39m [1mdist/tracker.d.ts [22m[32m6.48 KB[39m
|
|
51
|
-
[32mDTS[39m [1mdist/flags.d.ts [22m[32m7.17 KB[39m
|
|
52
|
-
[32mDTS[39m [1mdist/auth.d.ts [22m[32m6.21 KB[39m
|
package/dist/auth.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"auth.cjs"}
|
package/dist/auth.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"auth.mjs"}
|
package/dist/flags.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"flags.cjs"}
|
package/dist/flags.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"flags.mjs"}
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rfc7807.ts"],"names":[],"mappings":";;;AA2EO,IAAM,gBAAA,GAAmB","file":"index.cjs","sourcesContent":["/**\n * @fileoverview Problem Details for HTTP APIs Specification (RFC 7807).\n * Standardized error format across Go-Gin and NestJS error responses.\n * @see {@link https://www.rfc-editor.org/rfc/rfc7807}\n * @module @nexus/contracts/rfc7807\n */\n\n/**\n * RFC 7807 Compliant Error Schema.\n * Ensures consistent machine-readable error diagnostics across all Nexus services.\n *\n * @example\n * const problem: ProblemDetails = {\n * type: 'https://nexus.dev/errors/quota-exceeded',\n * title: 'Monthly Quota Exceeded',\n * status: 429,\n * detail: \"API Key 'pk_live_...' has exhausted its limit of 50,000 monthly events.\",\n * instance: '/api/v1/telemetry/errors',\n * timestamp: '2024-06-01T12:00:00Z',\n * };\n */\nexport interface ProblemDetails {\n /**\n * URI reference identifying the problem type.\n * Should be a stable, documented URI that clients can bookmark.\n * @example 'https://nexus.dev/errors/rate-limit-exceeded'\n */\n type: string;\n /**\n * Short, human-readable summary of problem type.\n * Must be invariant across occurrences of the same problem type.\n * @example 'Too Many Requests'\n */\n title: string;\n /**\n * HTTP status code generated by origin server.\n * @example 429\n */\n status: number;\n /**\n * Human-readable explanation specific to this occurrence of the problem.\n * May differ across occurrences of the same problem type.\n * @example \"API Key 'pk_live_a1b2...' has exhausted its monthly event limit.\"\n */\n detail: string;\n /**\n * URI reference identifying specific occurrence of problem.\n * Typically the request path that triggered the error.\n * @example '/api/v1/telemetry/errors'\n */\n instance?: string;\n /**\n * Additional diagnostic error parameters for validation failures.\n * @example [{ name: 'email', reason: 'Must be a valid email address.' }]\n */\n invalidParams?: Array<{\n /** Field name that caused the validation error. */\n name: string;\n /** Human-readable reason for the validation failure. */\n reason: string;\n }>;\n /**\n * ISO 8601 timestamp when error was produced.\n * @example '2024-06-01T12:00:00.000Z'\n */\n timestamp?: string;\n}\n\n/**\n * Standard Nexus error type URI prefix.\n * All RFC 7807 type values should use this base to ensure namespacing consistency.\n *\n * @example\n * const type = `${NEXUS_ERROR_BASE}/rate-limit-exceeded`;\n */\nexport const NEXUS_ERROR_BASE = 'https://nexus.dev/errors' as const;\n"]}
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rfc7807.ts"],"names":[],"mappings":";AA2EO,IAAM,gBAAA,GAAmB","file":"index.mjs","sourcesContent":["/**\n * @fileoverview Problem Details for HTTP APIs Specification (RFC 7807).\n * Standardized error format across Go-Gin and NestJS error responses.\n * @see {@link https://www.rfc-editor.org/rfc/rfc7807}\n * @module @nexus/contracts/rfc7807\n */\n\n/**\n * RFC 7807 Compliant Error Schema.\n * Ensures consistent machine-readable error diagnostics across all Nexus services.\n *\n * @example\n * const problem: ProblemDetails = {\n * type: 'https://nexus.dev/errors/quota-exceeded',\n * title: 'Monthly Quota Exceeded',\n * status: 429,\n * detail: \"API Key 'pk_live_...' has exhausted its limit of 50,000 monthly events.\",\n * instance: '/api/v1/telemetry/errors',\n * timestamp: '2024-06-01T12:00:00Z',\n * };\n */\nexport interface ProblemDetails {\n /**\n * URI reference identifying the problem type.\n * Should be a stable, documented URI that clients can bookmark.\n * @example 'https://nexus.dev/errors/rate-limit-exceeded'\n */\n type: string;\n /**\n * Short, human-readable summary of problem type.\n * Must be invariant across occurrences of the same problem type.\n * @example 'Too Many Requests'\n */\n title: string;\n /**\n * HTTP status code generated by origin server.\n * @example 429\n */\n status: number;\n /**\n * Human-readable explanation specific to this occurrence of the problem.\n * May differ across occurrences of the same problem type.\n * @example \"API Key 'pk_live_a1b2...' has exhausted its monthly event limit.\"\n */\n detail: string;\n /**\n * URI reference identifying specific occurrence of problem.\n * Typically the request path that triggered the error.\n * @example '/api/v1/telemetry/errors'\n */\n instance?: string;\n /**\n * Additional diagnostic error parameters for validation failures.\n * @example [{ name: 'email', reason: 'Must be a valid email address.' }]\n */\n invalidParams?: Array<{\n /** Field name that caused the validation error. */\n name: string;\n /** Human-readable reason for the validation failure. */\n reason: string;\n }>;\n /**\n * ISO 8601 timestamp when error was produced.\n * @example '2024-06-01T12:00:00.000Z'\n */\n timestamp?: string;\n}\n\n/**\n * Standard Nexus error type URI prefix.\n * All RFC 7807 type values should use this base to ensure namespacing consistency.\n *\n * @example\n * const type = `${NEXUS_ERROR_BASE}/rate-limit-exceeded`;\n */\nexport const NEXUS_ERROR_BASE = 'https://nexus.dev/errors' as const;\n"]}
|
package/dist/rfc7807.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rfc7807.ts"],"names":[],"mappings":";;;AA2EO,IAAM,gBAAA,GAAmB","file":"rfc7807.cjs","sourcesContent":["/**\n * @fileoverview Problem Details for HTTP APIs Specification (RFC 7807).\n * Standardized error format across Go-Gin and NestJS error responses.\n * @see {@link https://www.rfc-editor.org/rfc/rfc7807}\n * @module @nexus/contracts/rfc7807\n */\n\n/**\n * RFC 7807 Compliant Error Schema.\n * Ensures consistent machine-readable error diagnostics across all Nexus services.\n *\n * @example\n * const problem: ProblemDetails = {\n * type: 'https://nexus.dev/errors/quota-exceeded',\n * title: 'Monthly Quota Exceeded',\n * status: 429,\n * detail: \"API Key 'pk_live_...' has exhausted its limit of 50,000 monthly events.\",\n * instance: '/api/v1/telemetry/errors',\n * timestamp: '2024-06-01T12:00:00Z',\n * };\n */\nexport interface ProblemDetails {\n /**\n * URI reference identifying the problem type.\n * Should be a stable, documented URI that clients can bookmark.\n * @example 'https://nexus.dev/errors/rate-limit-exceeded'\n */\n type: string;\n /**\n * Short, human-readable summary of problem type.\n * Must be invariant across occurrences of the same problem type.\n * @example 'Too Many Requests'\n */\n title: string;\n /**\n * HTTP status code generated by origin server.\n * @example 429\n */\n status: number;\n /**\n * Human-readable explanation specific to this occurrence of the problem.\n * May differ across occurrences of the same problem type.\n * @example \"API Key 'pk_live_a1b2...' has exhausted its monthly event limit.\"\n */\n detail: string;\n /**\n * URI reference identifying specific occurrence of problem.\n * Typically the request path that triggered the error.\n * @example '/api/v1/telemetry/errors'\n */\n instance?: string;\n /**\n * Additional diagnostic error parameters for validation failures.\n * @example [{ name: 'email', reason: 'Must be a valid email address.' }]\n */\n invalidParams?: Array<{\n /** Field name that caused the validation error. */\n name: string;\n /** Human-readable reason for the validation failure. */\n reason: string;\n }>;\n /**\n * ISO 8601 timestamp when error was produced.\n * @example '2024-06-01T12:00:00.000Z'\n */\n timestamp?: string;\n}\n\n/**\n * Standard Nexus error type URI prefix.\n * All RFC 7807 type values should use this base to ensure namespacing consistency.\n *\n * @example\n * const type = `${NEXUS_ERROR_BASE}/rate-limit-exceeded`;\n */\nexport const NEXUS_ERROR_BASE = 'https://nexus.dev/errors' as const;\n"]}
|
package/dist/rfc7807.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rfc7807.ts"],"names":[],"mappings":";AA2EO,IAAM,gBAAA,GAAmB","file":"rfc7807.mjs","sourcesContent":["/**\n * @fileoverview Problem Details for HTTP APIs Specification (RFC 7807).\n * Standardized error format across Go-Gin and NestJS error responses.\n * @see {@link https://www.rfc-editor.org/rfc/rfc7807}\n * @module @nexus/contracts/rfc7807\n */\n\n/**\n * RFC 7807 Compliant Error Schema.\n * Ensures consistent machine-readable error diagnostics across all Nexus services.\n *\n * @example\n * const problem: ProblemDetails = {\n * type: 'https://nexus.dev/errors/quota-exceeded',\n * title: 'Monthly Quota Exceeded',\n * status: 429,\n * detail: \"API Key 'pk_live_...' has exhausted its limit of 50,000 monthly events.\",\n * instance: '/api/v1/telemetry/errors',\n * timestamp: '2024-06-01T12:00:00Z',\n * };\n */\nexport interface ProblemDetails {\n /**\n * URI reference identifying the problem type.\n * Should be a stable, documented URI that clients can bookmark.\n * @example 'https://nexus.dev/errors/rate-limit-exceeded'\n */\n type: string;\n /**\n * Short, human-readable summary of problem type.\n * Must be invariant across occurrences of the same problem type.\n * @example 'Too Many Requests'\n */\n title: string;\n /**\n * HTTP status code generated by origin server.\n * @example 429\n */\n status: number;\n /**\n * Human-readable explanation specific to this occurrence of the problem.\n * May differ across occurrences of the same problem type.\n * @example \"API Key 'pk_live_a1b2...' has exhausted its monthly event limit.\"\n */\n detail: string;\n /**\n * URI reference identifying specific occurrence of problem.\n * Typically the request path that triggered the error.\n * @example '/api/v1/telemetry/errors'\n */\n instance?: string;\n /**\n * Additional diagnostic error parameters for validation failures.\n * @example [{ name: 'email', reason: 'Must be a valid email address.' }]\n */\n invalidParams?: Array<{\n /** Field name that caused the validation error. */\n name: string;\n /** Human-readable reason for the validation failure. */\n reason: string;\n }>;\n /**\n * ISO 8601 timestamp when error was produced.\n * @example '2024-06-01T12:00:00.000Z'\n */\n timestamp?: string;\n}\n\n/**\n * Standard Nexus error type URI prefix.\n * All RFC 7807 type values should use this base to ensure namespacing consistency.\n *\n * @example\n * const type = `${NEXUS_ERROR_BASE}/rate-limit-exceeded`;\n */\nexport const NEXUS_ERROR_BASE = 'https://nexus.dev/errors' as const;\n"]}
|
package/dist/tracker.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"tracker.cjs"}
|
package/dist/tracker.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"tracker.mjs"}
|
package/src/auth.ts
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Authentication, Organization, Project, and API Key contracts.
|
|
3
|
-
* Governs multi-tenant B2B2C security and quota boundaries.
|
|
4
|
-
* @module @nexus/contracts/auth
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Subscription plan tiers determining rate limits and feature entitlements.
|
|
9
|
-
* @example
|
|
10
|
-
* const tier: PlanTier = 'PRO';
|
|
11
|
-
*/
|
|
12
|
-
export type PlanTier = 'FREE' | 'PRO' | 'ENTERPRISE';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Operational status of a tenant account.
|
|
16
|
-
* @example
|
|
17
|
-
* const status: AccountStatus = 'ACTIVE';
|
|
18
|
-
*/
|
|
19
|
-
export type AccountStatus = 'ACTIVE' | 'SUSPENDED' | 'CANCELLED';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Deployment environments for project isolation.
|
|
23
|
-
* @example
|
|
24
|
-
* const env: Environment = 'production';
|
|
25
|
-
*/
|
|
26
|
-
export type Environment = 'development' | 'staging' | 'production';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Cryptographic API Key permission scope.
|
|
30
|
-
* - `PUBLIC`: Embedded in client browsers. Permitted only for flag evaluation,
|
|
31
|
-
* SSE subscriptions, and error ingestion.
|
|
32
|
-
* - `SECRET`: Secure server-side only. Full administrative CRUD operations.
|
|
33
|
-
* @example
|
|
34
|
-
* const keyType: ApiKeyType = 'PUBLIC';
|
|
35
|
-
*/
|
|
36
|
-
export type ApiKeyType = 'PUBLIC' | 'SECRET';
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Represents a developer or organization account (Tenant).
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* const account: Account = {
|
|
43
|
-
* id: 'uuid-v4',
|
|
44
|
-
* name: 'Acme Corp',
|
|
45
|
-
* email: 'admin@acme.com',
|
|
46
|
-
* planTier: 'PRO',
|
|
47
|
-
* status: 'ACTIVE',
|
|
48
|
-
* createdAt: '2024-01-01T00:00:00Z',
|
|
49
|
-
* updatedAt: '2024-06-01T00:00:00Z',
|
|
50
|
-
* };
|
|
51
|
-
*/
|
|
52
|
-
export interface Account {
|
|
53
|
-
/** Unique UUID v4 identifier. */
|
|
54
|
-
id: string;
|
|
55
|
-
/** Organization or developer display name. */
|
|
56
|
-
name: string;
|
|
57
|
-
/** Primary contact and authentication email. */
|
|
58
|
-
email: string;
|
|
59
|
-
/** Current billing entitlement tier. */
|
|
60
|
-
planTier: PlanTier;
|
|
61
|
-
/** Current operational state. */
|
|
62
|
-
status: AccountStatus;
|
|
63
|
-
/** Arbitrary organizational metadata. */
|
|
64
|
-
metadata?: Record<string, unknown>;
|
|
65
|
-
/** Timestamp when account was created. */
|
|
66
|
-
createdAt: string;
|
|
67
|
-
/** Timestamp when account was last modified. */
|
|
68
|
-
updatedAt: string;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Represents an isolated application owned by an Account.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* const project: Project = {
|
|
76
|
-
* id: 'uuid-v4',
|
|
77
|
-
* accountId: 'account-uuid-v4',
|
|
78
|
-
* name: 'My App',
|
|
79
|
-
* slug: 'my-app',
|
|
80
|
-
* createdAt: '2024-01-01T00:00:00Z',
|
|
81
|
-
* updatedAt: '2024-06-01T00:00:00Z',
|
|
82
|
-
* };
|
|
83
|
-
*/
|
|
84
|
-
export interface Project {
|
|
85
|
-
/** Unique UUID v4 identifier. */
|
|
86
|
-
id: string;
|
|
87
|
-
/** Owning Account UUID v4 identifier. */
|
|
88
|
-
accountId: string;
|
|
89
|
-
/** Human-readable project name. */
|
|
90
|
-
name: string;
|
|
91
|
-
/** URL-friendly unique slug under the parent account. */
|
|
92
|
-
slug: string;
|
|
93
|
-
/** Project description. */
|
|
94
|
-
description?: string;
|
|
95
|
-
/** Timestamp of project creation. */
|
|
96
|
-
createdAt: string;
|
|
97
|
-
/** Timestamp of last modification. */
|
|
98
|
-
updatedAt: string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Public or Secret API Key metadata used by Go-Gin and NestJS guards.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* const apiKey: ApiKey = {
|
|
106
|
-
* id: 'uuid-v4',
|
|
107
|
-
* projectId: 'project-uuid-v4',
|
|
108
|
-
* environment: 'production',
|
|
109
|
-
* keyType: 'PUBLIC',
|
|
110
|
-
* keyPrefix: 'pk_live_a1b2',
|
|
111
|
-
* keyHash: 'sha256hexstring...',
|
|
112
|
-
* allowedDomains: ['https://mybrand.com'],
|
|
113
|
-
* rateLimitPerMin: 1000,
|
|
114
|
-
* monthlyEventsLimit: 100000,
|
|
115
|
-
* currentMonthUsage: 4250,
|
|
116
|
-
* usageResetAt: '2024-07-01T00:00:00Z',
|
|
117
|
-
* isActive: true,
|
|
118
|
-
* createdAt: '2024-01-01T00:00:00Z',
|
|
119
|
-
* };
|
|
120
|
-
*/
|
|
121
|
-
export interface ApiKey {
|
|
122
|
-
/** Unique UUID v4 identifier. */
|
|
123
|
-
id: string;
|
|
124
|
-
/** Parent Project identifier. */
|
|
125
|
-
projectId: string;
|
|
126
|
-
/** Target deployment environment. */
|
|
127
|
-
environment: Environment;
|
|
128
|
-
/** Key capability level. */
|
|
129
|
-
keyType: ApiKeyType;
|
|
130
|
-
/** Public preview prefix (e.g. "pk_live_abcd1234"). Raw secret is never persisted. */
|
|
131
|
-
keyPrefix: string;
|
|
132
|
-
/** SHA-256 hash string (64 chars) matching stored database records. */
|
|
133
|
-
keyHash: string;
|
|
134
|
-
/** Whitelisted Origin domains for browser CORS security (e.g. ["https://mybrand.com"]). */
|
|
135
|
-
allowedDomains: string[];
|
|
136
|
-
/** Maximum allowed HTTP requests per minute. */
|
|
137
|
-
rateLimitPerMin: number;
|
|
138
|
-
/** Hard cap for error and event ingestion per calendar month. */
|
|
139
|
-
monthlyEventsLimit: number;
|
|
140
|
-
/** Current count of events processed in the active billing window. */
|
|
141
|
-
currentMonthUsage: number;
|
|
142
|
-
/** Timestamp when the current billing usage cycle resets. */
|
|
143
|
-
usageResetAt: string;
|
|
144
|
-
/** Flag toggle allowing immediate key revocation. */
|
|
145
|
-
isActive: boolean;
|
|
146
|
-
/** Timestamp when the key was last used in any API request. */
|
|
147
|
-
lastUsedAt?: string;
|
|
148
|
-
/** Creation timestamp. */
|
|
149
|
-
createdAt: string;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Payload returned to the developer upon key generation.
|
|
154
|
-
* This is the ONLY time the raw token is made visible.
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* const response: GeneratedApiKeyResponse = {
|
|
158
|
-
* apiKey: { ... },
|
|
159
|
-
* rawKey: 'pk_live_a1b2c3d4e5f6...',
|
|
160
|
-
* };
|
|
161
|
-
*/
|
|
162
|
-
export interface GeneratedApiKeyResponse {
|
|
163
|
-
/** Public or Secret key metadata entity. */
|
|
164
|
-
apiKey: ApiKey;
|
|
165
|
-
/**
|
|
166
|
-
* Plaintext unhashed API key string (e.g., 'pk_live_a1b2c3...').
|
|
167
|
-
* Must be securely copied by developer; cannot be recovered after this response.
|
|
168
|
-
*/
|
|
169
|
-
rawKey: string;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* DTO for account registration requests.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* const dto: RegisterAccountDto = {
|
|
177
|
-
* name: 'Acme Corp',
|
|
178
|
-
* email: 'admin@acme.com',
|
|
179
|
-
* password: 'S3cur3P@ssw0rd!',
|
|
180
|
-
* };
|
|
181
|
-
*/
|
|
182
|
-
export interface RegisterAccountDto {
|
|
183
|
-
/** Organization display name. */
|
|
184
|
-
name: string;
|
|
185
|
-
/** Primary contact email. */
|
|
186
|
-
email: string;
|
|
187
|
-
/** Plaintext password (hashed server-side with bcrypt). */
|
|
188
|
-
password: string;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* DTO for login requests.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* const dto: LoginDto = {
|
|
196
|
-
* email: 'admin@acme.com',
|
|
197
|
-
* password: 'S3cur3P@ssw0rd!',
|
|
198
|
-
* };
|
|
199
|
-
*/
|
|
200
|
-
export interface LoginDto {
|
|
201
|
-
/** Registered email address. */
|
|
202
|
-
email: string;
|
|
203
|
-
/** Plaintext password to verify against stored bcrypt hash. */
|
|
204
|
-
password: string;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Session payload embedded in JWT and HttpOnly cookies.
|
|
209
|
-
*
|
|
210
|
-
* @example
|
|
211
|
-
* const session: SessionPayload = {
|
|
212
|
-
* accountId: 'uuid-v4',
|
|
213
|
-
* email: 'admin@acme.com',
|
|
214
|
-
* planTier: 'PRO',
|
|
215
|
-
* };
|
|
216
|
-
*/
|
|
217
|
-
export interface SessionPayload {
|
|
218
|
-
/** Authenticated account's UUID. */
|
|
219
|
-
accountId: string;
|
|
220
|
-
/** Authenticated account's email. */
|
|
221
|
-
email: string;
|
|
222
|
-
/** Plan tier for feature entitlement checks. */
|
|
223
|
-
planTier: PlanTier;
|
|
224
|
-
}
|
package/src/flags.ts
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Feature Flagging, Dynamic Configuration, and ABAC Targeting contracts.
|
|
3
|
-
* @module @nexus/contracts/flags
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Environment } from './auth.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Attribute evaluation operators for Attribute-Based Access Control (ABAC).
|
|
10
|
-
* Used in {@link TargetingRule} to compare user context values against flag targets.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const op: RuleOperator = 'IN';
|
|
14
|
-
*/
|
|
15
|
-
export type RuleOperator =
|
|
16
|
-
| 'EQUALS'
|
|
17
|
-
| 'NOT_EQUALS'
|
|
18
|
-
| 'CONTAINS'
|
|
19
|
-
| 'NOT_CONTAINS'
|
|
20
|
-
| 'IN'
|
|
21
|
-
| 'NOT_IN'
|
|
22
|
-
| 'STARTS_WITH'
|
|
23
|
-
| 'ENDS_WITH'
|
|
24
|
-
| 'GREATER_THAN'
|
|
25
|
-
| 'LESS_THAN'
|
|
26
|
-
| 'SEMVER_GTE'
|
|
27
|
-
| 'SEMVER_LTE';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Atomic rule evaluating a single user attribute against target values.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* const rule: TargetingRule = {
|
|
34
|
-
* attribute: 'country',
|
|
35
|
-
* operator: 'IN',
|
|
36
|
-
* values: ['VN', 'SG', 'TH'],
|
|
37
|
-
* };
|
|
38
|
-
*/
|
|
39
|
-
export interface TargetingRule {
|
|
40
|
-
/** Attribute path in UserContext (e.g. "country", "tier", "appVersion"). */
|
|
41
|
-
attribute: string;
|
|
42
|
-
/** Logical operator applied to the attribute. */
|
|
43
|
-
operator: RuleOperator;
|
|
44
|
-
/** Comparison targets (strings, numbers, or arrays). */
|
|
45
|
-
values: Array<string | number | boolean>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Primitive types permissible inside dynamic configuration variants.
|
|
50
|
-
*/
|
|
51
|
-
export type VariantValue = string | number | boolean | Record<string, unknown> | unknown[];
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Remote Configuration variants dictionary.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* const variants: FlagVariants = {
|
|
58
|
-
* button_color: '#FF0055',
|
|
59
|
-
* max_items: 25,
|
|
60
|
-
* theme: 'dark',
|
|
61
|
-
* };
|
|
62
|
-
*/
|
|
63
|
-
export type FlagVariants = Record<string, VariantValue>;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Represents a Feature Flag entity stored in the platform.
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* const flag: FeatureFlag = {
|
|
70
|
-
* id: 'uuid-v4',
|
|
71
|
-
* projectId: 'project-uuid',
|
|
72
|
-
* environment: 'production',
|
|
73
|
-
* key: 'checkout_v2',
|
|
74
|
-
* name: 'Checkout Redesign V2',
|
|
75
|
-
* isEnabled: true,
|
|
76
|
-
* rolloutPercentage: 50,
|
|
77
|
-
* targetingRules: [],
|
|
78
|
-
* variants: { show_express: true },
|
|
79
|
-
* version: 3,
|
|
80
|
-
* createdAt: '2024-01-01T00:00:00Z',
|
|
81
|
-
* updatedAt: '2024-06-01T00:00:00Z',
|
|
82
|
-
* };
|
|
83
|
-
*/
|
|
84
|
-
export interface FeatureFlag {
|
|
85
|
-
/** Unique UUID v4 identifier. */
|
|
86
|
-
id: string;
|
|
87
|
-
/** Owning Project UUID v4 identifier. */
|
|
88
|
-
projectId: string;
|
|
89
|
-
/** Deployment environment. */
|
|
90
|
-
environment: Environment;
|
|
91
|
-
/** Unique programmatic identifier (e.g. "checkout_v2"). */
|
|
92
|
-
key: string;
|
|
93
|
-
/** Human-readable flag name. */
|
|
94
|
-
name: string;
|
|
95
|
-
/** Optional purpose explanation. */
|
|
96
|
-
description?: string;
|
|
97
|
-
/** Master kill-switch. When false, flag immediately resolves to fallback/false. */
|
|
98
|
-
isEnabled: boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Percentage rollout integer (0 to 100).
|
|
101
|
-
* Computed deterministically via MurmurHash3(userId + flagKey).
|
|
102
|
-
*/
|
|
103
|
-
rolloutPercentage: number;
|
|
104
|
-
/** Ordered list of targeting rules. Must satisfy all rules for flag to apply. */
|
|
105
|
-
targetingRules: TargetingRule[];
|
|
106
|
-
/** Remote dynamic configuration key-value pairs attached to this flag. */
|
|
107
|
-
variants: FlagVariants;
|
|
108
|
-
/** Monotonically increasing schema version for cache invalidation. */
|
|
109
|
-
version: number;
|
|
110
|
-
/** Creation timestamp. */
|
|
111
|
-
createdAt: string;
|
|
112
|
-
/** Last modification timestamp. */
|
|
113
|
-
updatedAt: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* End-user contextual data supplied by Client SDK for rule evaluation.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* const user: UserContext = {
|
|
121
|
-
* id: 'usr_12345',
|
|
122
|
-
* email: 'john@example.com',
|
|
123
|
-
* country: 'VN',
|
|
124
|
-
* appVersion: '2.4.1',
|
|
125
|
-
* custom: { tier: 'premium', vipMember: true },
|
|
126
|
-
* };
|
|
127
|
-
*/
|
|
128
|
-
export interface UserContext {
|
|
129
|
-
/**
|
|
130
|
-
* Unique user identifier (e.g. "usr_12345").
|
|
131
|
-
* Crucial for consistent percentage rollout bucketing.
|
|
132
|
-
* If omitted, SDK must fallback to anonymous persistent device UUID.
|
|
133
|
-
*/
|
|
134
|
-
id?: string;
|
|
135
|
-
/** User email (commonly used for beta targeting). */
|
|
136
|
-
email?: string;
|
|
137
|
-
/** Two-letter ISO country code (e.g. "VN", "US"). */
|
|
138
|
-
country?: string;
|
|
139
|
-
/** Client application version (e.g. "2.4.1") for semver targeting. */
|
|
140
|
-
appVersion?: string;
|
|
141
|
-
/** Arbitrary custom attributes for ABAC rules. */
|
|
142
|
-
custom?: Record<string, string | number | boolean>;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Evaluation output generated for a single flag.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* const result: FlagEvaluationResult = {
|
|
150
|
-
* key: 'checkout_v2',
|
|
151
|
-
* enabled: true,
|
|
152
|
-
* variants: { show_express: true },
|
|
153
|
-
* reason: 'ROLLOUT_MATCH',
|
|
154
|
-
* version: 3,
|
|
155
|
-
* };
|
|
156
|
-
*/
|
|
157
|
-
export interface FlagEvaluationResult {
|
|
158
|
-
/** Flag unique key. */
|
|
159
|
-
key: string;
|
|
160
|
-
/** Final boolean active status. */
|
|
161
|
-
enabled: boolean;
|
|
162
|
-
/** Selected dynamic configuration variants (empty if disabled). */
|
|
163
|
-
variants: FlagVariants;
|
|
164
|
-
/** Explanation string of evaluation outcome. */
|
|
165
|
-
reason: 'TARGETING_MATCH' | 'ROLLOUT_MATCH' | 'DEFAULT_ENABLED' | 'KILL_SWITCH' | 'FALLBACK';
|
|
166
|
-
/** Schema version of the flag when evaluated. */
|
|
167
|
-
version: number;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Map of multiple evaluated flags returned in single batch request.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* const batch: BatchFlagEvaluation = {
|
|
175
|
-
* checkout_v2: { key: 'checkout_v2', enabled: true, variants: {}, reason: 'ROLLOUT_MATCH', version: 1 },
|
|
176
|
-
* dark_mode: { key: 'dark_mode', enabled: false, variants: {}, reason: 'KILL_SWITCH', version: 2 },
|
|
177
|
-
* };
|
|
178
|
-
*/
|
|
179
|
-
export type BatchFlagEvaluation = Record<string, FlagEvaluationResult>;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Real-time SSE payload pushed from Go-Gin to Client SDKs when a flag is updated.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* const event: FlagStreamEvent = {
|
|
186
|
-
* type: 'FLAG_UPDATE',
|
|
187
|
-
* key: 'checkout_v2',
|
|
188
|
-
* data: { key: 'checkout_v2', enabled: true, variants: {}, reason: 'DEFAULT_ENABLED', version: 4 },
|
|
189
|
-
* timestamp: 1704067200000,
|
|
190
|
-
* };
|
|
191
|
-
*/
|
|
192
|
-
export interface FlagStreamEvent {
|
|
193
|
-
/** Event classification. */
|
|
194
|
-
type: 'FLAG_UPDATE' | 'FLAG_DELETE' | 'HEARTBEAT';
|
|
195
|
-
/** Flag key modified. */
|
|
196
|
-
key: string;
|
|
197
|
-
/** Fresh evaluation payload or null on deletion. */
|
|
198
|
-
data?: FlagEvaluationResult;
|
|
199
|
-
/** Server timestamp of dispatch in milliseconds epoch. */
|
|
200
|
-
timestamp: number;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* DTO for creating a new feature flag.
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* const dto: CreateFlagDto = {
|
|
208
|
-
* key: 'new_checkout',
|
|
209
|
-
* name: 'New Checkout',
|
|
210
|
-
* environment: 'development',
|
|
211
|
-
* rolloutPercentage: 0,
|
|
212
|
-
* variants: {},
|
|
213
|
-
* targetingRules: [],
|
|
214
|
-
* };
|
|
215
|
-
*/
|
|
216
|
-
export interface CreateFlagDto {
|
|
217
|
-
/** Unique programmatic identifier. */
|
|
218
|
-
key: string;
|
|
219
|
-
/** Human-readable display name. */
|
|
220
|
-
name: string;
|
|
221
|
-
/** Target environment. */
|
|
222
|
-
environment: Environment;
|
|
223
|
-
/** Optional description. */
|
|
224
|
-
description?: string;
|
|
225
|
-
/** Initial rollout percentage. */
|
|
226
|
-
rolloutPercentage: number;
|
|
227
|
-
/** Initial variants. */
|
|
228
|
-
variants: FlagVariants;
|
|
229
|
-
/** Initial targeting rules. */
|
|
230
|
-
targetingRules: TargetingRule[];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* DTO for updating an existing feature flag (all fields optional).
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* const dto: UpdateFlagDto = {
|
|
238
|
-
* isEnabled: true,
|
|
239
|
-
* rolloutPercentage: 75,
|
|
240
|
-
* };
|
|
241
|
-
*/
|
|
242
|
-
export interface UpdateFlagDto {
|
|
243
|
-
/** Optional new display name. */
|
|
244
|
-
name?: string;
|
|
245
|
-
/** Optional new description. */
|
|
246
|
-
description?: string;
|
|
247
|
-
/** Toggle kill-switch state. */
|
|
248
|
-
isEnabled?: boolean;
|
|
249
|
-
/** New rollout percentage (0–100). */
|
|
250
|
-
rolloutPercentage?: number;
|
|
251
|
-
/** Updated targeting rules array. */
|
|
252
|
-
targetingRules?: TargetingRule[];
|
|
253
|
-
/** Updated variants map. */
|
|
254
|
-
variants?: FlagVariants;
|
|
255
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Main entry point for @nexussdk/contracts.
|
|
3
|
-
* Re-exports all contract modules: flags, tracker, auth, and RFC 7807 problem details.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* import { FeatureFlag, ProblemDetails, ErrorEventPayload } from '@nexussdk/contracts';
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export * from './auth.js';
|
|
10
|
-
export * from './flags.js';
|
|
11
|
-
export * from './tracker.js';
|
|
12
|
-
export * from './rfc7807.js';
|
package/src/rfc7807.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Problem Details for HTTP APIs Specification (RFC 7807).
|
|
3
|
-
* Standardized error format across Go-Gin and NestJS error responses.
|
|
4
|
-
* @see {@link https://www.rfc-editor.org/rfc/rfc7807}
|
|
5
|
-
* @module @nexus/contracts/rfc7807
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* RFC 7807 Compliant Error Schema.
|
|
10
|
-
* Ensures consistent machine-readable error diagnostics across all Nexus services.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const problem: ProblemDetails = {
|
|
14
|
-
* type: 'https://nexus.dev/errors/quota-exceeded',
|
|
15
|
-
* title: 'Monthly Quota Exceeded',
|
|
16
|
-
* status: 429,
|
|
17
|
-
* detail: "API Key 'pk_live_...' has exhausted its limit of 50,000 monthly events.",
|
|
18
|
-
* instance: '/api/v1/telemetry/errors',
|
|
19
|
-
* timestamp: '2024-06-01T12:00:00Z',
|
|
20
|
-
* };
|
|
21
|
-
*/
|
|
22
|
-
export interface ProblemDetails {
|
|
23
|
-
/**
|
|
24
|
-
* URI reference identifying the problem type.
|
|
25
|
-
* Should be a stable, documented URI that clients can bookmark.
|
|
26
|
-
* @example 'https://nexus.dev/errors/rate-limit-exceeded'
|
|
27
|
-
*/
|
|
28
|
-
type: string;
|
|
29
|
-
/**
|
|
30
|
-
* Short, human-readable summary of problem type.
|
|
31
|
-
* Must be invariant across occurrences of the same problem type.
|
|
32
|
-
* @example 'Too Many Requests'
|
|
33
|
-
*/
|
|
34
|
-
title: string;
|
|
35
|
-
/**
|
|
36
|
-
* HTTP status code generated by origin server.
|
|
37
|
-
* @example 429
|
|
38
|
-
*/
|
|
39
|
-
status: number;
|
|
40
|
-
/**
|
|
41
|
-
* Human-readable explanation specific to this occurrence of the problem.
|
|
42
|
-
* May differ across occurrences of the same problem type.
|
|
43
|
-
* @example "API Key 'pk_live_a1b2...' has exhausted its monthly event limit."
|
|
44
|
-
*/
|
|
45
|
-
detail: string;
|
|
46
|
-
/**
|
|
47
|
-
* URI reference identifying specific occurrence of problem.
|
|
48
|
-
* Typically the request path that triggered the error.
|
|
49
|
-
* @example '/api/v1/telemetry/errors'
|
|
50
|
-
*/
|
|
51
|
-
instance?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Additional diagnostic error parameters for validation failures.
|
|
54
|
-
* @example [{ name: 'email', reason: 'Must be a valid email address.' }]
|
|
55
|
-
*/
|
|
56
|
-
invalidParams?: Array<{
|
|
57
|
-
/** Field name that caused the validation error. */
|
|
58
|
-
name: string;
|
|
59
|
-
/** Human-readable reason for the validation failure. */
|
|
60
|
-
reason: string;
|
|
61
|
-
}>;
|
|
62
|
-
/**
|
|
63
|
-
* ISO 8601 timestamp when error was produced.
|
|
64
|
-
* @example '2024-06-01T12:00:00.000Z'
|
|
65
|
-
*/
|
|
66
|
-
timestamp?: string;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Standard Nexus error type URI prefix.
|
|
71
|
-
* All RFC 7807 type values should use this base to ensure namespacing consistency.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* const type = `${NEXUS_ERROR_BASE}/rate-limit-exceeded`;
|
|
75
|
-
*/
|
|
76
|
-
export const NEXUS_ERROR_BASE = 'https://nexus.dev/errors' as const;
|
package/src/tracker.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Telemetry, Breadcrumb Tracing, and Error Ingestion contracts.
|
|
3
|
-
* @module @nexus/contracts/tracker
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Environment } from './auth.js';
|
|
7
|
-
import type { UserContext } from './flags.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Severity level of captured telemetry events.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const level: SeverityLevel = 'error';
|
|
14
|
-
*/
|
|
15
|
-
export type SeverityLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Categorization of user action trails leading to a crash.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const category: BreadcrumbCategory = 'ui.click';
|
|
22
|
-
*/
|
|
23
|
-
export type BreadcrumbCategory = 'ui.click' | 'navigation' | 'http' | 'console' | 'custom';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Recorded trail of user activity captured before an exception.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* const breadcrumb: Breadcrumb = {
|
|
30
|
-
* timestamp: 1704067200000,
|
|
31
|
-
* category: 'ui.click',
|
|
32
|
-
* message: 'Clicked button #checkout-btn',
|
|
33
|
-
* level: 'info',
|
|
34
|
-
* data: { elementId: 'checkout-btn', page: '/checkout' },
|
|
35
|
-
* };
|
|
36
|
-
*/
|
|
37
|
-
export interface Breadcrumb {
|
|
38
|
-
/** Milliseconds epoch timestamp when event occurred. */
|
|
39
|
-
timestamp: number;
|
|
40
|
-
/** Categorical discriminator. */
|
|
41
|
-
category: BreadcrumbCategory;
|
|
42
|
-
/** Human-readable event description (e.g. "Clicked button #checkout-btn"). */
|
|
43
|
-
message: string;
|
|
44
|
-
/** Severity level of the action. */
|
|
45
|
-
level?: SeverityLevel;
|
|
46
|
-
/** Sanitized event payload (e.g. HTTP status, target route). */
|
|
47
|
-
data?: Record<string, unknown>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Parsed and structured stack frame information.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* const frame: StackFrame = {
|
|
55
|
-
* functionName: 'processPayment',
|
|
56
|
-
* fileName: 'https://app.example.com/chunk.abc123.js',
|
|
57
|
-
* lineNumber: 1,
|
|
58
|
-
* columnNumber: 45231,
|
|
59
|
-
* };
|
|
60
|
-
*/
|
|
61
|
-
export interface StackFrame {
|
|
62
|
-
/** Name of the executing function or scope. */
|
|
63
|
-
functionName: string;
|
|
64
|
-
/** URL or relative path of the script file. */
|
|
65
|
-
fileName: string;
|
|
66
|
-
/** 1-based source line number. */
|
|
67
|
-
lineNumber: number;
|
|
68
|
-
/** 1-based source column number. */
|
|
69
|
-
columnNumber: number;
|
|
70
|
-
/** Extracted source context lines if available (after source map resolution). */
|
|
71
|
-
contextLines?: string[];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Ambient client execution device and browser context.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* const ctx: DeviceContext = {
|
|
79
|
-
* userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...',
|
|
80
|
-
* currentUrl: 'https://app.example.com/checkout',
|
|
81
|
-
* viewport: '1920x1080',
|
|
82
|
-
* networkStatus: '4g',
|
|
83
|
-
* timezone: 'Asia/Ho_Chi_Minh',
|
|
84
|
-
* };
|
|
85
|
-
*/
|
|
86
|
-
export interface DeviceContext {
|
|
87
|
-
/** Browser User-Agent string. */
|
|
88
|
-
userAgent: string;
|
|
89
|
-
/** Client operating system name and version. */
|
|
90
|
-
os?: string;
|
|
91
|
-
/** Browser name and version. */
|
|
92
|
-
browser?: string;
|
|
93
|
-
/** Viewport dimensions (e.g. "1920x1080"). */
|
|
94
|
-
viewport?: string;
|
|
95
|
-
/** Current browser window URL where error occurred. */
|
|
96
|
-
currentUrl: string;
|
|
97
|
-
/** Network connectivity condition (e.g. "4g", "wifi", "online"). */
|
|
98
|
-
networkStatus?: string;
|
|
99
|
-
/** Client timezone (e.g. "Asia/Ho_Chi_Minh"). */
|
|
100
|
-
timezone?: string;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Ingestion payload dispatched from @nexus/tracker to Go-Gin edge.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* const payload: ErrorEventPayload = {
|
|
108
|
-
* fingerprint: 'sha256hex...',
|
|
109
|
-
* errorType: 'TypeError',
|
|
110
|
-
* errorMessage: "Cannot read properties of undefined (reading 'map')",
|
|
111
|
-
* stackTrace: [{ functionName: 'ProductList', fileName: 'chunk.js', lineNumber: 1, columnNumber: 400 }],
|
|
112
|
-
* breadcrumbs: [],
|
|
113
|
-
* deviceContext: { userAgent: 'Mozilla/5.0...', currentUrl: '/products' },
|
|
114
|
-
* occurrenceCount: 1,
|
|
115
|
-
* clientTimestamp: 1704067200000,
|
|
116
|
-
* };
|
|
117
|
-
*/
|
|
118
|
-
export interface ErrorEventPayload {
|
|
119
|
-
/**
|
|
120
|
-
* Deterministic hash representing this specific class of crash.
|
|
121
|
-
* Format: sha256(errorType + ":" + errorMessage + ":" + topFrameFile + ":" + topFrameLine)
|
|
122
|
-
*/
|
|
123
|
-
fingerprint: string;
|
|
124
|
-
/** JavaScript error type (e.g. "TypeError", "ReferenceError", "UnhandledRejection"). */
|
|
125
|
-
errorType: string;
|
|
126
|
-
/** Primary error message string. */
|
|
127
|
-
errorMessage: string;
|
|
128
|
-
/** Parsed stack trace frames from innermost to outermost. */
|
|
129
|
-
stackTrace: StackFrame[];
|
|
130
|
-
/** Chronological ring-buffer trail of events prior to crash (max 20). */
|
|
131
|
-
breadcrumbs: Breadcrumb[];
|
|
132
|
-
/** End-user context at time of crash (sanitized before transmission). */
|
|
133
|
-
userContext?: UserContext;
|
|
134
|
-
/** Client environment context. */
|
|
135
|
-
deviceContext: DeviceContext;
|
|
136
|
-
/** Key-value metadata tags for search aggregation. */
|
|
137
|
-
tags?: Record<string, string>;
|
|
138
|
-
/**
|
|
139
|
-
* Counter tracking consecutive duplicate occurrences aggregated by client.
|
|
140
|
-
* Prevents infinite loop crash cascades from overwhelming ingestion.
|
|
141
|
-
*/
|
|
142
|
-
occurrenceCount: number;
|
|
143
|
-
/** Client-side epoch timestamp in milliseconds when error was captured. */
|
|
144
|
-
clientTimestamp: number;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Persistent error event record stored in PostgreSQL and returned to Shell UI.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* const entity: ErrorEventEntity = {
|
|
152
|
-
* ...payload,
|
|
153
|
-
* id: 'uuid-v4',
|
|
154
|
-
* projectId: 'project-uuid',
|
|
155
|
-
* environment: 'production',
|
|
156
|
-
* serverReceivedAt: '2024-01-01T00:00:05Z',
|
|
157
|
-
* };
|
|
158
|
-
*/
|
|
159
|
-
export interface ErrorEventEntity extends ErrorEventPayload {
|
|
160
|
-
/** Unique UUID v4 identifier. */
|
|
161
|
-
id: string;
|
|
162
|
-
/** Project UUID v4 identifier. */
|
|
163
|
-
projectId: string;
|
|
164
|
-
/** Target deployment environment. */
|
|
165
|
-
environment: Environment;
|
|
166
|
-
/** Timestamp when Go-Gin successfully processed and recorded the event. */
|
|
167
|
-
serverReceivedAt: string;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Aggregated error group item displayed on the Console Dashboard.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* const group: ErrorGroupSummary = {
|
|
175
|
-
* fingerprint: 'sha256hex...',
|
|
176
|
-
* errorType: 'TypeError',
|
|
177
|
-
* errorMessage: "Cannot read properties of undefined (reading 'map')",
|
|
178
|
-
* environment: 'production',
|
|
179
|
-
* totalCount: 1547,
|
|
180
|
-
* affectedUsersCount: 234,
|
|
181
|
-
* firstSeenAt: '2024-01-01T10:00:00Z',
|
|
182
|
-
* lastSeenAt: '2024-06-15T14:32:01Z',
|
|
183
|
-
* };
|
|
184
|
-
*/
|
|
185
|
-
export interface ErrorGroupSummary {
|
|
186
|
-
/** Fingerprint common to all events in this group. */
|
|
187
|
-
fingerprint: string;
|
|
188
|
-
/** Error type classification. */
|
|
189
|
-
errorType: string;
|
|
190
|
-
/** Primary error message. */
|
|
191
|
-
errorMessage: string;
|
|
192
|
-
/** Environment where errors occurred. */
|
|
193
|
-
environment: Environment;
|
|
194
|
-
/** Total sum of crash occurrences across all end-users. */
|
|
195
|
-
totalCount: number;
|
|
196
|
-
/** Count of unique users impacted by this crash group. */
|
|
197
|
-
affectedUsersCount: number;
|
|
198
|
-
/** Timestamp of the first time this crash was ever seen. */
|
|
199
|
-
firstSeenAt: string;
|
|
200
|
-
/** Timestamp of the latest crash occurrence. */
|
|
201
|
-
lastSeenAt: string;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Re-export UserContext for downstream consumers of @nexus/contracts/tracker
|
|
205
|
-
export type { UserContext };
|
package/tsconfig.json
DELETED
package/tsup.config.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'tsup';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: ['src/index.ts', 'src/auth.ts', 'src/flags.ts', 'src/tracker.ts', 'src/rfc7807.ts'],
|
|
5
|
-
format: ['esm', 'cjs'],
|
|
6
|
-
dts: true,
|
|
7
|
-
splitting: false,
|
|
8
|
-
sourcemap: true,
|
|
9
|
-
clean: true,
|
|
10
|
-
treeshake: true,
|
|
11
|
-
target: 'es2022',
|
|
12
|
-
outExtension({ format }) {
|
|
13
|
-
return {
|
|
14
|
-
js: format === 'esm' ? '.mjs' : '.cjs',
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
});
|