@in2grate/sdk 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/dist/index.d.ts +193 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +34 -0
- package/dist/index.test.js.map +1 -0
- package/package.json +29 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export type TenantId = string & {
|
|
2
|
+
readonly __brand: 'TenantId';
|
|
3
|
+
};
|
|
4
|
+
export type FlowName = string & {
|
|
5
|
+
readonly __brand: 'FlowName';
|
|
6
|
+
};
|
|
7
|
+
export type RunId = string & {
|
|
8
|
+
readonly __brand: 'RunId';
|
|
9
|
+
};
|
|
10
|
+
export type OrgId = string & {
|
|
11
|
+
readonly __brand: 'OrgId';
|
|
12
|
+
};
|
|
13
|
+
export type FamilyId = string & {
|
|
14
|
+
readonly __brand: 'FamilyId';
|
|
15
|
+
};
|
|
16
|
+
export type EnvironmentId = string & {
|
|
17
|
+
readonly __brand: 'EnvironmentId';
|
|
18
|
+
};
|
|
19
|
+
export interface HttpRequestOptions {
|
|
20
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD';
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
body?: unknown;
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Controls how the response body is decoded. Defaults to `"json"`.
|
|
26
|
+
*
|
|
27
|
+
* - `"json"` — Parse as JSON. Empty bodies (e.g. 204) return `null` instead of
|
|
28
|
+
* throwing. Invalid JSON throws with the raw body included in the
|
|
29
|
+
* error message.
|
|
30
|
+
* - `"text"` — Return the raw response body as a `string`.
|
|
31
|
+
* - `"arrayBuffer"` — Return the raw response body as a `Uint8Array`.
|
|
32
|
+
* - `"raw"` — Alias for `"arrayBuffer"`. Signals intent to work with opaque bytes
|
|
33
|
+
* (e.g. binary files, multipart). `data` is `Uint8Array`.
|
|
34
|
+
*/
|
|
35
|
+
responseType?: 'json' | 'text' | 'arrayBuffer' | 'raw';
|
|
36
|
+
}
|
|
37
|
+
export interface HttpResponse<T = unknown> {
|
|
38
|
+
status: number;
|
|
39
|
+
headers: Record<string, string>;
|
|
40
|
+
data: T;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* All outbound network calls must go through this client so the platform can
|
|
44
|
+
* meter usage (1 task unit per call) and apply retry/timeout policy.
|
|
45
|
+
*/
|
|
46
|
+
export interface HttpClient {
|
|
47
|
+
request<T = unknown>(url: string, options?: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
48
|
+
get<T = unknown>(url: string, options?: Omit<HttpRequestOptions, 'method'>): Promise<HttpResponse<T>>;
|
|
49
|
+
post<T = unknown>(url: string, body?: unknown, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<HttpResponse<T>>;
|
|
50
|
+
put<T = unknown>(url: string, body?: unknown, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<HttpResponse<T>>;
|
|
51
|
+
patch<T = unknown>(url: string, body?: unknown, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<HttpResponse<T>>;
|
|
52
|
+
delete<T = unknown>(url: string, options?: Omit<HttpRequestOptions, 'method'>): Promise<HttpResponse<T>>;
|
|
53
|
+
}
|
|
54
|
+
export interface FlowLogger {
|
|
55
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
56
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
57
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
58
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Persistent key-value store scoped to a tenant.
|
|
62
|
+
* Useful in polling flows to track cursors, last-seen IDs, etc.
|
|
63
|
+
*/
|
|
64
|
+
export interface StateClient {
|
|
65
|
+
get(key: string): Promise<unknown>;
|
|
66
|
+
set(key: string, value: unknown): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
export interface SecretsClient {
|
|
69
|
+
get(key: string): Promise<string | undefined>;
|
|
70
|
+
}
|
|
71
|
+
export interface OAuthClient {
|
|
72
|
+
getToken(providerId: string): Promise<string>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Injected into every handler invocation. Customers receive this at runtime;
|
|
76
|
+
* tests receive a mock implementation from @in2grate/testing.
|
|
77
|
+
*/
|
|
78
|
+
export interface FlowContext {
|
|
79
|
+
/** @deprecated Use envId instead */
|
|
80
|
+
readonly tenantId: EnvironmentId;
|
|
81
|
+
readonly envId: EnvironmentId;
|
|
82
|
+
readonly orgId: OrgId;
|
|
83
|
+
readonly flowName: FlowName;
|
|
84
|
+
readonly runId: RunId;
|
|
85
|
+
readonly config: Readonly<Record<string, unknown>>;
|
|
86
|
+
readonly http: HttpClient;
|
|
87
|
+
readonly logger: FlowLogger;
|
|
88
|
+
readonly state: StateClient;
|
|
89
|
+
readonly secrets: SecretsClient;
|
|
90
|
+
readonly oauth: OAuthClient;
|
|
91
|
+
}
|
|
92
|
+
export interface WebhookTriggerConfig {
|
|
93
|
+
type: 'webhook';
|
|
94
|
+
}
|
|
95
|
+
export interface PollingTriggerConfig {
|
|
96
|
+
type: 'polling';
|
|
97
|
+
/** Standard 5-field cron expression (e.g. hourly = '0 * * * *', every 5 min uses asterisk/5). */
|
|
98
|
+
schedule: string;
|
|
99
|
+
}
|
|
100
|
+
export interface ManualTriggerConfig {
|
|
101
|
+
type: 'manual';
|
|
102
|
+
}
|
|
103
|
+
export type TriggerConfig = WebhookTriggerConfig | PollingTriggerConfig | ManualTriggerConfig;
|
|
104
|
+
export interface PollItem {
|
|
105
|
+
id: string | number;
|
|
106
|
+
[key: string]: unknown;
|
|
107
|
+
}
|
|
108
|
+
export interface PollResult {
|
|
109
|
+
items: PollItem[];
|
|
110
|
+
nextCursor?: unknown;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Optional named export from a polling flow module.
|
|
114
|
+
* Called on each scheduled tick to fetch new items.
|
|
115
|
+
* Return an empty items array to skip billing for that tick.
|
|
116
|
+
*/
|
|
117
|
+
export type PollFunction = (ctx: FlowContext, cursor: unknown) => Promise<PollResult>;
|
|
118
|
+
export interface FlowDefinition<TInput = unknown, TOutput = unknown> {
|
|
119
|
+
/** Must be unique within the tenant's project. Used as the URL slug for webhooks. */
|
|
120
|
+
name: string;
|
|
121
|
+
trigger: TriggerConfig;
|
|
122
|
+
handler(ctx: FlowContext, input: TInput): Promise<TOutput>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Throw this inside a flow handler to signal a permanent, non-retryable failure.
|
|
126
|
+
* The job will be moved to the dead-letter queue immediately without further attempts.
|
|
127
|
+
*
|
|
128
|
+
* Use for failures where retrying with the same input can never succeed:
|
|
129
|
+
* invalid signatures, malformed payloads, authorisation rejections, etc.
|
|
130
|
+
*/
|
|
131
|
+
export declare class PermanentError extends Error {
|
|
132
|
+
readonly name = "PermanentError";
|
|
133
|
+
constructor(message: string);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* defineFlow is a typed identity function — it exists solely for type inference
|
|
137
|
+
* and editor autocomplete. No runtime behaviour.
|
|
138
|
+
*/
|
|
139
|
+
export declare function defineFlow<TInput = unknown, TOutput = unknown>(definition: FlowDefinition<TInput, TOutput>): FlowDefinition<TInput, TOutput>;
|
|
140
|
+
/**
|
|
141
|
+
* Returns a new headers object with sensitive values replaced by [REDACTED].
|
|
142
|
+
* Always redacts: Authorization, Cookie, Set-Cookie, Proxy-Authorization.
|
|
143
|
+
* Also redacts any header whose name contains "token", "secret", or "key".
|
|
144
|
+
*/
|
|
145
|
+
export declare function redactHeaders(headers: Record<string, string>): Record<string, string>;
|
|
146
|
+
/**
|
|
147
|
+
* A single recorded HTTP call captured during a flow run.
|
|
148
|
+
* Stored in `.in2/cassettes/<flowName>.json` for use in offline replay.
|
|
149
|
+
*/
|
|
150
|
+
export interface CassetteEntry {
|
|
151
|
+
url: string;
|
|
152
|
+
method: string;
|
|
153
|
+
requestHeaders: Record<string, string>;
|
|
154
|
+
requestBody: unknown;
|
|
155
|
+
responseStatus: number;
|
|
156
|
+
responseHeaders: Record<string, string>;
|
|
157
|
+
responseBody: unknown;
|
|
158
|
+
/** Present only when response body could not be decoded as text/JSON */
|
|
159
|
+
_responseEncoding?: 'base64';
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* A single recorded HTTP interaction in the cassette format.
|
|
163
|
+
* Uses content-based matching (method + URL + body hash) for replay.
|
|
164
|
+
*/
|
|
165
|
+
export interface CassetteInteraction {
|
|
166
|
+
request: {
|
|
167
|
+
method: string;
|
|
168
|
+
url: string;
|
|
169
|
+
/** Sensitive headers have been redacted before writing to disk */
|
|
170
|
+
headers: Record<string, string>;
|
|
171
|
+
/** SHA-256 hex of request body; empty string when there is no body */
|
|
172
|
+
bodyHash: string;
|
|
173
|
+
};
|
|
174
|
+
response: {
|
|
175
|
+
status: number;
|
|
176
|
+
/** Sensitive headers have been redacted before writing to disk */
|
|
177
|
+
headers: Record<string, string>;
|
|
178
|
+
bodyType: 'json' | 'text' | 'bytes';
|
|
179
|
+
body: unknown;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Cassette file format (version 1) — stored under tests/cassettes/<name>.json.
|
|
184
|
+
* Secrets are redacted before writing; replay requires no real network.
|
|
185
|
+
*/
|
|
186
|
+
export interface CassetteFile {
|
|
187
|
+
meta: {
|
|
188
|
+
createdAt: string;
|
|
189
|
+
version: 1;
|
|
190
|
+
};
|
|
191
|
+
interactions: CassetteInteraction[];
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"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F,YAAY,EAAE,mBAAmB,EAAE,CAAC;CACrC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw this inside a flow handler to signal a permanent, non-retryable failure.
|
|
3
|
+
* The job will be moved to the dead-letter queue immediately without further attempts.
|
|
4
|
+
*
|
|
5
|
+
* Use for failures where retrying with the same input can never succeed:
|
|
6
|
+
* invalid signatures, malformed payloads, authorisation rejections, etc.
|
|
7
|
+
*/
|
|
8
|
+
export class PermanentError extends Error {
|
|
9
|
+
name = 'PermanentError';
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* defineFlow is a typed identity function — it exists solely for type inference
|
|
16
|
+
* and editor autocomplete. No runtime behaviour.
|
|
17
|
+
*/
|
|
18
|
+
export function defineFlow(definition) {
|
|
19
|
+
return definition;
|
|
20
|
+
}
|
|
21
|
+
// ─── Header redaction ─────────────────────────────────────────────────────────
|
|
22
|
+
const ALWAYS_REDACT_HEADERS = new Set([
|
|
23
|
+
'authorization',
|
|
24
|
+
'cookie',
|
|
25
|
+
'set-cookie',
|
|
26
|
+
'proxy-authorization',
|
|
27
|
+
]);
|
|
28
|
+
function isSensitiveHeader(name) {
|
|
29
|
+
const lower = name.toLowerCase();
|
|
30
|
+
return (ALWAYS_REDACT_HEADERS.has(lower) ||
|
|
31
|
+
lower.includes('token') ||
|
|
32
|
+
lower.includes('secret') ||
|
|
33
|
+
lower.includes('key'));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns a new headers object with sensitive values replaced by [REDACTED].
|
|
37
|
+
* Always redacts: Authorization, Cookie, Set-Cookie, Proxy-Authorization.
|
|
38
|
+
* Also redacts any header whose name contains "token", "secret", or "key".
|
|
39
|
+
*/
|
|
40
|
+
export function redactHeaders(headers) {
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
43
|
+
result[key] = isSensitiveHeader(key) ? '[REDACTED]' : value;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+JA;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrB,IAAI,GAAG,gBAAgB,CAAC;IAE1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,UAA2C;IAE3C,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,iFAAiF;AAEjF,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,eAAe;IACf,QAAQ;IACR,YAAY;IACZ,qBAAqB;CACtB,CAAC,CAAC;AAEH,SAAS,iBAAiB,CAAC,IAAY;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,OAAO,CACL,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC;QAChC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;QACvB,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACxB,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CACtB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,OAA+B;IAC3D,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { PermanentError, defineFlow } from './index.js';
|
|
4
|
+
describe('PermanentError', () => {
|
|
5
|
+
it('is an instance of Error', () => {
|
|
6
|
+
const err = new PermanentError('bad input');
|
|
7
|
+
assert.ok(err instanceof Error);
|
|
8
|
+
});
|
|
9
|
+
it('has name PermanentError', () => {
|
|
10
|
+
const err = new PermanentError('bad input');
|
|
11
|
+
assert.equal(err.name, 'PermanentError');
|
|
12
|
+
});
|
|
13
|
+
it('exposes the message', () => {
|
|
14
|
+
const err = new PermanentError('do not retry this');
|
|
15
|
+
assert.equal(err.message, 'do not retry this');
|
|
16
|
+
});
|
|
17
|
+
it('has a stack trace', () => {
|
|
18
|
+
const err = new PermanentError('oops');
|
|
19
|
+
assert.ok(err.stack);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('FlowContext', () => {
|
|
23
|
+
it('supports readonly ctx.config in flow definitions', () => {
|
|
24
|
+
const flow = defineFlow({
|
|
25
|
+
name: 'config-aware-flow',
|
|
26
|
+
trigger: { type: 'webhook' },
|
|
27
|
+
async handler(ctx) {
|
|
28
|
+
return ctx.config['region'];
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
assert.equal(flow.name, 'config-aware-flow');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,oBAAoB,CAA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SACF,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@in2grate/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^20.17.0",
|
|
21
|
+
"typescript": "^5.7.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"test": "tsc && node --test dist/index.test.js",
|
|
26
|
+
"lint": "eslint src",
|
|
27
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
28
|
+
}
|
|
29
|
+
}
|