@breadstone/archipel-mcp 0.0.10 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/data/guides/ai-text-generation.md +361 -0
  2. package/data/guides/analytics-and-error-tracking.md +189 -0
  3. package/data/guides/authentication-and-authorization.md +657 -0
  4. package/data/guides/blob-storage.md +242 -0
  5. package/data/guides/caching.md +255 -0
  6. package/data/guides/cryptography-and-otp.md +240 -0
  7. package/data/guides/database-setup.md +546 -0
  8. package/data/guides/document-generation.md +174 -0
  9. package/data/guides/email-delivery.md +196 -0
  10. package/data/guides/esigning-integration.md +231 -0
  11. package/data/guides/getting-started.md +351 -0
  12. package/data/guides/implementing-ports.md +317 -0
  13. package/data/guides/index.md +62 -0
  14. package/data/guides/mcp-server.md +222 -0
  15. package/data/guides/openapi-and-feature-discovery.md +266 -0
  16. package/data/guides/payments-and-feature-gating.md +244 -0
  17. package/data/guides/resource-management.md +352 -0
  18. package/data/guides/telemetry-and-observability.md +190 -0
  19. package/data/guides/testing.md +319 -0
  20. package/data/guides/tsdoc-guidelines.md +45 -0
  21. package/data/packages/platform-database/api/Class.DatabaseModule.md +3 -5
  22. package/data/packages/platform-database/api/Class.DatabaseService.md +5 -4
  23. package/data/packages/platform-database/api/Class.PrismaService.md +8 -7
  24. package/data/packages/platform-database/api/Interface.IDatabaseModuleConfig.md +13 -1
  25. package/data/packages/platform-database/api/Interface.IPrismaServiceOptions.md +22 -0
  26. package/data/packages/platform-database/api/Variable.DATABASE_MODULE_CONFIG.md +14 -0
  27. package/data/packages/platform-database/api/Variable.DB_ACCELERATE_URL.md +14 -0
  28. package/data/packages/platform-database/api/Variable.DB_AUTO_CONNECTION.md +14 -0
  29. package/data/packages/platform-database/api/Variable.DB_OPTIMIZE.md +14 -0
  30. package/data/packages/platform-database/api/Variable.DB_OPTIMIZE_API_KEY.md +14 -0
  31. package/data/packages/platform-database/api/Variable.PLATFORM_DATABASE_CONFIG_ENTRIES.md +14 -0
  32. package/data/packages/platform-database/api/index.md +13 -1
  33. package/data/packages/platform-database/index.md +41 -18
  34. package/data/packages/platform-openapi/api/Class.SwaggerFeatureDiscovery.md +10 -6
  35. package/data/packages/platform-telemetry/api/Class.NoopTelemetryFacade.md +10 -10
  36. package/data/packages/platform-telemetry/api/Interface.ITelemetryFacade.md +1 -1
  37. package/package.json +1 -1
  38. package/src/GuidesLoader.d.ts +13 -0
  39. package/src/GuidesLoader.js +81 -0
  40. package/src/main.js +36 -198
  41. package/src/models/IGuideDoc.d.ts +15 -0
  42. package/src/models/IGuideDoc.js +3 -0
  43. package/src/tools/registerGetConfigPatternTool.d.ts +5 -0
  44. package/src/tools/registerGetConfigPatternTool.js +15 -0
  45. package/src/tools/registerGetDtoPatternTool.d.ts +5 -0
  46. package/src/tools/registerGetDtoPatternTool.js +15 -0
  47. package/src/tools/registerGetErrorHandlingPatternTool.d.ts +5 -0
  48. package/src/tools/registerGetErrorHandlingPatternTool.js +15 -0
  49. package/src/tools/registerGetGuardPatternTool.d.ts +5 -0
  50. package/src/tools/registerGetGuardPatternTool.js +15 -0
  51. package/src/tools/registerGetGuideTool.d.ts +6 -0
  52. package/src/tools/registerGetGuideTool.js +32 -0
  53. package/src/tools/registerGetMappingPatternTool.d.ts +5 -0
  54. package/src/tools/registerGetMappingPatternTool.js +34 -0
  55. package/src/tools/registerGetModulePatternTool.d.ts +5 -0
  56. package/src/tools/registerGetModulePatternTool.js +29 -0
  57. package/src/tools/registerGetPackageDocTool.d.ts +6 -0
  58. package/src/tools/registerGetPackageDocTool.js +43 -0
  59. package/src/tools/registerGetQueryPatternTool.d.ts +5 -0
  60. package/src/tools/registerGetQueryPatternTool.js +29 -0
  61. package/src/tools/registerGetRepositoryPatternTool.d.ts +5 -0
  62. package/src/tools/registerGetRepositoryPatternTool.js +29 -0
  63. package/src/tools/registerGetTestingPatternTool.d.ts +5 -0
  64. package/src/tools/registerGetTestingPatternTool.js +15 -0
  65. package/src/tools/registerListGuidesTool.d.ts +6 -0
  66. package/src/tools/registerListGuidesTool.js +22 -0
  67. package/src/tools/registerListPackagesTool.d.ts +6 -0
  68. package/src/tools/registerListPackagesTool.js +20 -0
  69. package/src/tools/registerSearchDocsTool.d.ts +6 -0
  70. package/src/tools/registerSearchDocsTool.js +35 -0
  71. package/src/tools/registerSearchGuidesTool.d.ts +6 -0
  72. package/src/tools/registerSearchGuidesTool.js +28 -0
