@apicrafthq/script-sdk 0.1.0-beta.1 → 0.1.0-beta.3
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 +29 -23
- package/package.json +5 -12
- package/dist/testing.d.ts +0 -5
- package/dist/testing.js +0 -10
package/dist/index.d.ts
CHANGED
|
@@ -11,12 +11,20 @@ interface HttpRequestInit {
|
|
|
11
11
|
/** Serialized according to the Content-Type. */
|
|
12
12
|
body?: unknown;
|
|
13
13
|
query?: Record<string, string>;
|
|
14
|
-
}
|
|
15
|
-
|
|
14
|
+
/** Workflow scripts only: resolve `{{placeholders}}` against this API's bound environment. */
|
|
15
|
+
api?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parsed JSON when the response is JSON, the raw string otherwise, null when empty.
|
|
19
|
+
* Kept permissive so scripts can write `body.items[0].id` without narrowing first.
|
|
20
|
+
*/
|
|
21
|
+
type HttpResponseBody = any;
|
|
22
|
+
interface HttpResponse<TBody = HttpResponseBody> {
|
|
16
23
|
status: number;
|
|
17
24
|
statusText: string;
|
|
18
25
|
headers: Record<string, string>;
|
|
19
|
-
body:
|
|
26
|
+
body: TBody;
|
|
27
|
+
duration?: number;
|
|
20
28
|
}
|
|
21
29
|
/** Persistent key/value store across executions. */
|
|
22
30
|
interface ScriptCache {
|
|
@@ -75,40 +83,38 @@ interface ResolvedRequest {
|
|
|
75
83
|
body?: unknown;
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Known workflow block ids. Augmented per-API by the generated env.d.ts so
|
|
88
|
+
* `blockResult(...)` autocompletes real block ids; falls back to `string`.
|
|
89
|
+
*/
|
|
90
|
+
interface BlockResultSchema {
|
|
91
|
+
}
|
|
92
|
+
type WorkflowBlockId = keyof BlockResultSchema extends never ? string : keyof BlockResultSchema | (string & {});
|
|
93
|
+
/** Shared base for workflow scripts (assert, condition, transform, script). */
|
|
79
94
|
interface WorkflowScopedContext extends BaseContext {
|
|
80
95
|
/** 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>;
|
|
96
|
+
blockResult<K extends WorkflowBlockId>(blockId: K): K extends keyof BlockResultSchema ? BlockResultSchema[K] : BlockResult;
|
|
97
|
+
/** Resolved environment of an API bound to this run. Throws when the API is unbound. */
|
|
98
|
+
env(apiSlug: string): Promise<Record<string, string | number | boolean>>;
|
|
88
99
|
}
|
|
89
100
|
interface BlockResult {
|
|
90
101
|
/** Present for `request` blocks. */
|
|
91
102
|
response?: HttpResponse;
|
|
92
103
|
[key: string]: unknown;
|
|
93
104
|
}
|
|
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
105
|
/** Context for an assert script. Throw to fail the assertion. */
|
|
105
106
|
interface AssertContext extends WorkflowScopedContext {
|
|
106
107
|
}
|
|
107
108
|
/** Context for a condition script. Return a boolean to pick then/else. */
|
|
108
109
|
interface ConditionContext extends WorkflowScopedContext {
|
|
109
110
|
}
|
|
110
|
-
/** Context for a
|
|
111
|
+
/** Context for a transform script. Return an object; its keys become the block's outputs. */
|
|
112
|
+
interface TransformContext extends WorkflowScopedContext {
|
|
113
|
+
}
|
|
114
|
+
/** Context for a free-form script block (side-effects only, e.g. wait/poll). */
|
|
111
115
|
interface ScriptContext extends WorkflowScopedContext {
|
|
116
|
+
/** Non-blocking pause, e.g. for polling. */
|
|
117
|
+
sleep(milliseconds: number): Promise<void>;
|
|
112
118
|
}
|
|
113
119
|
|
|
114
|
-
export type { AfterResponseContext, AssertContext, BaseContext, BeforeRequestContext, BlockResult, ConditionContext, EnvSchema, HttpClient, HttpRequestInit, HttpResponse,
|
|
120
|
+
export type { AfterResponseContext, AssertContext, BaseContext, BeforeRequestContext, BlockResult, BlockResultSchema, ConditionContext, EnvSchema, HttpClient, HttpRequestInit, HttpResponse, HttpResponseBody, 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.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TypeScript types for API Craft middleware and custom-auth scripts.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,25 +34,18 @@
|
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
|
+
"development": "./src/index.ts",
|
|
37
38
|
"types": "./dist/index.d.ts",
|
|
38
39
|
"import": "./dist/index.js"
|
|
39
|
-
},
|
|
40
|
-
"./testing": {
|
|
41
|
-
"types": "./dist/testing.d.ts",
|
|
42
|
-
"import": "./dist/testing.js"
|
|
43
40
|
}
|
|
44
41
|
},
|
|
45
42
|
"devDependencies": {
|
|
46
|
-
"@types/chai": "^5.2.0",
|
|
47
43
|
"tsup": "^8",
|
|
48
44
|
"typescript": "^5"
|
|
49
45
|
},
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"@vitest/expect": "^3.2.0",
|
|
52
|
-
"chai": "^5.1.2"
|
|
53
|
-
},
|
|
54
46
|
"scripts": {
|
|
55
|
-
"build": "tsup src/index.ts
|
|
56
|
-
"dev": "tsup src/index.ts
|
|
47
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
48
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
49
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
57
50
|
}
|
|
58
51
|
}
|
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
|
-
};
|