@nexussdk/contracts 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,235 @@
1
+ import { Environment } from './auth.mjs';
2
+
3
+ /**
4
+ * @fileoverview Feature Flagging, Dynamic Configuration, and ABAC Targeting contracts.
5
+ * @module @nexus/contracts/flags
6
+ */
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
+ type RuleOperator = 'EQUALS' | 'NOT_EQUALS' | 'CONTAINS' | 'NOT_CONTAINS' | 'IN' | 'NOT_IN' | 'STARTS_WITH' | 'ENDS_WITH' | 'GREATER_THAN' | 'LESS_THAN' | 'SEMVER_GTE' | 'SEMVER_LTE';
16
+ /**
17
+ * Atomic rule evaluating a single user attribute against target values.
18
+ *
19
+ * @example
20
+ * const rule: TargetingRule = {
21
+ * attribute: 'country',
22
+ * operator: 'IN',
23
+ * values: ['VN', 'SG', 'TH'],
24
+ * };
25
+ */
26
+ interface TargetingRule {
27
+ /** Attribute path in UserContext (e.g. "country", "tier", "appVersion"). */
28
+ attribute: string;
29
+ /** Logical operator applied to the attribute. */
30
+ operator: RuleOperator;
31
+ /** Comparison targets (strings, numbers, or arrays). */
32
+ values: Array<string | number | boolean>;
33
+ }
34
+ /**
35
+ * Primitive types permissible inside dynamic configuration variants.
36
+ */
37
+ type VariantValue = string | number | boolean | Record<string, unknown> | unknown[];
38
+ /**
39
+ * Remote Configuration variants dictionary.
40
+ *
41
+ * @example
42
+ * const variants: FlagVariants = {
43
+ * button_color: '#FF0055',
44
+ * max_items: 25,
45
+ * theme: 'dark',
46
+ * };
47
+ */
48
+ type FlagVariants = Record<string, VariantValue>;
49
+ /**
50
+ * Represents a Feature Flag entity stored in the platform.
51
+ *
52
+ * @example
53
+ * const flag: FeatureFlag = {
54
+ * id: 'uuid-v4',
55
+ * projectId: 'project-uuid',
56
+ * environment: 'production',
57
+ * key: 'checkout_v2',
58
+ * name: 'Checkout Redesign V2',
59
+ * isEnabled: true,
60
+ * rolloutPercentage: 50,
61
+ * targetingRules: [],
62
+ * variants: { show_express: true },
63
+ * version: 3,
64
+ * createdAt: '2024-01-01T00:00:00Z',
65
+ * updatedAt: '2024-06-01T00:00:00Z',
66
+ * };
67
+ */
68
+ interface FeatureFlag {
69
+ /** Unique UUID v4 identifier. */
70
+ id: string;
71
+ /** Owning Project UUID v4 identifier. */
72
+ projectId: string;
73
+ /** Deployment environment. */
74
+ environment: Environment;
75
+ /** Unique programmatic identifier (e.g. "checkout_v2"). */
76
+ key: string;
77
+ /** Human-readable flag name. */
78
+ name: string;
79
+ /** Optional purpose explanation. */
80
+ description?: string;
81
+ /** Master kill-switch. When false, flag immediately resolves to fallback/false. */
82
+ isEnabled: boolean;
83
+ /**
84
+ * Percentage rollout integer (0 to 100).
85
+ * Computed deterministically via MurmurHash3(userId + flagKey).
86
+ */
87
+ rolloutPercentage: number;
88
+ /** Ordered list of targeting rules. Must satisfy all rules for flag to apply. */
89
+ targetingRules: TargetingRule[];
90
+ /** Remote dynamic configuration key-value pairs attached to this flag. */
91
+ variants: FlagVariants;
92
+ /** Monotonically increasing schema version for cache invalidation. */
93
+ version: number;
94
+ /** Creation timestamp. */
95
+ createdAt: string;
96
+ /** Last modification timestamp. */
97
+ updatedAt: string;
98
+ }
99
+ /**
100
+ * End-user contextual data supplied by Client SDK for rule evaluation.
101
+ *
102
+ * @example
103
+ * const user: UserContext = {
104
+ * id: 'usr_12345',
105
+ * email: 'john@example.com',
106
+ * country: 'VN',
107
+ * appVersion: '2.4.1',
108
+ * custom: { tier: 'premium', vipMember: true },
109
+ * };
110
+ */
111
+ interface UserContext {
112
+ /**
113
+ * Unique user identifier (e.g. "usr_12345").
114
+ * Crucial for consistent percentage rollout bucketing.
115
+ * If omitted, SDK must fallback to anonymous persistent device UUID.
116
+ */
117
+ id?: string;
118
+ /** User email (commonly used for beta targeting). */
119
+ email?: string;
120
+ /** Two-letter ISO country code (e.g. "VN", "US"). */
121
+ country?: string;
122
+ /** Client application version (e.g. "2.4.1") for semver targeting. */
123
+ appVersion?: string;
124
+ /** Arbitrary custom attributes for ABAC rules. */
125
+ custom?: Record<string, string | number | boolean>;
126
+ }
127
+ /**
128
+ * Evaluation output generated for a single flag.
129
+ *
130
+ * @example
131
+ * const result: FlagEvaluationResult = {
132
+ * key: 'checkout_v2',
133
+ * enabled: true,
134
+ * variants: { show_express: true },
135
+ * reason: 'ROLLOUT_MATCH',
136
+ * version: 3,
137
+ * };
138
+ */
139
+ interface FlagEvaluationResult {
140
+ /** Flag unique key. */
141
+ key: string;
142
+ /** Final boolean active status. */
143
+ enabled: boolean;
144
+ /** Selected dynamic configuration variants (empty if disabled). */
145
+ variants: FlagVariants;
146
+ /** Explanation string of evaluation outcome. */
147
+ reason: 'TARGETING_MATCH' | 'ROLLOUT_MATCH' | 'DEFAULT_ENABLED' | 'KILL_SWITCH' | 'FALLBACK';
148
+ /** Schema version of the flag when evaluated. */
149
+ version: number;
150
+ }
151
+ /**
152
+ * Map of multiple evaluated flags returned in single batch request.
153
+ *
154
+ * @example
155
+ * const batch: BatchFlagEvaluation = {
156
+ * checkout_v2: { key: 'checkout_v2', enabled: true, variants: {}, reason: 'ROLLOUT_MATCH', version: 1 },
157
+ * dark_mode: { key: 'dark_mode', enabled: false, variants: {}, reason: 'KILL_SWITCH', version: 2 },
158
+ * };
159
+ */
160
+ type BatchFlagEvaluation = Record<string, FlagEvaluationResult>;
161
+ /**
162
+ * Real-time SSE payload pushed from Go-Gin to Client SDKs when a flag is updated.
163
+ *
164
+ * @example
165
+ * const event: FlagStreamEvent = {
166
+ * type: 'FLAG_UPDATE',
167
+ * key: 'checkout_v2',
168
+ * data: { key: 'checkout_v2', enabled: true, variants: {}, reason: 'DEFAULT_ENABLED', version: 4 },
169
+ * timestamp: 1704067200000,
170
+ * };
171
+ */
172
+ interface FlagStreamEvent {
173
+ /** Event classification. */
174
+ type: 'FLAG_UPDATE' | 'FLAG_DELETE' | 'HEARTBEAT';
175
+ /** Flag key modified. */
176
+ key: string;
177
+ /** Fresh evaluation payload or null on deletion. */
178
+ data?: FlagEvaluationResult;
179
+ /** Server timestamp of dispatch in milliseconds epoch. */
180
+ timestamp: number;
181
+ }
182
+ /**
183
+ * DTO for creating a new feature flag.
184
+ *
185
+ * @example
186
+ * const dto: CreateFlagDto = {
187
+ * key: 'new_checkout',
188
+ * name: 'New Checkout',
189
+ * environment: 'development',
190
+ * rolloutPercentage: 0,
191
+ * variants: {},
192
+ * targetingRules: [],
193
+ * };
194
+ */
195
+ interface CreateFlagDto {
196
+ /** Unique programmatic identifier. */
197
+ key: string;
198
+ /** Human-readable display name. */
199
+ name: string;
200
+ /** Target environment. */
201
+ environment: Environment;
202
+ /** Optional description. */
203
+ description?: string;
204
+ /** Initial rollout percentage. */
205
+ rolloutPercentage: number;
206
+ /** Initial variants. */
207
+ variants: FlagVariants;
208
+ /** Initial targeting rules. */
209
+ targetingRules: TargetingRule[];
210
+ }
211
+ /**
212
+ * DTO for updating an existing feature flag (all fields optional).
213
+ *
214
+ * @example
215
+ * const dto: UpdateFlagDto = {
216
+ * isEnabled: true,
217
+ * rolloutPercentage: 75,
218
+ * };
219
+ */
220
+ interface UpdateFlagDto {
221
+ /** Optional new display name. */
222
+ name?: string;
223
+ /** Optional new description. */
224
+ description?: string;
225
+ /** Toggle kill-switch state. */
226
+ isEnabled?: boolean;
227
+ /** New rollout percentage (0–100). */
228
+ rolloutPercentage?: number;
229
+ /** Updated targeting rules array. */
230
+ targetingRules?: TargetingRule[];
231
+ /** Updated variants map. */
232
+ variants?: FlagVariants;
233
+ }
234
+
235
+ export type { BatchFlagEvaluation, CreateFlagDto, FeatureFlag, FlagEvaluationResult, FlagStreamEvent, FlagVariants, RuleOperator, TargetingRule, UpdateFlagDto, UserContext, VariantValue };
@@ -0,0 +1,235 @@
1
+ import { Environment } from './auth.js';
2
+
3
+ /**
4
+ * @fileoverview Feature Flagging, Dynamic Configuration, and ABAC Targeting contracts.
5
+ * @module @nexus/contracts/flags
6
+ */
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
+ type RuleOperator = 'EQUALS' | 'NOT_EQUALS' | 'CONTAINS' | 'NOT_CONTAINS' | 'IN' | 'NOT_IN' | 'STARTS_WITH' | 'ENDS_WITH' | 'GREATER_THAN' | 'LESS_THAN' | 'SEMVER_GTE' | 'SEMVER_LTE';
16
+ /**
17
+ * Atomic rule evaluating a single user attribute against target values.
18
+ *
19
+ * @example
20
+ * const rule: TargetingRule = {
21
+ * attribute: 'country',
22
+ * operator: 'IN',
23
+ * values: ['VN', 'SG', 'TH'],
24
+ * };
25
+ */
26
+ interface TargetingRule {
27
+ /** Attribute path in UserContext (e.g. "country", "tier", "appVersion"). */
28
+ attribute: string;
29
+ /** Logical operator applied to the attribute. */
30
+ operator: RuleOperator;
31
+ /** Comparison targets (strings, numbers, or arrays). */
32
+ values: Array<string | number | boolean>;
33
+ }
34
+ /**
35
+ * Primitive types permissible inside dynamic configuration variants.
36
+ */
37
+ type VariantValue = string | number | boolean | Record<string, unknown> | unknown[];
38
+ /**
39
+ * Remote Configuration variants dictionary.
40
+ *
41
+ * @example
42
+ * const variants: FlagVariants = {
43
+ * button_color: '#FF0055',
44
+ * max_items: 25,
45
+ * theme: 'dark',
46
+ * };
47
+ */
48
+ type FlagVariants = Record<string, VariantValue>;
49
+ /**
50
+ * Represents a Feature Flag entity stored in the platform.
51
+ *
52
+ * @example
53
+ * const flag: FeatureFlag = {
54
+ * id: 'uuid-v4',
55
+ * projectId: 'project-uuid',
56
+ * environment: 'production',
57
+ * key: 'checkout_v2',
58
+ * name: 'Checkout Redesign V2',
59
+ * isEnabled: true,
60
+ * rolloutPercentage: 50,
61
+ * targetingRules: [],
62
+ * variants: { show_express: true },
63
+ * version: 3,
64
+ * createdAt: '2024-01-01T00:00:00Z',
65
+ * updatedAt: '2024-06-01T00:00:00Z',
66
+ * };
67
+ */
68
+ interface FeatureFlag {
69
+ /** Unique UUID v4 identifier. */
70
+ id: string;
71
+ /** Owning Project UUID v4 identifier. */
72
+ projectId: string;
73
+ /** Deployment environment. */
74
+ environment: Environment;
75
+ /** Unique programmatic identifier (e.g. "checkout_v2"). */
76
+ key: string;
77
+ /** Human-readable flag name. */
78
+ name: string;
79
+ /** Optional purpose explanation. */
80
+ description?: string;
81
+ /** Master kill-switch. When false, flag immediately resolves to fallback/false. */
82
+ isEnabled: boolean;
83
+ /**
84
+ * Percentage rollout integer (0 to 100).
85
+ * Computed deterministically via MurmurHash3(userId + flagKey).
86
+ */
87
+ rolloutPercentage: number;
88
+ /** Ordered list of targeting rules. Must satisfy all rules for flag to apply. */
89
+ targetingRules: TargetingRule[];
90
+ /** Remote dynamic configuration key-value pairs attached to this flag. */
91
+ variants: FlagVariants;
92
+ /** Monotonically increasing schema version for cache invalidation. */
93
+ version: number;
94
+ /** Creation timestamp. */
95
+ createdAt: string;
96
+ /** Last modification timestamp. */
97
+ updatedAt: string;
98
+ }
99
+ /**
100
+ * End-user contextual data supplied by Client SDK for rule evaluation.
101
+ *
102
+ * @example
103
+ * const user: UserContext = {
104
+ * id: 'usr_12345',
105
+ * email: 'john@example.com',
106
+ * country: 'VN',
107
+ * appVersion: '2.4.1',
108
+ * custom: { tier: 'premium', vipMember: true },
109
+ * };
110
+ */
111
+ interface UserContext {
112
+ /**
113
+ * Unique user identifier (e.g. "usr_12345").
114
+ * Crucial for consistent percentage rollout bucketing.
115
+ * If omitted, SDK must fallback to anonymous persistent device UUID.
116
+ */
117
+ id?: string;
118
+ /** User email (commonly used for beta targeting). */
119
+ email?: string;
120
+ /** Two-letter ISO country code (e.g. "VN", "US"). */
121
+ country?: string;
122
+ /** Client application version (e.g. "2.4.1") for semver targeting. */
123
+ appVersion?: string;
124
+ /** Arbitrary custom attributes for ABAC rules. */
125
+ custom?: Record<string, string | number | boolean>;
126
+ }
127
+ /**
128
+ * Evaluation output generated for a single flag.
129
+ *
130
+ * @example
131
+ * const result: FlagEvaluationResult = {
132
+ * key: 'checkout_v2',
133
+ * enabled: true,
134
+ * variants: { show_express: true },
135
+ * reason: 'ROLLOUT_MATCH',
136
+ * version: 3,
137
+ * };
138
+ */
139
+ interface FlagEvaluationResult {
140
+ /** Flag unique key. */
141
+ key: string;
142
+ /** Final boolean active status. */
143
+ enabled: boolean;
144
+ /** Selected dynamic configuration variants (empty if disabled). */
145
+ variants: FlagVariants;
146
+ /** Explanation string of evaluation outcome. */
147
+ reason: 'TARGETING_MATCH' | 'ROLLOUT_MATCH' | 'DEFAULT_ENABLED' | 'KILL_SWITCH' | 'FALLBACK';
148
+ /** Schema version of the flag when evaluated. */
149
+ version: number;
150
+ }
151
+ /**
152
+ * Map of multiple evaluated flags returned in single batch request.
153
+ *
154
+ * @example
155
+ * const batch: BatchFlagEvaluation = {
156
+ * checkout_v2: { key: 'checkout_v2', enabled: true, variants: {}, reason: 'ROLLOUT_MATCH', version: 1 },
157
+ * dark_mode: { key: 'dark_mode', enabled: false, variants: {}, reason: 'KILL_SWITCH', version: 2 },
158
+ * };
159
+ */
160
+ type BatchFlagEvaluation = Record<string, FlagEvaluationResult>;
161
+ /**
162
+ * Real-time SSE payload pushed from Go-Gin to Client SDKs when a flag is updated.
163
+ *
164
+ * @example
165
+ * const event: FlagStreamEvent = {
166
+ * type: 'FLAG_UPDATE',
167
+ * key: 'checkout_v2',
168
+ * data: { key: 'checkout_v2', enabled: true, variants: {}, reason: 'DEFAULT_ENABLED', version: 4 },
169
+ * timestamp: 1704067200000,
170
+ * };
171
+ */
172
+ interface FlagStreamEvent {
173
+ /** Event classification. */
174
+ type: 'FLAG_UPDATE' | 'FLAG_DELETE' | 'HEARTBEAT';
175
+ /** Flag key modified. */
176
+ key: string;
177
+ /** Fresh evaluation payload or null on deletion. */
178
+ data?: FlagEvaluationResult;
179
+ /** Server timestamp of dispatch in milliseconds epoch. */
180
+ timestamp: number;
181
+ }
182
+ /**
183
+ * DTO for creating a new feature flag.
184
+ *
185
+ * @example
186
+ * const dto: CreateFlagDto = {
187
+ * key: 'new_checkout',
188
+ * name: 'New Checkout',
189
+ * environment: 'development',
190
+ * rolloutPercentage: 0,
191
+ * variants: {},
192
+ * targetingRules: [],
193
+ * };
194
+ */
195
+ interface CreateFlagDto {
196
+ /** Unique programmatic identifier. */
197
+ key: string;
198
+ /** Human-readable display name. */
199
+ name: string;
200
+ /** Target environment. */
201
+ environment: Environment;
202
+ /** Optional description. */
203
+ description?: string;
204
+ /** Initial rollout percentage. */
205
+ rolloutPercentage: number;
206
+ /** Initial variants. */
207
+ variants: FlagVariants;
208
+ /** Initial targeting rules. */
209
+ targetingRules: TargetingRule[];
210
+ }
211
+ /**
212
+ * DTO for updating an existing feature flag (all fields optional).
213
+ *
214
+ * @example
215
+ * const dto: UpdateFlagDto = {
216
+ * isEnabled: true,
217
+ * rolloutPercentage: 75,
218
+ * };
219
+ */
220
+ interface UpdateFlagDto {
221
+ /** Optional new display name. */
222
+ name?: string;
223
+ /** Optional new description. */
224
+ description?: string;
225
+ /** Toggle kill-switch state. */
226
+ isEnabled?: boolean;
227
+ /** New rollout percentage (0–100). */
228
+ rolloutPercentage?: number;
229
+ /** Updated targeting rules array. */
230
+ targetingRules?: TargetingRule[];
231
+ /** Updated variants map. */
232
+ variants?: FlagVariants;
233
+ }
234
+
235
+ export type { BatchFlagEvaluation, CreateFlagDto, FeatureFlag, FlagEvaluationResult, FlagStreamEvent, FlagVariants, RuleOperator, TargetingRule, UpdateFlagDto, UserContext, VariantValue };
package/dist/flags.mjs ADDED
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=flags.mjs.map
3
+ //# sourceMappingURL=flags.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"flags.mjs"}
package/dist/index.cjs ADDED
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,4 @@
1
+ export { Account, AccountStatus, ApiKey, ApiKeyType, Environment, GeneratedApiKeyResponse, LoginDto, PlanTier, Project, RegisterAccountDto, SessionPayload } from './auth.mjs';
2
+ export { BatchFlagEvaluation, CreateFlagDto, FeatureFlag, FlagEvaluationResult, FlagStreamEvent, FlagVariants, RuleOperator, TargetingRule, UpdateFlagDto, UserContext, VariantValue } from './flags.mjs';
3
+ export { Breadcrumb, BreadcrumbCategory, DeviceContext, ErrorEventEntity, ErrorEventPayload, ErrorGroupSummary, SeverityLevel, StackFrame } from './tracker.mjs';
4
+ export { NEXUS_ERROR_BASE, ProblemDetails } from './rfc7807.mjs';
@@ -0,0 +1,4 @@
1
+ export { Account, AccountStatus, ApiKey, ApiKeyType, Environment, GeneratedApiKeyResponse, LoginDto, PlanTier, Project, RegisterAccountDto, SessionPayload } from './auth.js';
2
+ export { BatchFlagEvaluation, CreateFlagDto, FeatureFlag, FlagEvaluationResult, FlagStreamEvent, FlagVariants, RuleOperator, TargetingRule, UpdateFlagDto, UserContext, VariantValue } from './flags.js';
3
+ export { Breadcrumb, BreadcrumbCategory, DeviceContext, ErrorEventEntity, ErrorEventPayload, ErrorGroupSummary, SeverityLevel, StackFrame } from './tracker.js';
4
+ export { NEXUS_ERROR_BASE, ProblemDetails } from './rfc7807.js';
package/dist/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ // src/rfc7807.ts
2
+ var NEXUS_ERROR_BASE = "https://nexus.dev/errors";
3
+
4
+ export { NEXUS_ERROR_BASE };
5
+ //# sourceMappingURL=index.mjs.map
6
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,76 @@
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
+ * RFC 7807 Compliant Error Schema.
9
+ * Ensures consistent machine-readable error diagnostics across all Nexus services.
10
+ *
11
+ * @example
12
+ * const problem: ProblemDetails = {
13
+ * type: 'https://nexus.dev/errors/quota-exceeded',
14
+ * title: 'Monthly Quota Exceeded',
15
+ * status: 429,
16
+ * detail: "API Key 'pk_live_...' has exhausted its limit of 50,000 monthly events.",
17
+ * instance: '/api/v1/telemetry/errors',
18
+ * timestamp: '2024-06-01T12:00:00Z',
19
+ * };
20
+ */
21
+ interface ProblemDetails {
22
+ /**
23
+ * URI reference identifying the problem type.
24
+ * Should be a stable, documented URI that clients can bookmark.
25
+ * @example 'https://nexus.dev/errors/rate-limit-exceeded'
26
+ */
27
+ type: string;
28
+ /**
29
+ * Short, human-readable summary of problem type.
30
+ * Must be invariant across occurrences of the same problem type.
31
+ * @example 'Too Many Requests'
32
+ */
33
+ title: string;
34
+ /**
35
+ * HTTP status code generated by origin server.
36
+ * @example 429
37
+ */
38
+ status: number;
39
+ /**
40
+ * Human-readable explanation specific to this occurrence of the problem.
41
+ * May differ across occurrences of the same problem type.
42
+ * @example "API Key 'pk_live_a1b2...' has exhausted its monthly event limit."
43
+ */
44
+ detail: string;
45
+ /**
46
+ * URI reference identifying specific occurrence of problem.
47
+ * Typically the request path that triggered the error.
48
+ * @example '/api/v1/telemetry/errors'
49
+ */
50
+ instance?: string;
51
+ /**
52
+ * Additional diagnostic error parameters for validation failures.
53
+ * @example [{ name: 'email', reason: 'Must be a valid email address.' }]
54
+ */
55
+ invalidParams?: Array<{
56
+ /** Field name that caused the validation error. */
57
+ name: string;
58
+ /** Human-readable reason for the validation failure. */
59
+ reason: string;
60
+ }>;
61
+ /**
62
+ * ISO 8601 timestamp when error was produced.
63
+ * @example '2024-06-01T12:00:00.000Z'
64
+ */
65
+ timestamp?: string;
66
+ }
67
+ /**
68
+ * Standard Nexus error type URI prefix.
69
+ * All RFC 7807 type values should use this base to ensure namespacing consistency.
70
+ *
71
+ * @example
72
+ * const type = `${NEXUS_ERROR_BASE}/rate-limit-exceeded`;
73
+ */
74
+ declare const NEXUS_ERROR_BASE: "https://nexus.dev/errors";
75
+
76
+ export { NEXUS_ERROR_BASE, type ProblemDetails };