@giveitsmaller/sdk 0.1.1 → 0.2.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/client.d.ts +55 -0
- package/dist/client.js +284 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +30 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/sse.d.ts +11 -0
- package/dist/sse.js +95 -0
- package/dist/types.d.ts +106 -0
- package/dist/types.js +12 -0
- package/dist/webhook.d.ts +10 -0
- package/dist/webhook.js +33 -0
- package/package.json +10 -4
- package/src/client.ts +0 -401
- package/src/errors.ts +0 -39
- package/src/index.ts +0 -86
- package/src/sse.ts +0 -105
- package/src/types.ts +0 -151
- package/src/webhook.ts +0 -48
package/src/types.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
OperationType,
|
|
3
|
-
CallbackEventType,
|
|
4
|
-
SseEventType,
|
|
5
|
-
SseOperationProgressData,
|
|
6
|
-
SseOperationCompletedData,
|
|
7
|
-
SseOperationFailedData,
|
|
8
|
-
SseJobCompletedData,
|
|
9
|
-
SseJobFailedData,
|
|
10
|
-
SseWorkflowTerminalData,
|
|
11
|
-
} from '@giveitsmaller/contracts/openapi';
|
|
12
|
-
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
// Client configuration
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
export interface GislClientConfig {
|
|
18
|
-
baseUrl: string;
|
|
19
|
-
apiKey?: string;
|
|
20
|
-
headers?: Record<string, string>;
|
|
21
|
-
timeout?: number;
|
|
22
|
-
/** Threshold in bytes above which multipart upload is used (default: 10MB) */
|
|
23
|
-
multipartThreshold?: number;
|
|
24
|
-
/** Max concurrent chunk uploads for multipart (default: 4) */
|
|
25
|
-
multipartConcurrency?: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
// Job definition (typed replacement for generated `any`)
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
|
|
32
|
-
export interface OperationDef {
|
|
33
|
-
type: OperationType;
|
|
34
|
-
options?: Record<string, unknown>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Job sourced from an uploaded file */
|
|
38
|
-
export interface FileJobPayload {
|
|
39
|
-
ref: string;
|
|
40
|
-
file_id: string;
|
|
41
|
-
operations: OperationDef[];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Job sourced from a single upstream job's output */
|
|
45
|
-
export interface SourceJobPayload {
|
|
46
|
-
ref: string;
|
|
47
|
-
source: { ref: string; operation?: string };
|
|
48
|
-
operations: OperationDef[];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Job sourced from multiple upstream jobs (merge/archive) */
|
|
52
|
-
export interface InputsJobPayload {
|
|
53
|
-
ref: string;
|
|
54
|
-
inputs: Array<{
|
|
55
|
-
ref: string;
|
|
56
|
-
operation?: string;
|
|
57
|
-
per_input_options?: Record<string, unknown>;
|
|
58
|
-
}>;
|
|
59
|
-
operations: OperationDef[];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type JobDefinitionPayload =
|
|
63
|
-
| FileJobPayload
|
|
64
|
-
| SourceJobPayload
|
|
65
|
-
| InputsJobPayload;
|
|
66
|
-
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
// Job factory functions
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
|
|
71
|
-
export function fileJob(
|
|
72
|
-
ref: string,
|
|
73
|
-
fileId: string,
|
|
74
|
-
operations: OperationDef[],
|
|
75
|
-
): FileJobPayload {
|
|
76
|
-
return { ref, file_id: fileId, operations };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function sourceJob(
|
|
80
|
-
ref: string,
|
|
81
|
-
source: { ref: string; operation?: string },
|
|
82
|
-
operations: OperationDef[],
|
|
83
|
-
): SourceJobPayload {
|
|
84
|
-
return { ref, source, operations };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function inputsJob(
|
|
88
|
-
ref: string,
|
|
89
|
-
inputs: Array<{
|
|
90
|
-
ref: string;
|
|
91
|
-
operation?: string;
|
|
92
|
-
per_input_options?: Record<string, unknown>;
|
|
93
|
-
}>,
|
|
94
|
-
operations: OperationDef[],
|
|
95
|
-
): InputsJobPayload {
|
|
96
|
-
return { ref, inputs, operations };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
// Workflow creation request (SDK-level, wire-format ready)
|
|
101
|
-
// ---------------------------------------------------------------------------
|
|
102
|
-
|
|
103
|
-
export interface WorkflowCreatePayload {
|
|
104
|
-
jobs: JobDefinitionPayload[];
|
|
105
|
-
workflow_edges?: Array<{ from: string; to: string }>;
|
|
106
|
-
callback_url?: string;
|
|
107
|
-
callback_events?: CallbackEventType[];
|
|
108
|
-
export?: {
|
|
109
|
-
service: 's3';
|
|
110
|
-
bucket: string;
|
|
111
|
-
key_prefix?: string;
|
|
112
|
-
role_arn: string;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// ---------------------------------------------------------------------------
|
|
117
|
-
// Polling options
|
|
118
|
-
// ---------------------------------------------------------------------------
|
|
119
|
-
|
|
120
|
-
export interface WaitOptions {
|
|
121
|
-
/** Poll interval in milliseconds (default: 2000) */
|
|
122
|
-
intervalMs?: number;
|
|
123
|
-
/** Maximum wait time in milliseconds (default: 300000 = 5 min) */
|
|
124
|
-
timeoutMs?: number;
|
|
125
|
-
/** Called after each poll with current status */
|
|
126
|
-
onPoll?: (status: string) => void;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// ---------------------------------------------------------------------------
|
|
130
|
-
// SSE event types (SDK-level typed discriminated union)
|
|
131
|
-
// ---------------------------------------------------------------------------
|
|
132
|
-
|
|
133
|
-
export type GislSseEvent =
|
|
134
|
-
| { event: typeof SseEventType.operation_progress; data: SseOperationProgressData }
|
|
135
|
-
| { event: typeof SseEventType.operation_completed; data: SseOperationCompletedData }
|
|
136
|
-
| { event: typeof SseEventType.operation_failed; data: SseOperationFailedData }
|
|
137
|
-
| { event: typeof SseEventType.job_completed; data: SseJobCompletedData }
|
|
138
|
-
| { event: typeof SseEventType.job_failed; data: SseJobFailedData }
|
|
139
|
-
| { event: typeof SseEventType.workflow_completed; data: SseWorkflowTerminalData }
|
|
140
|
-
| { event: typeof SseEventType.workflow_failed; data: SseWorkflowTerminalData }
|
|
141
|
-
| { event: typeof SseEventType.workflow_partially_failed; data: SseWorkflowTerminalData }
|
|
142
|
-
| { event: string; data: unknown };
|
|
143
|
-
|
|
144
|
-
// ---------------------------------------------------------------------------
|
|
145
|
-
// Upload options
|
|
146
|
-
// ---------------------------------------------------------------------------
|
|
147
|
-
|
|
148
|
-
export interface UploadOptions {
|
|
149
|
-
/** Called with bytes uploaded so far (only for multipart) */
|
|
150
|
-
onProgress?: (uploadedBytes: number, totalBytes: number) => void;
|
|
151
|
-
}
|
package/src/webhook.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
|
-
import { GislError } from './errors.js';
|
|
3
|
-
|
|
4
|
-
const SIGNATURE_PREFIX = 'sha256=';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Verify a GISL webhook signature.
|
|
8
|
-
*
|
|
9
|
-
* @param secret The `webhook_secret` from the workflow creation response.
|
|
10
|
-
* @param signature The value of the `X-GIS-Signature` header.
|
|
11
|
-
* @param body The raw request body as a string or Buffer.
|
|
12
|
-
* @returns `true` if valid.
|
|
13
|
-
* @throws {GislError} if the signature is missing, malformed, or invalid.
|
|
14
|
-
*/
|
|
15
|
-
export function verifyWebhook(
|
|
16
|
-
secret: string,
|
|
17
|
-
signature: string,
|
|
18
|
-
body: string | Buffer,
|
|
19
|
-
): boolean {
|
|
20
|
-
if (!signature.startsWith(SIGNATURE_PREFIX)) {
|
|
21
|
-
throw new GislError(
|
|
22
|
-
`Invalid signature format: expected "${SIGNATURE_PREFIX}<hex>"`,
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const receivedHex = signature.slice(SIGNATURE_PREFIX.length);
|
|
27
|
-
|
|
28
|
-
if (!/^[0-9a-f]{64}$/i.test(receivedHex)) {
|
|
29
|
-
throw new GislError('Webhook signature verification failed');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const expectedHex = createHmac('sha256', secret)
|
|
33
|
-
.update(body)
|
|
34
|
-
.digest('hex');
|
|
35
|
-
|
|
36
|
-
const receivedBuf = Buffer.from(receivedHex, 'hex');
|
|
37
|
-
const expectedBuf = Buffer.from(expectedHex, 'hex');
|
|
38
|
-
|
|
39
|
-
if (receivedBuf.length !== expectedBuf.length) {
|
|
40
|
-
throw new GislError('Webhook signature verification failed');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!timingSafeEqual(receivedBuf, expectedBuf)) {
|
|
44
|
-
throw new GislError('Webhook signature verification failed');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return true;
|
|
48
|
-
}
|