@apicrafthq/script-sdk 0.1.0-beta.1 → 0.1.0-beta.2
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/dist/index.d.ts +20 -20
- package/package.json +3 -12
- package/dist/testing.d.ts +0 -5
- package/dist/testing.js +0 -10
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ interface HttpRequestInit {
|
|
|
11
11
|
/** Serialized according to the Content-Type. */
|
|
12
12
|
body?: unknown;
|
|
13
13
|
query?: Record<string, string>;
|
|
14
|
+
/** Workflow scripts only: resolve `{{placeholders}}` against this API's bound environment. */
|
|
15
|
+
api?: string;
|
|
14
16
|
}
|
|
15
17
|
interface HttpResponse {
|
|
16
18
|
status: number;
|
|
@@ -75,40 +77,38 @@ interface ResolvedRequest {
|
|
|
75
77
|
body?: unknown;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Known workflow block ids. Augmented per-API by the generated env.d.ts so
|
|
82
|
+
* `blockResult(...)` autocompletes real block ids; falls back to `string`.
|
|
83
|
+
*/
|
|
84
|
+
interface BlockResultSchema {
|
|
85
|
+
}
|
|
86
|
+
type WorkflowBlockId = keyof BlockResultSchema extends never ? string : keyof BlockResultSchema | (string & {});
|
|
87
|
+
/** Shared base for workflow scripts (assert, condition, transform, script). */
|
|
79
88
|
interface WorkflowScopedContext extends BaseContext {
|
|
80
89
|
/** Reads the result of a previous block by its id. */
|
|
81
|
-
blockResult(blockId:
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
/** Runs an existing request instance and returns its response. */
|
|
85
|
-
executeRequest(resource: string, instance: string, overrides?: RequestOverrides): Promise<HttpResponse>;
|
|
86
|
-
/** Non-blocking pause, e.g. for polling. */
|
|
87
|
-
sleep(milliseconds: number): Promise<void>;
|
|
90
|
+
blockResult(blockId: WorkflowBlockId): BlockResult;
|
|
91
|
+
/** Resolved environment of an API bound to this run. Throws when the API is unbound. */
|
|
92
|
+
env(apiSlug: string): Promise<Record<string, string | number | boolean>>;
|
|
88
93
|
}
|
|
89
94
|
interface BlockResult {
|
|
90
95
|
/** Present for `request` blocks. */
|
|
91
96
|
response?: HttpResponse;
|
|
92
97
|
[key: string]: unknown;
|
|
93
98
|
}
|
|
94
|
-
interface RequestOverrides {
|
|
95
|
-
params?: {
|
|
96
|
-
path?: Record<string, string>;
|
|
97
|
-
query?: Record<string, string>;
|
|
98
|
-
header?: Record<string, string>;
|
|
99
|
-
};
|
|
100
|
-
body?: {
|
|
101
|
-
data?: unknown;
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
99
|
/** Context for an assert script. Throw to fail the assertion. */
|
|
105
100
|
interface AssertContext extends WorkflowScopedContext {
|
|
106
101
|
}
|
|
107
102
|
/** Context for a condition script. Return a boolean to pick then/else. */
|
|
108
103
|
interface ConditionContext extends WorkflowScopedContext {
|
|
109
104
|
}
|
|
110
|
-
/** Context for a
|
|
105
|
+
/** Context for a transform script. Return an object; its keys become the block's outputs. */
|
|
106
|
+
interface TransformContext extends WorkflowScopedContext {
|
|
107
|
+
}
|
|
108
|
+
/** Context for a free-form script block (side-effects only, e.g. wait/poll). */
|
|
111
109
|
interface ScriptContext extends WorkflowScopedContext {
|
|
110
|
+
/** Non-blocking pause, e.g. for polling. */
|
|
111
|
+
sleep(milliseconds: number): Promise<void>;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
export type { AfterResponseContext, AssertContext, BaseContext, BeforeRequestContext, BlockResult, ConditionContext, EnvSchema, HttpClient, HttpRequestInit, HttpResponse, MutableResolvedRequest,
|
|
114
|
+
export type { AfterResponseContext, AssertContext, BaseContext, BeforeRequestContext, BlockResult, BlockResultSchema, ConditionContext, EnvSchema, HttpClient, HttpRequestInit, HttpResponse, MutableResolvedRequest, RequestScopedContext, ResolvedRequest, ScriptCache, ScriptContext, ScriptLogger, TransformContext, WorkflowScopedContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apicrafthq/script-sdk",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TypeScript types for API Craft middleware and custom-auth scripts.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,23 +36,14 @@
|
|
|
36
36
|
".": {
|
|
37
37
|
"types": "./dist/index.d.ts",
|
|
38
38
|
"import": "./dist/index.js"
|
|
39
|
-
},
|
|
40
|
-
"./testing": {
|
|
41
|
-
"types": "./dist/testing.d.ts",
|
|
42
|
-
"import": "./dist/testing.js"
|
|
43
39
|
}
|
|
44
40
|
},
|
|
45
41
|
"devDependencies": {
|
|
46
|
-
"@types/chai": "^5.2.0",
|
|
47
42
|
"tsup": "^8",
|
|
48
43
|
"typescript": "^5"
|
|
49
44
|
},
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"@vitest/expect": "^3.2.0",
|
|
52
|
-
"chai": "^5.1.2"
|
|
53
|
-
},
|
|
54
45
|
"scripts": {
|
|
55
|
-
"build": "tsup src/index.ts
|
|
56
|
-
"dev": "tsup src/index.ts
|
|
46
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
47
|
+
"dev": "tsup src/index.ts --format esm --dts --watch"
|
|
57
48
|
}
|
|
58
49
|
}
|
package/dist/testing.d.ts
DELETED
package/dist/testing.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// src/expect.ts
|
|
2
|
-
import * as chai from "chai";
|
|
3
|
-
import { JestExtend, JestChaiExpect, JestAsymmetricMatchers } from "@vitest/expect";
|
|
4
|
-
chai.use(JestExtend);
|
|
5
|
-
chai.use(JestChaiExpect);
|
|
6
|
-
chai.use(JestAsymmetricMatchers);
|
|
7
|
-
var expect2 = chai.expect;
|
|
8
|
-
export {
|
|
9
|
-
expect2 as expect
|
|
10
|
-
};
|