@apicrafthq/script-sdk 0.1.0-beta.0 → 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 CHANGED
@@ -11,13 +11,14 @@ 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;
17
19
  statusText: string;
18
20
  headers: Record<string, string>;
19
- /** Parsed JSON when possible, otherwise a string. */
20
- body: unknown;
21
+ body: Record<string, any>;
21
22
  }
22
23
  /** Persistent key/value store across executions. */
23
24
  interface ScriptCache {
@@ -76,40 +77,38 @@ interface ResolvedRequest {
76
77
  body?: unknown;
77
78
  }
78
79
 
79
- /** Shared base for workflow scripts (assert, condition, script). */
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). */
80
88
  interface WorkflowScopedContext extends BaseContext {
81
89
  /** Reads the result of a previous block by its id. */
82
- blockResult(blockId: string): BlockResult;
83
- /** Writes a variable available to later blocks. */
84
- setVar(name: string, value: unknown): void;
85
- /** Runs an existing request instance and returns its response. */
86
- executeRequest(resource: string, instance: string, overrides?: RequestOverrides): Promise<HttpResponse>;
87
- /** Non-blocking pause, e.g. for polling. */
88
- 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>>;
89
93
  }
90
94
  interface BlockResult {
91
95
  /** Present for `request` blocks. */
92
96
  response?: HttpResponse;
93
97
  [key: string]: unknown;
94
98
  }
95
- interface RequestOverrides {
96
- params?: {
97
- path?: Record<string, string>;
98
- query?: Record<string, string>;
99
- header?: Record<string, string>;
100
- };
101
- body?: {
102
- data?: unknown;
103
- };
104
- }
105
99
  /** Context for an assert script. Throw to fail the assertion. */
106
100
  interface AssertContext extends WorkflowScopedContext {
107
101
  }
108
102
  /** Context for a condition script. Return a boolean to pick then/else. */
109
103
  interface ConditionContext extends WorkflowScopedContext {
110
104
  }
111
- /** Context for a free-form script block. */
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). */
112
109
  interface ScriptContext extends WorkflowScopedContext {
110
+ /** Non-blocking pause, e.g. for polling. */
111
+ sleep(milliseconds: number): Promise<void>;
113
112
  }
114
113
 
115
- export type { AfterResponseContext, AssertContext, BaseContext, BeforeRequestContext, BlockResult, ConditionContext, EnvSchema, HttpClient, HttpRequestInit, HttpResponse, MutableResolvedRequest, RequestOverrides, RequestScopedContext, ResolvedRequest, ScriptCache, ScriptContext, ScriptLogger, WorkflowScopedContext };
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.0",
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 src/testing.ts --format esm --dts --clean",
56
- "dev": "tsup src/index.ts src/testing.ts --format esm --dts --watch"
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
@@ -1,5 +0,0 @@
1
- import { ExpectStatic } from '@vitest/expect';
2
-
3
- declare const expect: ExpectStatic;
4
-
5
- export { expect };
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
- };