38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import 'reflect-metadata';
|
|
import 'dotenv/config';
|
|
import { randomUUID } from 'node:crypto';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { z } from 'zod';
|
|
import { AppModule } from '../app.module';
|
|
import { SessionStore } from '../identity/session.store';
|
|
import { OrderExpiryStore } from '../workflows/order-expiry.store';
|
|
import { expiryRunSchema } from '../workflows/workflow.schemas';
|
|
export async function runExpiryCommand(environment = process.env) {
|
|
const token = z
|
|
.string()
|
|
.regex(/^[A-Za-z0-9_-]{43}$/)
|
|
.parse(environment.WORKFLOW_TOKEN);
|
|
const input = expiryRunSchema.parse({
|
|
limit: Number(environment.WORKFLOW_LIMIT ?? 10),
|
|
idempotencyKey: environment.WORKFLOW_RUN_KEY ?? randomUUID(),
|
|
});
|
|
const app = await NestFactory.createApplicationContext(AppModule, {
|
|
logger: false,
|
|
});
|
|
try {
|
|
const actor = await app.get(SessionStore).authenticate(token);
|
|
return await app.get(OrderExpiryStore).run(actor, input);
|
|
} finally {
|
|
await app.close();
|
|
}
|
|
}
|
|
if (require.main === module)
|
|
void runExpiryCommand()
|
|
.then((result) => console.log(JSON.stringify(result)))
|
|
.catch(() => {
|
|
console.error(
|
|
'Order expiry workflow failed. Check authentication, permissions and database availability.',
|
|
);
|
|
process.exitCode = 1;
|
|
});
|