@@ -0,0 +1,240 @@
1
+ ---
2
+ title: Cryptography & OTP
3
+ description: Hash passwords with bcrypt, generate prefixed UUIDs, and implement TOTP-based multi-factor authentication with QR code enrollment.
4
+ order: 17
5
+ ---
6
+
7
+ # Cryptography & OTP
8
+
9
+ This guide covers cryptographic utilities provided by `platform-cryptography`: password hashing with bcrypt, prefixed UUID generation, and TOTP-based one-time password flows for multi-factor authentication.
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ yarn add @breadstone/archipel-platform-cryptography
17
+ ```
18
+
19
+ ---
20
+
21
+ ## Password Hashing with Bcrypt
22
+
23
+ `BcryptService` wraps the `bcrypt` library to hash and verify passwords securely. It generates a unique salt per hash automatically.
24
+
25
+ ### Hashing a Password
26
+
27
+ ```typescript
28
+ import { Injectable } from '@nestjs/common';
29
+ import { BcryptService } from '@breadstone/archipel-platform-cryptography';
30
+
31
+ @Injectable()
32
+ export class UserService {
33
+ private readonly _bcrypt: BcryptService;
34
+
35
+ constructor(bcrypt: BcryptService) {
36
+ this._bcrypt = bcrypt;
37
+ }
38
+
39
+ public async createUser(email: string, password: string): Promise<void> {
40
+ const hashedPassword = await this._bcrypt.hash(password);
41
+ // Store hashedPassword in the database — never the plain password
42
+ await this._userRepository.create({ email, password: hashedPassword });
43
+ }
44
+ }
45
+ ```
46
+
47
+ ### Verifying a Password
48
+
49
+ ```typescript
50
+ public async authenticate(email: string, password: string): Promise<boolean> {
51
+ const user = await this._userRepository.findByEmail(email);
52
+ if (!user) {
53
+ return false;
54
+ }
55
+
56
+ return this._bcrypt.compare(password, user.password);
57
+ }
58
+ ```
59
+
60
+ `compare()` returns `true` if the plain-text password matches the stored hash.
61
+
62
+ ---
63
+
64
+ ## Generating Prefixed UUIDs
65
+
66
+ `CryptoService` generates UUIDs with a configurable prefix. This is useful for creating human-readable identifiers that indicate their resource type.
67
+
68
+ ```typescript
69
+ import { Injectable } from '@nestjs/common';
70
+ import { CryptoService } from '@breadstone/archipel-platform-cryptography';
71
+
72
+ @Injectable()
73
+ export class OrderService {
74
+ private readonly _crypto: CryptoService;
75
+
76
+ constructor(crypto: CryptoService) {
77
+ this._crypto = crypto;
78
+ }
79
+
80
+ public createOrderId(): string {
81
+ return this._crypto.getRandomGuid('ord');
82
+ // Example: "ord-a1b2c3d4-e5f6-7890-abcd-ef1234567890"
83
+ }
84
+ }
85
+ ```
86
+
87
+ The prefix is required and must be a non-empty string. Use short, descriptive prefixes that represent the resource type:
88
+
89
+ | Resource | Prefix | Example |
90
+ | ------------ | ------ | ------------------------------------------ |
91
+ | Order | `ord` | `ord-550e8400-e29b-41d4-a716-446655440000` |
92
+ | Invoice | `inv` | `inv-6ba7b810-9dad-11d1-80b4-00c04fd430c8` |
93
+ | Subscription | `sub` | `sub-f47ac10b-58cc-4372-a567-0e02b2c3d479` |
94
+ | User | `usr` | `usr-7c9e6679-7425-40de-944b-e07fc1f90ae7` |
95
+
96
+ ---
97
+
98
+ ## TOTP Multi-Factor Authentication
99
+
100
+ `OtpService` implements TOTP (Time-Based One-Time Password) as defined in [RFC 6238](https://datatracker.ietf.org/doc/html/rfc6238). It supports QR code enrollment and token verification.
101
+
102
+ ### Injecting OtpService
103
+
104
+ `OtpService` is provided behind the `OTP_SERVICE_TOKEN` injection token so consumers depend on the `IOtpService` interface:
105
+
106
+ ```typescript
107
+ import { Module } from '@nestjs/common';
108
+ import { OtpService, OTP_SERVICE_TOKEN } from '@breadstone/archipel-platform-cryptography';
109
+
110
+ @Module({
111
+ providers: [
112
+ {
113
+ provide: OTP_SERVICE_TOKEN,
114
+ useClass: OtpService,
115
+ },
116
+ ],
117
+ exports: [OTP_SERVICE_TOKEN],
118
+ })
119
+ export class SecurityModule {}
120
+ ```
121
+
122
+ ### Enrolling a User
123
+
124
+ Generate a secret and a QR code URI for the user's authenticator app:
125
+
126
+ ```typescript
127
+ import { Inject, Injectable } from '@nestjs/common';
128
+ import { OTP_SERVICE_TOKEN, type IOtpService } from '@breadstone/archipel-platform-cryptography';
129
+
130
+ @Injectable()
131
+ export class MfaService {
132
+ private readonly _otp: IOtpService;
133
+
134
+ constructor(@Inject(OTP_SERVICE_TOKEN) otp: IOtpService) {
135
+ this._otp = otp;
136
+ }
137
+
138
+ public async enroll(userId: string, email: string): Promise<{ secret: string; uri: string }> {
139
+ const secret = this._otp.generateSecret();
140
+ const uri = this._otp.generateUri({
141
+ issuer: 'MyApp',
142
+ label: email,
143
+ secret: secret,
144
+ });
145
+
146
+ // Store the secret securely alongside the user record
147
+ await this._userRepository.updateMfaSecret(userId, secret);
148
+
149
+ return { secret, uri };
150
+ // The URI can be encoded as a QR code for scanning with Google Authenticator, Authy, etc.
151
+ }
152
+ }
153
+ ```
154
+
155
+ ### Verifying a Token
156
+
157
+ Verify a 6-digit TOTP code entered by the user:
158
+
159
+ ```typescript
160
+ public verifyToken(token: string, secret: string): boolean {
161
+ return this._otp.verify(token, secret);
162
+ }
163
+ ```
164
+
165
+ Verification uses a configurable tolerance window (`TOTP_EPOCH_TOLERANCE`). The default tolerance is **30 seconds** (±1 time step), meaning the current code and the immediately preceding/following codes are accepted. This compensates for minor clock drift between the server and the user's device.
166
+
167
+ ### Tolerance Configuration
168
+
169
+ The `TOTP_EPOCH_TOLERANCE` constant controls the verification window:
170
+
171
+ | `TOTP_EPOCH_TOLERANCE` | Accepted range |
172
+ | ---------------------- | ----------------- |
173
+ | `0` | Current step only |
174
+ | `30` | ±1 step (±30 s) |
175
+ | `60` | ±2 steps (±60 s) |
176
+ | `90` | ±3 steps (±90 s) |
177
+
178
+ The default value is `30` (±1 step).
179
+
180
+ ---
181
+
182
+ ## Combining Services
183
+
184
+ A typical MFA login flow uses all three services:
185
+
186
+ ```typescript
187
+ @Injectable()
188
+ export class AuthService {
189
+ private readonly _bcrypt: BcryptService;
190
+ private readonly _otp: IOtpService;
191
+ private readonly _crypto: CryptoService;
192
+
193
+ constructor(bcrypt: BcryptService, @Inject(OTP_SERVICE_TOKEN) otp: IOtpService, crypto: CryptoService) {
194
+ this._bcrypt = bcrypt;
195
+ this._otp = otp;
196
+ this._crypto = crypto;
197
+ }
198
+
199
+ public async login(email: string, password: string, totpCode?: string): Promise<IAuthResult> {
200
+ const user = await this._userRepository.findByEmail(email);
201
+ if (!user) {
202
+ throw new UnauthorizedException();
203
+ }
204
+
205
+ // Step 1: Verify password
206
+ const validPassword = await this._bcrypt.compare(password, user.password);
207
+ if (!validPassword) {
208
+ throw new UnauthorizedException();
209
+ }
210
+
211
+ // Step 2: Verify TOTP (if MFA is enabled)
212
+ if (user.mfaEnabled) {
213
+ if (!totpCode) {
214
+ return { status: 'mfa-required' };
215
+ }
216
+ const validTotp = this._otp.verify(totpCode, user.mfaSecret);
217
+ if (!validTotp) {
218
+ throw new UnauthorizedException('Invalid MFA code');
219
+ }
220
+ }
221
+
222
+ // Step 3: Issue session
223
+ const sessionId = this._crypto.getRandomGuid('ses');
224
+ return { status: 'authenticated', sessionId };
225
+ }
226
+ }
227
+ ```
228
+
229
+ ---
230
+
231
+ ## Security Best Practices
232
+
233
+ | Practice | Why |
234
+ | ----------------------------------- | --------------------------------------------------------- |
235
+ | Never store plain-text passwords | Always use `BcryptService.hash()` before persisting |
236
+ | Store MFA secrets encrypted at rest | The TOTP secret is equivalent to a password |
237
+ | Use rate limiting on verification | Prevents brute-force attacks on 6-digit TOTP codes |
238
+ | Generate backup codes on enrollment | Users may lose access to their authenticator device |
239
+ | Log MFA events, not secrets | Never log secrets, tokens, or plain-text passwords |
240
+ | Use `OTP_SERVICE_TOKEN` for DI | Depend on `IOtpService` interface, not the concrete class |