@hotmeshio/long-tail-dbos 0.0.0-stage → 0.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/build/steps.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ltClose = exports.ltOpen = void 0;
4
+ exports.openWait = openWait;
5
+ exports.closeWait = closeWait;
6
+ const dbos_sdk_1 = require("@dbos-inc/dbos-sdk");
7
+ const constants_1 = require("./constants");
8
+ const duration_1 = require("./duration");
9
+ const lt_client_1 = require("./lt-client");
10
+ /** Open the escalation this workflow waits on. Runs as a checkpointed step. */
11
+ async function openWait(waitKey, config) {
12
+ const workflowId = dbos_sdk_1.DBOS.workflowID;
13
+ if (!workflowId)
14
+ throw new Error('conditional() must run inside a DBOS workflow');
15
+ const status = await dbos_sdk_1.DBOS.getWorkflowStatus(workflowId);
16
+ const workflowType = status?.workflowName ?? null;
17
+ const expiresAt = config.timeout !== undefined ? new Date(Date.now() + (0, duration_1.toMs)(config.timeout)).toISOString() : null;
18
+ const opened = await (0, lt_client_1.postOpenWait)({
19
+ workflowId,
20
+ runScope: '',
21
+ ...(workflowType ? { workflowType } : {}),
22
+ waitKey,
23
+ role: config.role,
24
+ type: config.type,
25
+ subtype: config.subtype,
26
+ description: config.description,
27
+ priority: config.priority,
28
+ metadata: config.metadata,
29
+ data: config.data,
30
+ ...(expiresAt ? { expiresAt } : {}),
31
+ });
32
+ return { escalationId: opened.escalationId, waitKey, status: opened.status, expiresAt, workflowType };
33
+ }
34
+ /** Cancel the escalation when the recv deadline passes first. */
35
+ async function closeWait(escalationId) {
36
+ await (0, lt_client_1.postCancel)(escalationId);
37
+ }
38
+ function register(fn, name) {
39
+ try {
40
+ return dbos_sdk_1.DBOS.registerStep(fn, { name, retriesAllowed: true, maxAttempts: constants_1.WAIT_DEFAULTS.OPEN_ATTEMPTS });
41
+ }
42
+ catch (err) {
43
+ if (err instanceof dbos_sdk_1.Error.DBOSConflictingRegistrationError) {
44
+ throw new Error(`@hotmeshio/long-tail-dbos must be imported before DBOS.launch(): its ${name} step registers at import`, { cause: err });
45
+ }
46
+ throw err;
47
+ }
48
+ }
49
+ exports.ltOpen = register(openWait, constants_1.STEP.OPEN);
50
+ exports.ltClose = register(closeWait, constants_1.STEP.CLOSE);
@@ -0,0 +1,39 @@
1
+ /** Mirrors Long Tail's LTWaitOutcome; kept local so app processes need no Long Tail install. */
2
+ export interface LTWaitOutcome {
3
+ waitKey: string;
4
+ escalationId: string;
5
+ status: 'resolved' | 'expired' | 'cancelled';
6
+ data?: Record<string, unknown>;
7
+ resolvedBy?: string;
8
+ resolvedAt?: string;
9
+ }
10
+ export interface LongTailConnection {
11
+ /** Long Tail base URL, e.g. https://longtail.example.com */
12
+ url: string;
13
+ /** Bot API key (lt_bot_...) or a JWT. */
14
+ apiKey: string;
15
+ /** Per-request timeout. Default 15 s. */
16
+ requestTimeoutMs?: number;
17
+ }
18
+ export interface LTConditionalConfig {
19
+ role: string;
20
+ type: string;
21
+ subtype?: string;
22
+ description?: string;
23
+ priority?: 1 | 2 | 3 | 4;
24
+ metadata?: Record<string, unknown>;
25
+ /** Shown to the resolver. */
26
+ data?: Record<string, unknown>;
27
+ /** Escalation SLA: '48h', '30m', '10s', '2d', or milliseconds. */
28
+ timeout?: string | number;
29
+ /** recv backstop when there is no SLA, in seconds. Default 365 days. */
30
+ maxWaitSeconds?: number;
31
+ }
32
+ /** Output of the lt.open step; stored in the checkpoint. */
33
+ export interface OpenedWait {
34
+ escalationId: string;
35
+ waitKey: string;
36
+ status: string;
37
+ expiresAt: string | null;
38
+ workflowType: string | null;
39
+ }
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@hotmeshio/long-tail-dbos",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Long Tail escalations for DBOS workflows: one call, conditional().",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "main": "./build/index.js",
7
+ "types": "./build/index.d.ts",
8
+ "files": [
9
+ "build/",
10
+ "LICENSE",
11
+ "README.md"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.build.json",
18
+ "test": "vitest run",
19
+ "test:integration": "vitest run --config vitest.integration.config.ts",
20
+ "test:e2e": "vitest run --config vitest.e2e.config.ts",
21
+ "typecheck": "tsc -p tsconfig.json --noEmit",
22
+ "start": "node build/start.js",
23
+ "probe": "tsx scripts/probe.ts",
24
+ "prepublishOnly": "npm run build"
25
+ },
26
+ "dependencies": {
27
+ "pg": "^8.23.1"
28
+ },
29
+ "peerDependencies": {
30
+ "@dbos-inc/dbos-sdk": "^5.5.0",
31
+ "@hotmeshio/long-tail": "^0.35.0"
32
+ },
33
+ "devDependencies": {
34
+ "@dbos-inc/dbos-sdk": "^5.5.0",
35
+ "@hotmeshio/long-tail": "^0.35.0",
36
+ "@types/node": "^22.20.5",
37
+ "@types/pg": "^8.23.1",
38
+ "socket.io-client": "^4.8.4",
39
+ "tsx": "^4.23.15",
40
+ "typescript": "^5.9.3",
41
+ "vitest": "^3.2.7"
42
+ },
43
+ "exports": {
44
+ ".": {
45
+ "types": "./build/index.d.ts",
46
+ "default": "./build/index.js"
47
+ },
48
+ "./provider": {
49
+ "types": "./build/provider/index.d.ts",
50
+ "default": "./build/provider/index.js"
51
+ }
52
+ },
53
+ "typesVersions": {
54
+ "*": {
55
+ "provider": [
56
+ "./build/provider/index.d.ts"
57
+ ]
58
+ }
59
+ },
60
+ "engines": {
61
+ "node": ">=20"
62
+ },
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "https://github.com/hotmeshio/long-tail-dbos.git"
66
+ }
67
+ }