nestjs-temporal-core 2.0.7 → 2.0.8
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 +39 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -339,6 +339,7 @@ When integrating Temporal with your NestJS application, organizing your code pro
|
|
|
339
339
|
|
|
340
340
|
```
|
|
341
341
|
|
|
342
|
+
```
|
|
342
343
|
src/
|
|
343
344
|
├── temporal/
|
|
344
345
|
│ ├── activities/
|
|
@@ -364,29 +365,33 @@ src/
|
|
|
364
365
|
│ └── payment.module.ts
|
|
365
366
|
└── app.module.ts
|
|
366
367
|
|
|
367
|
-
|
|
368
|
+
```
|
|
368
369
|
|
|
369
370
|
### Key Files and Their Purpose
|
|
370
371
|
|
|
371
372
|
1. **Activities (src/temporal/activities/)**:
|
|
372
|
-
|
|
373
|
-
|
|
373
|
+
|
|
374
|
+
- Contains activity classes decorated with `@Activity()`
|
|
375
|
+
- Each activity class should group related functionality
|
|
374
376
|
|
|
375
377
|
2. **Workflows (src/temporal/workflows/)**:
|
|
376
|
-
|
|
377
|
-
|
|
378
|
+
|
|
379
|
+
- Contains workflow definitions that orchestrate activities
|
|
380
|
+
- Workflows should be in separate files based on domain
|
|
378
381
|
|
|
379
382
|
3. **Interfaces (src/temporal/interfaces/)**:
|
|
380
|
-
|
|
381
|
-
|
|
383
|
+
|
|
384
|
+
- TypeScript interfaces that define activity and workflow parameters/returns
|
|
385
|
+
- Helps maintain type safety between activities and workflows
|
|
382
386
|
|
|
383
387
|
4. **Temporal Module (src/temporal/temporal.module.ts)**:
|
|
384
|
-
- Centralizes Temporal configuration
|
|
385
|
-
- Imports and registers all activities
|
|
386
388
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
389
|
+
- Centralizes Temporal configuration
|
|
390
|
+
- Imports and registers all activities
|
|
391
|
+
|
|
392
|
+
5. **Business Services (src/modules/\*/)**:
|
|
393
|
+
- Inject the TemporalService
|
|
394
|
+
- Use it to start workflows and interact with Temporal
|
|
390
395
|
|
|
391
396
|
## Integration Examples
|
|
392
397
|
|
|
@@ -401,29 +406,29 @@ import { EmailService } from '../../modules/email/email.service';
|
|
|
401
406
|
@Injectable()
|
|
402
407
|
@Activity()
|
|
403
408
|
export class EmailActivities {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
409
|
+
constructor(private readonly emailService: EmailService) {}
|
|
410
|
+
|
|
411
|
+
@ActivityMethod()
|
|
412
|
+
async sendWelcomeEmail(to: string, name: string): Promise<boolean> {
|
|
413
|
+
await this.emailService.sendEmail({
|
|
414
|
+
to,
|
|
415
|
+
subject: 'Welcome!',
|
|
416
|
+
body: `Hello ${name}, welcome to our platform!`,
|
|
417
|
+
});
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
@ActivityMethod()
|
|
422
|
+
async sendPasswordReset(to: string, resetToken: string): Promise<boolean> {
|
|
423
|
+
await this.emailService.sendEmail({
|
|
424
|
+
to,
|
|
425
|
+
subject: 'Password Reset',
|
|
426
|
+
body: `Please use this token to reset your password: ${resetToken}`,
|
|
427
|
+
});
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
425
430
|
}
|
|
426
|
-
|
|
431
|
+
```
|
|
427
432
|
|
|
428
433
|
```typescript
|
|
429
434
|
// src/temporal/activities/index.ts
|