@kb-labs/workflow-constants 1.1.0
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 +207 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# @kb-labs/workflow-constants
|
|
2
|
+
|
|
3
|
+
Shared constants for the KB Labs workflow engine.
|
|
4
|
+
|
|
5
|
+
## Vision & Purpose
|
|
6
|
+
|
|
7
|
+
**@kb-labs/workflow-constants** provides shared constants for the KB Labs workflow engine. It includes state constants, event names, status enums, and Redis key factories.
|
|
8
|
+
|
|
9
|
+
### Core Goals
|
|
10
|
+
|
|
11
|
+
- **State Constants**: Workflow, job, and step state definitions
|
|
12
|
+
- **Event Names**: Event type constants for workflow events
|
|
13
|
+
- **Status Enums**: Status and state enumerations
|
|
14
|
+
- **Redis Key Factory**: Redis key generation utilities
|
|
15
|
+
|
|
16
|
+
## Package Status
|
|
17
|
+
|
|
18
|
+
- **Version**: 0.1.0
|
|
19
|
+
- **Stage**: Stable
|
|
20
|
+
- **Status**: Production Ready ✅
|
|
21
|
+
|
|
22
|
+
## Architecture
|
|
23
|
+
|
|
24
|
+
### High-Level Overview
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
Workflow Constants
|
|
28
|
+
│
|
|
29
|
+
├──► State Constants
|
|
30
|
+
├──► Event Names
|
|
31
|
+
├──► Priority Constants
|
|
32
|
+
└──► Redis Key Factory
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Key Components
|
|
36
|
+
|
|
37
|
+
1. **Constants** (`index.ts`): All constants and utilities
|
|
38
|
+
|
|
39
|
+
## ✨ Features
|
|
40
|
+
|
|
41
|
+
- **State constants** for workflow, job, and step states
|
|
42
|
+
- **Event names** for workflow events
|
|
43
|
+
- **Priority constants** for job priorities
|
|
44
|
+
- **Redis key factory** for key generation
|
|
45
|
+
- **Environment variable constants** for configuration
|
|
46
|
+
|
|
47
|
+
## 📦 API Reference
|
|
48
|
+
|
|
49
|
+
### Main Exports
|
|
50
|
+
|
|
51
|
+
#### Constants
|
|
52
|
+
|
|
53
|
+
- `RUN_STATES`: Workflow run states
|
|
54
|
+
- `JOB_STATES`: Job execution states
|
|
55
|
+
- `STEP_STATES`: Step execution states
|
|
56
|
+
- `JOB_PRIORITIES`: Job priority levels
|
|
57
|
+
- `EVENT_NAMES`: Event type names
|
|
58
|
+
|
|
59
|
+
#### Types
|
|
60
|
+
|
|
61
|
+
- `RunState`: Run state type
|
|
62
|
+
- `JobState`: Job state type
|
|
63
|
+
- `StepState`: Step state type
|
|
64
|
+
- `JobPriority`: Job priority type
|
|
65
|
+
- `WorkflowEventName`: Workflow event name type
|
|
66
|
+
- `RedisMode`: Redis mode type
|
|
67
|
+
|
|
68
|
+
#### Functions
|
|
69
|
+
|
|
70
|
+
- `createRedisKeyFactory(options)`: Create Redis key factory
|
|
71
|
+
|
|
72
|
+
#### Constants
|
|
73
|
+
|
|
74
|
+
- `DEFAULT_REDIS_NAMESPACE`: Default Redis namespace
|
|
75
|
+
- `WORKFLOW_REDIS_CHANNEL`: Workflow Redis channel
|
|
76
|
+
- `IDEMPOTENCY_TTL_ENV`: Idempotency TTL environment variable
|
|
77
|
+
- `CONCURRENCY_TTL_ENV`: Concurrency TTL environment variable
|
|
78
|
+
- `REDIS_URL_ENV`: Redis URL environment variable
|
|
79
|
+
- `REDIS_MODE_ENV`: Redis mode environment variable
|
|
80
|
+
- `REDIS_NAMESPACE_ENV`: Redis namespace environment variable
|
|
81
|
+
|
|
82
|
+
## 🔧 Configuration
|
|
83
|
+
|
|
84
|
+
### Configuration Options
|
|
85
|
+
|
|
86
|
+
#### RedisKeyFactoryOptions
|
|
87
|
+
|
|
88
|
+
- **namespace**: Redis namespace (default: `'kb'`)
|
|
89
|
+
|
|
90
|
+
### Environment Variables
|
|
91
|
+
|
|
92
|
+
- `KB_WF_IDEMP_TTL_MS`: Idempotency TTL in milliseconds
|
|
93
|
+
- `KB_WF_CONC_TTL_MS`: Concurrency TTL in milliseconds
|
|
94
|
+
- `KB_REDIS_URL`: Redis connection URL
|
|
95
|
+
- `KB_REDIS_MODE`: Redis mode (standalone/cluster/sentinel)
|
|
96
|
+
- `KB_REDIS_NAMESPACE`: Redis namespace
|
|
97
|
+
|
|
98
|
+
## 🔗 Dependencies
|
|
99
|
+
|
|
100
|
+
### Runtime Dependencies
|
|
101
|
+
|
|
102
|
+
None (pure constants package)
|
|
103
|
+
|
|
104
|
+
### Development Dependencies
|
|
105
|
+
|
|
106
|
+
- `@kb-labs/devkit` (`link:../../../kb-labs-devkit`): DevKit presets
|
|
107
|
+
- `@types/node` (`^24.3.3`): Node.js types
|
|
108
|
+
- `tsup` (`^8.5.0`): TypeScript bundler
|
|
109
|
+
- `typescript` (`^5.6.3`): TypeScript compiler
|
|
110
|
+
- `vitest` (`^3.2.4`): Test runner
|
|
111
|
+
|
|
112
|
+
## 🧪 Testing
|
|
113
|
+
|
|
114
|
+
### Test Structure
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
src/__tests__/
|
|
118
|
+
└── (tests to be added)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Test Coverage
|
|
122
|
+
|
|
123
|
+
- **Current Coverage**: ~0% (tests to be added)
|
|
124
|
+
- **Target Coverage**: 90%
|
|
125
|
+
|
|
126
|
+
## 📈 Performance
|
|
127
|
+
|
|
128
|
+
### Performance Characteristics
|
|
129
|
+
|
|
130
|
+
- **Time Complexity**: O(1) for all operations
|
|
131
|
+
- **Space Complexity**: O(1)
|
|
132
|
+
- **Bottlenecks**: None
|
|
133
|
+
|
|
134
|
+
## 🔒 Security
|
|
135
|
+
|
|
136
|
+
### Security Considerations
|
|
137
|
+
|
|
138
|
+
- **Key Factory**: Secure key generation
|
|
139
|
+
- **Namespace Validation**: Namespace validation
|
|
140
|
+
|
|
141
|
+
### Known Vulnerabilities
|
|
142
|
+
|
|
143
|
+
- None
|
|
144
|
+
|
|
145
|
+
## 🐛 Known Issues & Limitations
|
|
146
|
+
|
|
147
|
+
### Known Issues
|
|
148
|
+
|
|
149
|
+
- None currently
|
|
150
|
+
|
|
151
|
+
### Limitations
|
|
152
|
+
|
|
153
|
+
- **Fixed Constants**: Constants are fixed (no dynamic configuration)
|
|
154
|
+
|
|
155
|
+
### Future Improvements
|
|
156
|
+
|
|
157
|
+
- **Dynamic Constants**: Configurable constants support
|
|
158
|
+
|
|
159
|
+
## 🔄 Migration & Breaking Changes
|
|
160
|
+
|
|
161
|
+
### Migration from Previous Versions
|
|
162
|
+
|
|
163
|
+
No breaking changes in current version (0.1.0).
|
|
164
|
+
|
|
165
|
+
### Breaking Changes in Future Versions
|
|
166
|
+
|
|
167
|
+
- None planned
|
|
168
|
+
|
|
169
|
+
## 📚 Examples
|
|
170
|
+
|
|
171
|
+
### Example 1: Use State Constants
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { RUN_STATES, StepState } from '@kb-labs/workflow-constants';
|
|
175
|
+
|
|
176
|
+
if (run.state === RUN_STATES.RUNNING) {
|
|
177
|
+
// ...
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const stepState: StepState = StepState.SUCCESS;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Example 2: Use Event Names
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { EVENT_NAMES } from '@kb-labs/workflow-constants';
|
|
187
|
+
|
|
188
|
+
eventBus.publish(EVENT_NAMES.run.started, data);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Example 3: Create Redis Key Factory
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { createRedisKeyFactory } from '@kb-labs/workflow-constants';
|
|
195
|
+
|
|
196
|
+
const keys = createRedisKeyFactory({ namespace: 'kb' });
|
|
197
|
+
const runKey = keys.run('run-123');
|
|
198
|
+
const queueKey = keys.jobQueue('high');
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## 🤝 Contributing
|
|
202
|
+
|
|
203
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development guidelines.
|
|
204
|
+
|
|
205
|
+
## 📄 License
|
|
206
|
+
|
|
207
|
+
MIT © KB Labs
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
declare const RUN_STATES: readonly ["queued", "running", "success", "failed", "cancelled", "skipped", "dlq"];
|
|
2
|
+
declare const JOB_STATES: readonly ["queued", "running", "success", "failed", "cancelled", "skipped", "interrupted"];
|
|
3
|
+
declare const STEP_STATES: readonly ["queued", "running", "success", "failed", "cancelled", "skipped", "dlq", "waiting_approval"];
|
|
4
|
+
declare const JOB_PRIORITIES: readonly ["high", "normal", "low"];
|
|
5
|
+
|
|
6
|
+
type RunState = (typeof RUN_STATES)[number];
|
|
7
|
+
type JobState = (typeof JOB_STATES)[number];
|
|
8
|
+
type StepState = (typeof STEP_STATES)[number];
|
|
9
|
+
type JobPriority = (typeof JOB_PRIORITIES)[number];
|
|
10
|
+
declare const EVENT_NAMES: {
|
|
11
|
+
readonly run: {
|
|
12
|
+
readonly created: "run.created";
|
|
13
|
+
readonly started: "run.started";
|
|
14
|
+
readonly updated: "run.updated";
|
|
15
|
+
readonly finished: "run.finished";
|
|
16
|
+
readonly cancelled: "run.cancelled";
|
|
17
|
+
readonly failed: "run.failed";
|
|
18
|
+
};
|
|
19
|
+
readonly job: {
|
|
20
|
+
readonly queued: "job.queued";
|
|
21
|
+
readonly started: "job.started";
|
|
22
|
+
readonly updated: "job.updated";
|
|
23
|
+
readonly succeeded: "job.succeeded";
|
|
24
|
+
readonly failed: "job.failed";
|
|
25
|
+
readonly cancelled: "job.cancelled";
|
|
26
|
+
readonly skipped: "job.skipped";
|
|
27
|
+
};
|
|
28
|
+
readonly step: {
|
|
29
|
+
readonly queued: "step.queued";
|
|
30
|
+
readonly started: "step.started";
|
|
31
|
+
readonly updated: "step.updated";
|
|
32
|
+
readonly succeeded: "step.succeeded";
|
|
33
|
+
readonly failed: "step.failed";
|
|
34
|
+
readonly cancelled: "step.cancelled";
|
|
35
|
+
readonly skipped: "step.skipped";
|
|
36
|
+
readonly waitingApproval: "step.waitingApproval";
|
|
37
|
+
};
|
|
38
|
+
readonly log: {
|
|
39
|
+
readonly appended: "log.appended";
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
type WorkflowEventName = (typeof EVENT_NAMES)['run'][keyof (typeof EVENT_NAMES)['run']] | (typeof EVENT_NAMES)['job'][keyof (typeof EVENT_NAMES)['job']] | (typeof EVENT_NAMES)['step'][keyof (typeof EVENT_NAMES)['step']] | (typeof EVENT_NAMES)['log'][keyof (typeof EVENT_NAMES)['log']];
|
|
43
|
+
interface RedisKeyFactory {
|
|
44
|
+
namespace: string;
|
|
45
|
+
idempotency(key: string): string;
|
|
46
|
+
concurrency(group: string): string;
|
|
47
|
+
run(runId: string): string;
|
|
48
|
+
artifacts(runId: string): string;
|
|
49
|
+
jobQueue(priority?: JobPriority): string;
|
|
50
|
+
runEvents(runId: string): string;
|
|
51
|
+
eventChannel(): string;
|
|
52
|
+
lock(name: string): string;
|
|
53
|
+
}
|
|
54
|
+
interface RedisKeyFactoryOptions {
|
|
55
|
+
namespace?: string;
|
|
56
|
+
}
|
|
57
|
+
declare const DEFAULT_REDIS_NAMESPACE = "kb";
|
|
58
|
+
declare const WORKFLOW_REDIS_CHANNEL = "kb:wf:events";
|
|
59
|
+
declare function createRedisKeyFactory(options?: RedisKeyFactoryOptions): RedisKeyFactory;
|
|
60
|
+
declare const IDEMPOTENCY_TTL_ENV = "KB_WF_IDEMP_TTL_MS";
|
|
61
|
+
declare const CONCURRENCY_TTL_ENV = "KB_WF_CONC_TTL_MS";
|
|
62
|
+
declare const REDIS_URL_ENV = "KB_REDIS_URL";
|
|
63
|
+
declare const REDIS_MODE_ENV = "KB_REDIS_MODE";
|
|
64
|
+
declare const REDIS_NAMESPACE_ENV = "KB_REDIS_NAMESPACE";
|
|
65
|
+
type RedisMode = 'standalone' | 'cluster' | 'sentinel';
|
|
66
|
+
|
|
67
|
+
export { CONCURRENCY_TTL_ENV, DEFAULT_REDIS_NAMESPACE, EVENT_NAMES, IDEMPOTENCY_TTL_ENV, JOB_PRIORITIES, JOB_STATES, type JobPriority, type JobState, REDIS_MODE_ENV, REDIS_NAMESPACE_ENV, REDIS_URL_ENV, RUN_STATES, type RedisKeyFactory, type RedisKeyFactoryOptions, type RedisMode, type RunState, STEP_STATES, type StepState, WORKFLOW_REDIS_CHANNEL, type WorkflowEventName, createRedisKeyFactory };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var RUN_STATES = ["queued", "running", "success", "failed", "cancelled", "skipped", "dlq"];
|
|
3
|
+
var JOB_STATES = ["queued", "running", "success", "failed", "cancelled", "skipped", "interrupted"];
|
|
4
|
+
var STEP_STATES = [...RUN_STATES, "waiting_approval"];
|
|
5
|
+
var JOB_PRIORITIES = ["high", "normal", "low"];
|
|
6
|
+
var EVENT_NAMES = {
|
|
7
|
+
run: {
|
|
8
|
+
created: "run.created",
|
|
9
|
+
started: "run.started",
|
|
10
|
+
updated: "run.updated",
|
|
11
|
+
finished: "run.finished",
|
|
12
|
+
cancelled: "run.cancelled",
|
|
13
|
+
failed: "run.failed"
|
|
14
|
+
},
|
|
15
|
+
job: {
|
|
16
|
+
queued: "job.queued",
|
|
17
|
+
started: "job.started",
|
|
18
|
+
updated: "job.updated",
|
|
19
|
+
succeeded: "job.succeeded",
|
|
20
|
+
failed: "job.failed",
|
|
21
|
+
cancelled: "job.cancelled",
|
|
22
|
+
skipped: "job.skipped"
|
|
23
|
+
},
|
|
24
|
+
step: {
|
|
25
|
+
queued: "step.queued",
|
|
26
|
+
started: "step.started",
|
|
27
|
+
updated: "step.updated",
|
|
28
|
+
succeeded: "step.succeeded",
|
|
29
|
+
failed: "step.failed",
|
|
30
|
+
cancelled: "step.cancelled",
|
|
31
|
+
skipped: "step.skipped",
|
|
32
|
+
waitingApproval: "step.waitingApproval"
|
|
33
|
+
},
|
|
34
|
+
log: {
|
|
35
|
+
appended: "log.appended"
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var DEFAULT_REDIS_NAMESPACE = "kb";
|
|
39
|
+
var WORKFLOW_REDIS_CHANNEL = "kb:wf:events";
|
|
40
|
+
function createRedisKeyFactory(options = {}) {
|
|
41
|
+
const namespace = options.namespace?.replace(/[:\s]+/g, ":").replace(/:+$/, "") || DEFAULT_REDIS_NAMESPACE;
|
|
42
|
+
const wfNs = `${namespace}:wf`;
|
|
43
|
+
return {
|
|
44
|
+
namespace: wfNs,
|
|
45
|
+
idempotency(key) {
|
|
46
|
+
return `${wfNs}:idemp:${key}`;
|
|
47
|
+
},
|
|
48
|
+
concurrency(group) {
|
|
49
|
+
return `${wfNs}:conc:${group}`;
|
|
50
|
+
},
|
|
51
|
+
run(runId) {
|
|
52
|
+
return `${wfNs}:runs:${runId}`;
|
|
53
|
+
},
|
|
54
|
+
artifacts(runId) {
|
|
55
|
+
return `${wfNs}:artifacts:${runId}`;
|
|
56
|
+
},
|
|
57
|
+
jobQueue(priority = "normal") {
|
|
58
|
+
return `${wfNs}:queue:jobs:${priority}`;
|
|
59
|
+
},
|
|
60
|
+
runEvents(runId) {
|
|
61
|
+
return `${wfNs}:events:runs:${runId}`;
|
|
62
|
+
},
|
|
63
|
+
eventChannel() {
|
|
64
|
+
return WORKFLOW_REDIS_CHANNEL;
|
|
65
|
+
},
|
|
66
|
+
lock(name) {
|
|
67
|
+
return `${wfNs}:locks:${name}`;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
var IDEMPOTENCY_TTL_ENV = "KB_WF_IDEMP_TTL_MS";
|
|
72
|
+
var CONCURRENCY_TTL_ENV = "KB_WF_CONC_TTL_MS";
|
|
73
|
+
var REDIS_URL_ENV = "KB_REDIS_URL";
|
|
74
|
+
var REDIS_MODE_ENV = "KB_REDIS_MODE";
|
|
75
|
+
var REDIS_NAMESPACE_ENV = "KB_REDIS_NAMESPACE";
|
|
76
|
+
|
|
77
|
+
export { CONCURRENCY_TTL_ENV, DEFAULT_REDIS_NAMESPACE, EVENT_NAMES, IDEMPOTENCY_TTL_ENV, JOB_PRIORITIES, JOB_STATES, REDIS_MODE_ENV, REDIS_NAMESPACE_ENV, REDIS_URL_ENV, RUN_STATES, STEP_STATES, WORKFLOW_REDIS_CHANNEL, createRedisKeyFactory };
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["const RUN_STATES = ['queued', 'running', 'success', 'failed', 'cancelled', 'skipped', 'dlq'] as const\nconst JOB_STATES = ['queued', 'running', 'success', 'failed', 'cancelled', 'skipped', 'interrupted'] as const\nconst STEP_STATES = [...RUN_STATES, 'waiting_approval'] as const\nconst JOB_PRIORITIES = ['high', 'normal', 'low'] as const\n\nexport { RUN_STATES, JOB_STATES, STEP_STATES, JOB_PRIORITIES }\n\nexport type RunState = (typeof RUN_STATES)[number]\nexport type JobState = (typeof JOB_STATES)[number]\nexport type StepState = (typeof STEP_STATES)[number]\nexport type JobPriority = (typeof JOB_PRIORITIES)[number]\n\nexport const EVENT_NAMES = {\n run: {\n created: 'run.created',\n started: 'run.started',\n updated: 'run.updated',\n finished: 'run.finished',\n cancelled: 'run.cancelled',\n failed: 'run.failed',\n },\n job: {\n queued: 'job.queued',\n started: 'job.started',\n updated: 'job.updated',\n succeeded: 'job.succeeded',\n failed: 'job.failed',\n cancelled: 'job.cancelled',\n skipped: 'job.skipped',\n },\n step: {\n queued: 'step.queued',\n started: 'step.started',\n updated: 'step.updated',\n succeeded: 'step.succeeded',\n failed: 'step.failed',\n cancelled: 'step.cancelled',\n skipped: 'step.skipped',\n waitingApproval: 'step.waitingApproval',\n },\n log: {\n appended: 'log.appended',\n },\n} as const\n\nexport type WorkflowEventName =\n | (typeof EVENT_NAMES)['run'][keyof (typeof EVENT_NAMES)['run']]\n | (typeof EVENT_NAMES)['job'][keyof (typeof EVENT_NAMES)['job']]\n | (typeof EVENT_NAMES)['step'][keyof (typeof EVENT_NAMES)['step']]\n | (typeof EVENT_NAMES)['log'][keyof (typeof EVENT_NAMES)['log']]\n\nexport interface RedisKeyFactory {\n namespace: string\n idempotency(key: string): string\n concurrency(group: string): string\n run(runId: string): string\n artifacts(runId: string): string\n jobQueue(priority?: JobPriority): string\n runEvents(runId: string): string\n eventChannel(): string\n lock(name: string): string\n}\n\nexport interface RedisKeyFactoryOptions {\n namespace?: string\n}\n\nexport const DEFAULT_REDIS_NAMESPACE = 'kb'\nexport const WORKFLOW_REDIS_CHANNEL = 'kb:wf:events'\n\nexport function createRedisKeyFactory(\n options: RedisKeyFactoryOptions = {},\n): RedisKeyFactory {\n const namespace =\n options.namespace?.replace(/[:\\s]+/g, ':').replace(/:+$/, '') ||\n DEFAULT_REDIS_NAMESPACE\n const wfNs = `${namespace}:wf`\n\n return {\n namespace: wfNs,\n idempotency(key: string) {\n return `${wfNs}:idemp:${key}`\n },\n concurrency(group: string) {\n return `${wfNs}:conc:${group}`\n },\n run(runId: string) {\n return `${wfNs}:runs:${runId}`\n },\n artifacts(runId: string) {\n return `${wfNs}:artifacts:${runId}`\n },\n jobQueue(priority: JobPriority = 'normal') {\n return `${wfNs}:queue:jobs:${priority}`\n },\n runEvents(runId: string) {\n return `${wfNs}:events:runs:${runId}`\n },\n eventChannel() {\n return WORKFLOW_REDIS_CHANNEL\n },\n lock(name: string) {\n return `${wfNs}:locks:${name}`\n },\n }\n}\n\nexport const IDEMPOTENCY_TTL_ENV = 'KB_WF_IDEMP_TTL_MS'\nexport const CONCURRENCY_TTL_ENV = 'KB_WF_CONC_TTL_MS'\nexport const REDIS_URL_ENV = 'KB_REDIS_URL'\nexport const REDIS_MODE_ENV = 'KB_REDIS_MODE'\nexport const REDIS_NAMESPACE_ENV = 'KB_REDIS_NAMESPACE'\n\nexport type RedisMode = 'standalone' | 'cluster' | 'sentinel'\n\n\n\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kb-labs/workflow-constants",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Shared constants for the KB Labs workflow engine.",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rimraf dist",
|
|
23
|
+
"build": "pnpm clean && tsup --config tsup.config.ts",
|
|
24
|
+
"dev": "tsup --config tsup.config.ts --watch",
|
|
25
|
+
"type-check": "tsc --noEmit",
|
|
26
|
+
"test": "vitest run --passWithNoTests",
|
|
27
|
+
"lint": "eslint . --ignore-pattern 'dist/**'",
|
|
28
|
+
"lint:fix": "eslint . --fix --ignore-pattern 'dist/**'",
|
|
29
|
+
"test:watch": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@kb-labs/devkit": "link:../../../../infra/kb-labs-devkit",
|
|
33
|
+
"@types/node": "^24.3.3",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8",
|
|
35
|
+
"@typescript-eslint/parser": "^8",
|
|
36
|
+
"eslint": "^9",
|
|
37
|
+
"rimraf": "^6.0.1",
|
|
38
|
+
"tsup": "^8.5.0",
|
|
39
|
+
"typescript": "^5.6.3",
|
|
40
|
+
"vitest": "^3.2.4"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=20.0.0",
|
|
44
|
+
"pnpm": ">=9.0.0"
|
|
45
|
+
}
|
|
46
|
+
}
|