@wefunder/sdk 0.1.0-beta.1 → 0.1.0-beta.11
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/README.md +190 -114
- package/dist/index.cjs +1734 -687
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7070 -1940
- package/dist/index.d.ts +7070 -1940
- package/dist/index.js +1719 -684
- package/dist/index.js.map +1 -1
- package/examples_manifest.json +67 -0
- package/package.json +12 -9
package/dist/index.js
CHANGED
|
@@ -4,8 +4,819 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
|
|
7
|
+
// src/generated/core/bodySerializer.gen.ts
|
|
8
|
+
var jsonBodySerializer = {
|
|
9
|
+
bodySerializer: (body) => JSON.stringify(
|
|
10
|
+
body,
|
|
11
|
+
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
12
|
+
)
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// src/generated/core/params.gen.ts
|
|
16
|
+
var extraPrefixesMap = {
|
|
17
|
+
$body_: "body",
|
|
18
|
+
$headers_: "headers",
|
|
19
|
+
$path_: "path",
|
|
20
|
+
$query_: "query"
|
|
21
|
+
};
|
|
22
|
+
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
23
|
+
|
|
24
|
+
// src/generated/core/serverSentEvents.gen.ts
|
|
25
|
+
function createSseClient({
|
|
26
|
+
onRequest,
|
|
27
|
+
onSseError,
|
|
28
|
+
onSseEvent,
|
|
29
|
+
responseTransformer,
|
|
30
|
+
responseValidator,
|
|
31
|
+
sseDefaultRetryDelay,
|
|
32
|
+
sseMaxRetryAttempts,
|
|
33
|
+
sseMaxRetryDelay,
|
|
34
|
+
sseSleepFn,
|
|
35
|
+
url,
|
|
36
|
+
...options
|
|
37
|
+
}) {
|
|
38
|
+
let lastEventId;
|
|
39
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
40
|
+
const createStream = async function* () {
|
|
41
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
42
|
+
let attempt = 0;
|
|
43
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
44
|
+
while (true) {
|
|
45
|
+
if (signal.aborted) break;
|
|
46
|
+
attempt++;
|
|
47
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
48
|
+
if (lastEventId !== void 0) {
|
|
49
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const requestInit = {
|
|
53
|
+
redirect: "follow",
|
|
54
|
+
...options,
|
|
55
|
+
body: options.serializedBody,
|
|
56
|
+
headers,
|
|
57
|
+
signal
|
|
58
|
+
};
|
|
59
|
+
let request = new Request(url, requestInit);
|
|
60
|
+
if (onRequest) {
|
|
61
|
+
request = await onRequest(url, requestInit);
|
|
62
|
+
}
|
|
63
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
64
|
+
const response = await _fetch(request);
|
|
65
|
+
if (!response.ok)
|
|
66
|
+
throw new Error(
|
|
67
|
+
`SSE failed: ${response.status} ${response.statusText}`
|
|
68
|
+
);
|
|
69
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
70
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
71
|
+
let buffer = "";
|
|
72
|
+
const abortHandler = () => {
|
|
73
|
+
try {
|
|
74
|
+
reader.cancel();
|
|
75
|
+
} catch {
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
signal.addEventListener("abort", abortHandler);
|
|
79
|
+
try {
|
|
80
|
+
while (true) {
|
|
81
|
+
const { done, value } = await reader.read();
|
|
82
|
+
if (done) break;
|
|
83
|
+
buffer += value;
|
|
84
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
85
|
+
const chunks = buffer.split("\n\n");
|
|
86
|
+
buffer = chunks.pop() ?? "";
|
|
87
|
+
for (const chunk of chunks) {
|
|
88
|
+
const lines = chunk.split("\n");
|
|
89
|
+
const dataLines = [];
|
|
90
|
+
let eventName;
|
|
91
|
+
for (const line of lines) {
|
|
92
|
+
if (line.startsWith("data:")) {
|
|
93
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
94
|
+
} else if (line.startsWith("event:")) {
|
|
95
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
96
|
+
} else if (line.startsWith("id:")) {
|
|
97
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
98
|
+
} else if (line.startsWith("retry:")) {
|
|
99
|
+
const parsed = Number.parseInt(
|
|
100
|
+
line.replace(/^retry:\s*/, ""),
|
|
101
|
+
10
|
|
102
|
+
);
|
|
103
|
+
if (!Number.isNaN(parsed)) {
|
|
104
|
+
retryDelay = parsed;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
let data;
|
|
109
|
+
let parsedJson = false;
|
|
110
|
+
if (dataLines.length) {
|
|
111
|
+
const rawData = dataLines.join("\n");
|
|
112
|
+
try {
|
|
113
|
+
data = JSON.parse(rawData);
|
|
114
|
+
parsedJson = true;
|
|
115
|
+
} catch {
|
|
116
|
+
data = rawData;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (parsedJson) {
|
|
120
|
+
if (responseValidator) {
|
|
121
|
+
await responseValidator(data);
|
|
122
|
+
}
|
|
123
|
+
if (responseTransformer) {
|
|
124
|
+
data = await responseTransformer(data);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
onSseEvent?.({
|
|
128
|
+
data,
|
|
129
|
+
event: eventName,
|
|
130
|
+
id: lastEventId,
|
|
131
|
+
retry: retryDelay
|
|
132
|
+
});
|
|
133
|
+
if (dataLines.length) {
|
|
134
|
+
yield data;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} finally {
|
|
139
|
+
signal.removeEventListener("abort", abortHandler);
|
|
140
|
+
reader.releaseLock();
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
onSseError?.(error);
|
|
145
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
const backoff = Math.min(
|
|
149
|
+
retryDelay * 2 ** (attempt - 1),
|
|
150
|
+
sseMaxRetryDelay ?? 3e4
|
|
151
|
+
);
|
|
152
|
+
await sleep(backoff);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const stream = createStream();
|
|
157
|
+
return { stream };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// src/generated/core/pathSerializer.gen.ts
|
|
161
|
+
var separatorArrayExplode = (style) => {
|
|
162
|
+
switch (style) {
|
|
163
|
+
case "label":
|
|
164
|
+
return ".";
|
|
165
|
+
case "matrix":
|
|
166
|
+
return ";";
|
|
167
|
+
case "simple":
|
|
168
|
+
return ",";
|
|
169
|
+
default:
|
|
170
|
+
return "&";
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var separatorArrayNoExplode = (style) => {
|
|
174
|
+
switch (style) {
|
|
175
|
+
case "form":
|
|
176
|
+
return ",";
|
|
177
|
+
case "pipeDelimited":
|
|
178
|
+
return "|";
|
|
179
|
+
case "spaceDelimited":
|
|
180
|
+
return "%20";
|
|
181
|
+
default:
|
|
182
|
+
return ",";
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var separatorObjectExplode = (style) => {
|
|
186
|
+
switch (style) {
|
|
187
|
+
case "label":
|
|
188
|
+
return ".";
|
|
189
|
+
case "matrix":
|
|
190
|
+
return ";";
|
|
191
|
+
case "simple":
|
|
192
|
+
return ",";
|
|
193
|
+
default:
|
|
194
|
+
return "&";
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
var serializeArrayParam = ({
|
|
198
|
+
allowReserved,
|
|
199
|
+
explode,
|
|
200
|
+
name,
|
|
201
|
+
style,
|
|
202
|
+
value
|
|
203
|
+
}) => {
|
|
204
|
+
if (!explode) {
|
|
205
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
206
|
+
switch (style) {
|
|
207
|
+
case "label":
|
|
208
|
+
return `.${joinedValues2}`;
|
|
209
|
+
case "matrix":
|
|
210
|
+
return `;${name}=${joinedValues2}`;
|
|
211
|
+
case "simple":
|
|
212
|
+
return joinedValues2;
|
|
213
|
+
default:
|
|
214
|
+
return `${name}=${joinedValues2}`;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const separator = separatorArrayExplode(style);
|
|
218
|
+
const joinedValues = value.map((v) => {
|
|
219
|
+
if (style === "label" || style === "simple") {
|
|
220
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
221
|
+
}
|
|
222
|
+
return serializePrimitiveParam({
|
|
223
|
+
allowReserved,
|
|
224
|
+
name,
|
|
225
|
+
value: v
|
|
226
|
+
});
|
|
227
|
+
}).join(separator);
|
|
228
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
229
|
+
};
|
|
230
|
+
var serializePrimitiveParam = ({
|
|
231
|
+
allowReserved,
|
|
232
|
+
name,
|
|
233
|
+
value
|
|
234
|
+
}) => {
|
|
235
|
+
if (value === void 0 || value === null) {
|
|
236
|
+
return "";
|
|
237
|
+
}
|
|
238
|
+
if (typeof value === "object") {
|
|
239
|
+
throw new Error(
|
|
240
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
244
|
+
};
|
|
245
|
+
var serializeObjectParam = ({
|
|
246
|
+
allowReserved,
|
|
247
|
+
explode,
|
|
248
|
+
name,
|
|
249
|
+
style,
|
|
250
|
+
value,
|
|
251
|
+
valueOnly
|
|
252
|
+
}) => {
|
|
253
|
+
if (value instanceof Date) {
|
|
254
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
255
|
+
}
|
|
256
|
+
if (style !== "deepObject" && !explode) {
|
|
257
|
+
let values = [];
|
|
258
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
259
|
+
values = [
|
|
260
|
+
...values,
|
|
261
|
+
key,
|
|
262
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
263
|
+
];
|
|
264
|
+
});
|
|
265
|
+
const joinedValues2 = values.join(",");
|
|
266
|
+
switch (style) {
|
|
267
|
+
case "form":
|
|
268
|
+
return `${name}=${joinedValues2}`;
|
|
269
|
+
case "label":
|
|
270
|
+
return `.${joinedValues2}`;
|
|
271
|
+
case "matrix":
|
|
272
|
+
return `;${name}=${joinedValues2}`;
|
|
273
|
+
default:
|
|
274
|
+
return joinedValues2;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const separator = separatorObjectExplode(style);
|
|
278
|
+
const joinedValues = Object.entries(value).map(
|
|
279
|
+
([key, v]) => serializePrimitiveParam({
|
|
280
|
+
allowReserved,
|
|
281
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
282
|
+
value: v
|
|
283
|
+
})
|
|
284
|
+
).join(separator);
|
|
285
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/generated/core/utils.gen.ts
|
|
289
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
290
|
+
var defaultPathSerializer = ({
|
|
291
|
+
path,
|
|
292
|
+
url: _url
|
|
293
|
+
}) => {
|
|
294
|
+
let url = _url;
|
|
295
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
296
|
+
if (matches) {
|
|
297
|
+
for (const match of matches) {
|
|
298
|
+
let explode = false;
|
|
299
|
+
let name = match.substring(1, match.length - 1);
|
|
300
|
+
let style = "simple";
|
|
301
|
+
if (name.endsWith("*")) {
|
|
302
|
+
explode = true;
|
|
303
|
+
name = name.substring(0, name.length - 1);
|
|
304
|
+
}
|
|
305
|
+
if (name.startsWith(".")) {
|
|
306
|
+
name = name.substring(1);
|
|
307
|
+
style = "label";
|
|
308
|
+
} else if (name.startsWith(";")) {
|
|
309
|
+
name = name.substring(1);
|
|
310
|
+
style = "matrix";
|
|
311
|
+
}
|
|
312
|
+
const value = path[name];
|
|
313
|
+
if (value === void 0 || value === null) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (Array.isArray(value)) {
|
|
317
|
+
url = url.replace(
|
|
318
|
+
match,
|
|
319
|
+
serializeArrayParam({ explode, name, style, value })
|
|
320
|
+
);
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (typeof value === "object") {
|
|
324
|
+
url = url.replace(
|
|
325
|
+
match,
|
|
326
|
+
serializeObjectParam({
|
|
327
|
+
explode,
|
|
328
|
+
name,
|
|
329
|
+
style,
|
|
330
|
+
value,
|
|
331
|
+
valueOnly: true
|
|
332
|
+
})
|
|
333
|
+
);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (style === "matrix") {
|
|
337
|
+
url = url.replace(
|
|
338
|
+
match,
|
|
339
|
+
`;${serializePrimitiveParam({
|
|
340
|
+
name,
|
|
341
|
+
value
|
|
342
|
+
})}`
|
|
343
|
+
);
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const replaceValue = encodeURIComponent(
|
|
347
|
+
style === "label" ? `.${value}` : value
|
|
348
|
+
);
|
|
349
|
+
url = url.replace(match, replaceValue);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return url;
|
|
353
|
+
};
|
|
354
|
+
var getUrl = ({
|
|
355
|
+
baseUrl,
|
|
356
|
+
path,
|
|
357
|
+
query,
|
|
358
|
+
querySerializer,
|
|
359
|
+
url: _url
|
|
360
|
+
}) => {
|
|
361
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
362
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
363
|
+
if (path) {
|
|
364
|
+
url = defaultPathSerializer({ path, url });
|
|
365
|
+
}
|
|
366
|
+
let search = query ? querySerializer(query) : "";
|
|
367
|
+
if (search.startsWith("?")) {
|
|
368
|
+
search = search.substring(1);
|
|
369
|
+
}
|
|
370
|
+
if (search) {
|
|
371
|
+
url += `?${search}`;
|
|
372
|
+
}
|
|
373
|
+
return url;
|
|
374
|
+
};
|
|
375
|
+
function getValidRequestBody(options) {
|
|
376
|
+
const hasBody = options.body !== void 0;
|
|
377
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
378
|
+
if (isSerializedBody) {
|
|
379
|
+
if ("serializedBody" in options) {
|
|
380
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
381
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
382
|
+
}
|
|
383
|
+
return options.body !== "" ? options.body : null;
|
|
384
|
+
}
|
|
385
|
+
if (hasBody) {
|
|
386
|
+
return options.body;
|
|
387
|
+
}
|
|
388
|
+
return void 0;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/generated/core/auth.gen.ts
|
|
392
|
+
var getAuthToken = async (auth, callback) => {
|
|
393
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
394
|
+
if (!token) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (auth.scheme === "bearer") {
|
|
398
|
+
return `Bearer ${token}`;
|
|
399
|
+
}
|
|
400
|
+
if (auth.scheme === "basic") {
|
|
401
|
+
return `Basic ${btoa(token)}`;
|
|
402
|
+
}
|
|
403
|
+
return token;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// src/generated/client/utils.gen.ts
|
|
407
|
+
var createQuerySerializer = ({
|
|
408
|
+
parameters = {},
|
|
409
|
+
...args
|
|
410
|
+
} = {}) => {
|
|
411
|
+
const querySerializer = (queryParams) => {
|
|
412
|
+
const search = [];
|
|
413
|
+
if (queryParams && typeof queryParams === "object") {
|
|
414
|
+
for (const name in queryParams) {
|
|
415
|
+
const value = queryParams[name];
|
|
416
|
+
if (value === void 0 || value === null) {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const options = parameters[name] || args;
|
|
420
|
+
if (Array.isArray(value)) {
|
|
421
|
+
const serializedArray = serializeArrayParam({
|
|
422
|
+
allowReserved: options.allowReserved,
|
|
423
|
+
explode: true,
|
|
424
|
+
name,
|
|
425
|
+
style: "form",
|
|
426
|
+
value,
|
|
427
|
+
...options.array
|
|
428
|
+
});
|
|
429
|
+
if (serializedArray) search.push(serializedArray);
|
|
430
|
+
} else if (typeof value === "object") {
|
|
431
|
+
const serializedObject = serializeObjectParam({
|
|
432
|
+
allowReserved: options.allowReserved,
|
|
433
|
+
explode: true,
|
|
434
|
+
name,
|
|
435
|
+
style: "deepObject",
|
|
436
|
+
value,
|
|
437
|
+
...options.object
|
|
438
|
+
});
|
|
439
|
+
if (serializedObject) search.push(serializedObject);
|
|
440
|
+
} else {
|
|
441
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
442
|
+
allowReserved: options.allowReserved,
|
|
443
|
+
name,
|
|
444
|
+
value
|
|
445
|
+
});
|
|
446
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return search.join("&");
|
|
451
|
+
};
|
|
452
|
+
return querySerializer;
|
|
453
|
+
};
|
|
454
|
+
var getParseAs = (contentType) => {
|
|
455
|
+
if (!contentType) {
|
|
456
|
+
return "stream";
|
|
457
|
+
}
|
|
458
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
459
|
+
if (!cleanContent) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
463
|
+
return "json";
|
|
464
|
+
}
|
|
465
|
+
if (cleanContent === "multipart/form-data") {
|
|
466
|
+
return "formData";
|
|
467
|
+
}
|
|
468
|
+
if (["application/", "audio/", "image/", "video/"].some(
|
|
469
|
+
(type) => cleanContent.startsWith(type)
|
|
470
|
+
)) {
|
|
471
|
+
return "blob";
|
|
472
|
+
}
|
|
473
|
+
if (cleanContent.startsWith("text/")) {
|
|
474
|
+
return "text";
|
|
475
|
+
}
|
|
476
|
+
return;
|
|
477
|
+
};
|
|
478
|
+
var checkForExistence = (options, name) => {
|
|
479
|
+
if (!name) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
return false;
|
|
486
|
+
};
|
|
487
|
+
async function setAuthParams(options) {
|
|
488
|
+
for (const auth of options.security ?? []) {
|
|
489
|
+
if (checkForExistence(options, auth.name)) {
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
const token = await getAuthToken(auth, options.auth);
|
|
493
|
+
if (!token) {
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
const name = auth.name ?? "Authorization";
|
|
497
|
+
switch (auth.in) {
|
|
498
|
+
case "query":
|
|
499
|
+
if (!options.query) {
|
|
500
|
+
options.query = {};
|
|
501
|
+
}
|
|
502
|
+
options.query[name] = token;
|
|
503
|
+
break;
|
|
504
|
+
case "cookie":
|
|
505
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
506
|
+
break;
|
|
507
|
+
case "header":
|
|
508
|
+
default:
|
|
509
|
+
options.headers.set(name, token);
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
var buildUrl = (options) => getUrl({
|
|
515
|
+
baseUrl: options.baseUrl,
|
|
516
|
+
path: options.path,
|
|
517
|
+
query: options.query,
|
|
518
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
519
|
+
url: options.url
|
|
520
|
+
});
|
|
521
|
+
var mergeConfigs = (a, b) => {
|
|
522
|
+
const config = { ...a, ...b };
|
|
523
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
524
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
525
|
+
}
|
|
526
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
527
|
+
return config;
|
|
528
|
+
};
|
|
529
|
+
var headersEntries = (headers) => {
|
|
530
|
+
const entries = [];
|
|
531
|
+
headers.forEach((value, key) => {
|
|
532
|
+
entries.push([key, value]);
|
|
533
|
+
});
|
|
534
|
+
return entries;
|
|
535
|
+
};
|
|
536
|
+
var mergeHeaders = (...headers) => {
|
|
537
|
+
const mergedHeaders = new Headers();
|
|
538
|
+
for (const header of headers) {
|
|
539
|
+
if (!header) {
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
543
|
+
for (const [key, value] of iterator) {
|
|
544
|
+
if (value === null) {
|
|
545
|
+
mergedHeaders.delete(key);
|
|
546
|
+
} else if (Array.isArray(value)) {
|
|
547
|
+
for (const v of value) {
|
|
548
|
+
mergedHeaders.append(key, v);
|
|
549
|
+
}
|
|
550
|
+
} else if (value !== void 0) {
|
|
551
|
+
mergedHeaders.set(
|
|
552
|
+
key,
|
|
553
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return mergedHeaders;
|
|
559
|
+
};
|
|
560
|
+
var Interceptors = class {
|
|
561
|
+
fns = [];
|
|
562
|
+
clear() {
|
|
563
|
+
this.fns = [];
|
|
564
|
+
}
|
|
565
|
+
eject(id) {
|
|
566
|
+
const index = this.getInterceptorIndex(id);
|
|
567
|
+
if (this.fns[index]) {
|
|
568
|
+
this.fns[index] = null;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
exists(id) {
|
|
572
|
+
const index = this.getInterceptorIndex(id);
|
|
573
|
+
return Boolean(this.fns[index]);
|
|
574
|
+
}
|
|
575
|
+
getInterceptorIndex(id) {
|
|
576
|
+
if (typeof id === "number") {
|
|
577
|
+
return this.fns[id] ? id : -1;
|
|
578
|
+
}
|
|
579
|
+
return this.fns.indexOf(id);
|
|
580
|
+
}
|
|
581
|
+
update(id, fn) {
|
|
582
|
+
const index = this.getInterceptorIndex(id);
|
|
583
|
+
if (this.fns[index]) {
|
|
584
|
+
this.fns[index] = fn;
|
|
585
|
+
return id;
|
|
586
|
+
}
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
use(fn) {
|
|
590
|
+
this.fns.push(fn);
|
|
591
|
+
return this.fns.length - 1;
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
var createInterceptors = () => ({
|
|
595
|
+
error: new Interceptors(),
|
|
596
|
+
request: new Interceptors(),
|
|
597
|
+
response: new Interceptors()
|
|
598
|
+
});
|
|
599
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
600
|
+
allowReserved: false,
|
|
601
|
+
array: {
|
|
602
|
+
explode: true,
|
|
603
|
+
style: "form"
|
|
604
|
+
},
|
|
605
|
+
object: {
|
|
606
|
+
explode: true,
|
|
607
|
+
style: "deepObject"
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
var defaultHeaders = {
|
|
611
|
+
"Content-Type": "application/json"
|
|
612
|
+
};
|
|
613
|
+
var createConfig = (override = {}) => ({
|
|
614
|
+
...jsonBodySerializer,
|
|
615
|
+
headers: defaultHeaders,
|
|
616
|
+
parseAs: "auto",
|
|
617
|
+
querySerializer: defaultQuerySerializer,
|
|
618
|
+
...override
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
// src/generated/client/client.gen.ts
|
|
622
|
+
var createClient = (config = {}) => {
|
|
623
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
624
|
+
const getConfig = () => ({ ..._config });
|
|
625
|
+
const setConfig = (config2) => {
|
|
626
|
+
_config = mergeConfigs(_config, config2);
|
|
627
|
+
return getConfig();
|
|
628
|
+
};
|
|
629
|
+
const interceptors = createInterceptors();
|
|
630
|
+
const beforeRequest = async (options) => {
|
|
631
|
+
const opts = {
|
|
632
|
+
..._config,
|
|
633
|
+
...options,
|
|
634
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
635
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
636
|
+
serializedBody: void 0
|
|
637
|
+
};
|
|
638
|
+
if (opts.security) {
|
|
639
|
+
await setAuthParams(opts);
|
|
640
|
+
}
|
|
641
|
+
if (opts.requestValidator) {
|
|
642
|
+
await opts.requestValidator(opts);
|
|
643
|
+
}
|
|
644
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
645
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
646
|
+
}
|
|
647
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
648
|
+
opts.headers.delete("Content-Type");
|
|
649
|
+
}
|
|
650
|
+
const resolvedOpts = opts;
|
|
651
|
+
const url = buildUrl(resolvedOpts);
|
|
652
|
+
return { opts: resolvedOpts, url };
|
|
653
|
+
};
|
|
654
|
+
const request = async (options) => {
|
|
655
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
656
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
657
|
+
let request2;
|
|
658
|
+
let response;
|
|
659
|
+
try {
|
|
660
|
+
const { opts, url } = await beforeRequest(options);
|
|
661
|
+
const requestInit = {
|
|
662
|
+
redirect: "follow",
|
|
663
|
+
...opts,
|
|
664
|
+
body: getValidRequestBody(opts)
|
|
665
|
+
};
|
|
666
|
+
request2 = new Request(url, requestInit);
|
|
667
|
+
for (const fn of interceptors.request.fns) {
|
|
668
|
+
if (fn) {
|
|
669
|
+
request2 = await fn(request2, opts);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const _fetch = opts.fetch;
|
|
673
|
+
response = await _fetch(request2);
|
|
674
|
+
for (const fn of interceptors.response.fns) {
|
|
675
|
+
if (fn) {
|
|
676
|
+
response = await fn(response, request2, opts);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const result = {
|
|
680
|
+
request: request2,
|
|
681
|
+
response
|
|
682
|
+
};
|
|
683
|
+
if (response.ok) {
|
|
684
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
685
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
686
|
+
let emptyData;
|
|
687
|
+
switch (parseAs) {
|
|
688
|
+
case "arrayBuffer":
|
|
689
|
+
case "blob":
|
|
690
|
+
case "text":
|
|
691
|
+
emptyData = await response[parseAs]();
|
|
692
|
+
break;
|
|
693
|
+
case "formData":
|
|
694
|
+
emptyData = new FormData();
|
|
695
|
+
break;
|
|
696
|
+
case "stream":
|
|
697
|
+
emptyData = response.body;
|
|
698
|
+
break;
|
|
699
|
+
case "json":
|
|
700
|
+
default:
|
|
701
|
+
emptyData = {};
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
705
|
+
data: emptyData,
|
|
706
|
+
...result
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
let data;
|
|
710
|
+
switch (parseAs) {
|
|
711
|
+
case "arrayBuffer":
|
|
712
|
+
case "blob":
|
|
713
|
+
case "formData":
|
|
714
|
+
case "text":
|
|
715
|
+
data = await response[parseAs]();
|
|
716
|
+
break;
|
|
717
|
+
case "json": {
|
|
718
|
+
const text = await response.text();
|
|
719
|
+
data = text ? JSON.parse(text) : {};
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
case "stream":
|
|
723
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
724
|
+
data: response.body,
|
|
725
|
+
...result
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
if (parseAs === "json") {
|
|
729
|
+
if (opts.responseValidator) {
|
|
730
|
+
await opts.responseValidator(data);
|
|
731
|
+
}
|
|
732
|
+
if (opts.responseTransformer) {
|
|
733
|
+
data = await opts.responseTransformer(data);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return opts.responseStyle === "data" ? data : {
|
|
737
|
+
data,
|
|
738
|
+
...result
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
const textError = await response.text();
|
|
742
|
+
let jsonError;
|
|
743
|
+
try {
|
|
744
|
+
jsonError = JSON.parse(textError);
|
|
745
|
+
} catch {
|
|
746
|
+
}
|
|
747
|
+
throw jsonError ?? textError;
|
|
748
|
+
} catch (error) {
|
|
749
|
+
let finalError = error;
|
|
750
|
+
for (const fn of interceptors.error.fns) {
|
|
751
|
+
if (fn) {
|
|
752
|
+
finalError = await fn(
|
|
753
|
+
finalError,
|
|
754
|
+
response,
|
|
755
|
+
request2,
|
|
756
|
+
options
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
finalError = finalError || {};
|
|
761
|
+
if (throwOnError) {
|
|
762
|
+
throw finalError;
|
|
763
|
+
}
|
|
764
|
+
return responseStyle === "data" ? void 0 : {
|
|
765
|
+
error: finalError,
|
|
766
|
+
request: request2,
|
|
767
|
+
response
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
772
|
+
const makeSseFn = (method) => async (options) => {
|
|
773
|
+
const { opts, url } = await beforeRequest(options);
|
|
774
|
+
return createSseClient({
|
|
775
|
+
...opts,
|
|
776
|
+
body: opts.body,
|
|
777
|
+
method,
|
|
778
|
+
onRequest: async (url2, init) => {
|
|
779
|
+
let request2 = new Request(url2, init);
|
|
780
|
+
for (const fn of interceptors.request.fns) {
|
|
781
|
+
if (fn) {
|
|
782
|
+
request2 = await fn(request2, opts);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return request2;
|
|
786
|
+
},
|
|
787
|
+
serializedBody: getValidRequestBody(opts),
|
|
788
|
+
url
|
|
789
|
+
});
|
|
790
|
+
};
|
|
791
|
+
const _buildUrl = (options) => buildUrl({ ..._config, ...options });
|
|
792
|
+
return {
|
|
793
|
+
buildUrl: _buildUrl,
|
|
794
|
+
connect: makeMethodFn("CONNECT"),
|
|
795
|
+
delete: makeMethodFn("DELETE"),
|
|
796
|
+
get: makeMethodFn("GET"),
|
|
797
|
+
getConfig,
|
|
798
|
+
head: makeMethodFn("HEAD"),
|
|
799
|
+
interceptors,
|
|
800
|
+
options: makeMethodFn("OPTIONS"),
|
|
801
|
+
patch: makeMethodFn("PATCH"),
|
|
802
|
+
post: makeMethodFn("POST"),
|
|
803
|
+
put: makeMethodFn("PUT"),
|
|
804
|
+
request,
|
|
805
|
+
setConfig,
|
|
806
|
+
sse: {
|
|
807
|
+
connect: makeSseFn("CONNECT"),
|
|
808
|
+
delete: makeSseFn("DELETE"),
|
|
809
|
+
get: makeSseFn("GET"),
|
|
810
|
+
head: makeSseFn("HEAD"),
|
|
811
|
+
options: makeSseFn("OPTIONS"),
|
|
812
|
+
patch: makeSseFn("PATCH"),
|
|
813
|
+
post: makeSseFn("POST"),
|
|
814
|
+
put: makeSseFn("PUT"),
|
|
815
|
+
trace: makeSseFn("TRACE")
|
|
816
|
+
},
|
|
817
|
+
trace: makeMethodFn("TRACE")
|
|
818
|
+
};
|
|
819
|
+
};
|
|
9
820
|
|
|
10
821
|
// src/http.ts
|
|
11
822
|
var IDEMPOTENT = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
@@ -27,13 +838,6 @@ function backoffMs(attempt, opts, random) {
|
|
|
27
838
|
const jitter = exp * 0.5 * random();
|
|
28
839
|
return Math.min(exp + jitter, opts.maxDelayMs);
|
|
29
840
|
}
|
|
30
|
-
function withBearer(input, init, token) {
|
|
31
|
-
const headers = new Headers(
|
|
32
|
-
init?.headers ?? (input instanceof Request ? input.headers : void 0)
|
|
33
|
-
);
|
|
34
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
35
|
-
return { ...init, headers };
|
|
36
|
-
}
|
|
37
841
|
function createFetch(deps) {
|
|
38
842
|
const baseFetch = deps.fetch ?? fetch;
|
|
39
843
|
const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
@@ -47,21 +851,37 @@ function createFetch(deps) {
|
|
|
47
851
|
return async function wrappedFetch(input, init) {
|
|
48
852
|
const method = methodOf(input, init);
|
|
49
853
|
const idempotent = IDEMPOTENT.has(method);
|
|
854
|
+
const isRequest = input instanceof Request;
|
|
50
855
|
let refreshed = false;
|
|
51
856
|
let attempt = 0;
|
|
857
|
+
let retryToken;
|
|
858
|
+
const dispatch = (authToken) => {
|
|
859
|
+
if (isRequest) {
|
|
860
|
+
const fresh = input.clone();
|
|
861
|
+
if (authToken === void 0) return baseFetch(fresh);
|
|
862
|
+
const headers = new Headers(fresh.headers);
|
|
863
|
+
headers.set("Authorization", `Bearer ${authToken}`);
|
|
864
|
+
return baseFetch(new Request(fresh, { headers }));
|
|
865
|
+
}
|
|
866
|
+
const nextInit = authToken === void 0 ? init : (() => {
|
|
867
|
+
const headers = new Headers(init?.headers);
|
|
868
|
+
headers.set("Authorization", `Bearer ${authToken}`);
|
|
869
|
+
return { ...init, headers };
|
|
870
|
+
})();
|
|
871
|
+
return baseFetch(input, nextInit);
|
|
872
|
+
};
|
|
52
873
|
for (; ; ) {
|
|
53
874
|
let response;
|
|
54
875
|
let networkError;
|
|
55
876
|
try {
|
|
56
|
-
response = await
|
|
877
|
+
response = await dispatch(retryToken);
|
|
57
878
|
} catch (err) {
|
|
58
879
|
networkError = err;
|
|
59
880
|
}
|
|
60
|
-
|
|
61
|
-
if (response?.status === 401 && !refreshed && replayable && deps.tokenManager?.canRefresh) {
|
|
881
|
+
if (response?.status === 401 && !refreshed && deps.tokenManager?.canRefresh) {
|
|
62
882
|
refreshed = true;
|
|
63
883
|
const next = await deps.tokenManager.refresh();
|
|
64
|
-
|
|
884
|
+
retryToken = next.accessToken;
|
|
65
885
|
continue;
|
|
66
886
|
}
|
|
67
887
|
if (response?.status === 429 && attempt < retry.maxRetries) {
|
|
@@ -84,10 +904,11 @@ function createFetch(deps) {
|
|
|
84
904
|
// src/oauth.ts
|
|
85
905
|
import { createHash, randomBytes } from "crypto";
|
|
86
906
|
var DEFAULT_AUTHORIZE_BASE_URL = "https://wefunder.com/oauth";
|
|
87
|
-
var
|
|
907
|
+
var SANDBOX_AUTHORIZE_BASE_URL = "https://oauth.wefunder-sandbox.com/oauth";
|
|
908
|
+
var DEFAULT_TOKEN_BASE_URL = "https://api.wefunder.com/oauth";
|
|
88
909
|
var DEFAULT_OAUTH_BASE_URL = DEFAULT_AUTHORIZE_BASE_URL;
|
|
89
|
-
function
|
|
90
|
-
return
|
|
910
|
+
function defaultAuthorizeBase(clientId) {
|
|
911
|
+
return clientId.startsWith("pk_test_") ? SANDBOX_AUTHORIZE_BASE_URL : DEFAULT_AUTHORIZE_BASE_URL;
|
|
91
912
|
}
|
|
92
913
|
function resolveTokenBase(o) {
|
|
93
914
|
return o.tokenBaseUrl ?? o.oauthBaseUrl ?? DEFAULT_TOKEN_BASE_URL;
|
|
@@ -127,7 +948,7 @@ function generatePkce() {
|
|
|
127
948
|
return { codeVerifier, codeChallenge, codeChallengeMethod: "S256" };
|
|
128
949
|
}
|
|
129
950
|
function createAuthorizationUrl(opts) {
|
|
130
|
-
const base =
|
|
951
|
+
const base = opts.authorizeBaseUrl ?? opts.oauthBaseUrl ?? defaultAuthorizeBase(opts.clientId);
|
|
131
952
|
const q = new URLSearchParams({
|
|
132
953
|
response_type: "code",
|
|
133
954
|
client_id: opts.clientId,
|
|
@@ -201,6 +1022,20 @@ var WefunderAuthError = class extends WefunderError {
|
|
|
201
1022
|
};
|
|
202
1023
|
|
|
203
1024
|
// src/token-manager.ts
|
|
1025
|
+
var WefunderTokenPersistenceError = class extends Error {
|
|
1026
|
+
tokens;
|
|
1027
|
+
constructor(tokens, cause) {
|
|
1028
|
+
super(
|
|
1029
|
+
`Token store failed to save the rotated token set: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
1030
|
+
{ cause }
|
|
1031
|
+
);
|
|
1032
|
+
this.name = "WefunderTokenPersistenceError";
|
|
1033
|
+
this.tokens = tokens;
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
function sameTokenSet(a, b) {
|
|
1037
|
+
return a.accessToken === b.accessToken && a.refreshToken === b.refreshToken;
|
|
1038
|
+
}
|
|
204
1039
|
var TokenManager = class {
|
|
205
1040
|
#tokens;
|
|
206
1041
|
#clientId;
|
|
@@ -213,6 +1048,7 @@ var TokenManager = class {
|
|
|
213
1048
|
#now;
|
|
214
1049
|
#leeway;
|
|
215
1050
|
#inflight;
|
|
1051
|
+
#pending;
|
|
216
1052
|
constructor(opts) {
|
|
217
1053
|
this.#tokens = opts.tokens;
|
|
218
1054
|
this.#clientId = opts.clientId;
|
|
@@ -225,15 +1061,40 @@ var TokenManager = class {
|
|
|
225
1061
|
this.#now = opts.now ?? Date.now;
|
|
226
1062
|
this.#leeway = opts.expiryLeewayMs ?? 3e4;
|
|
227
1063
|
}
|
|
1064
|
+
/** The durable, in-use token set. A rotated set that could not be persisted sits in `pendingTokens`. */
|
|
228
1065
|
get current() {
|
|
229
1066
|
return this.#tokens;
|
|
230
1067
|
}
|
|
231
1068
|
/** True if the manager can recover an expired token (rotate a refresh token or re-mint). */
|
|
232
1069
|
get canRefresh() {
|
|
233
|
-
return Boolean(
|
|
1070
|
+
return Boolean(
|
|
1071
|
+
this.#tokens.refreshToken && this.#clientId || this.#reMint
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
/** A rotated set awaiting a successful `store.save` (see `WefunderTokenPersistenceError`). */
|
|
1075
|
+
get pendingTokens() {
|
|
1076
|
+
return this.#pending;
|
|
234
1077
|
}
|
|
235
|
-
/**
|
|
1078
|
+
/**
|
|
1079
|
+
* Tell the manager you persisted `tokens` (the set from a `WefunderTokenPersistenceError`)
|
|
1080
|
+
* yourself. Publishes it only if it is still the pending set — a stale acknowledgment (the
|
|
1081
|
+
* manager has since rotated again) is a no-op and returns false, so an older save can never
|
|
1082
|
+
* publish a newer, unsaved set.
|
|
1083
|
+
*/
|
|
1084
|
+
async markPersisted(tokens) {
|
|
1085
|
+
const pending = this.#pending;
|
|
1086
|
+
if (!pending || !sameTokenSet(pending, tokens)) return false;
|
|
1087
|
+
this.#pending = void 0;
|
|
1088
|
+
this.#tokens = pending;
|
|
1089
|
+
return true;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Returns a valid access token, refreshing proactively if it's expired/near-expiry. If a
|
|
1093
|
+
* rotated set is pending persistence, the save is retried first — no request uses an
|
|
1094
|
+
* undurable token.
|
|
1095
|
+
*/
|
|
236
1096
|
async getAccessToken() {
|
|
1097
|
+
if (this.#pending) await this.refresh();
|
|
237
1098
|
const { expiresAt } = this.#tokens;
|
|
238
1099
|
if (expiresAt !== void 0 && this.#now() >= expiresAt - this.#leeway && this.canRefresh) {
|
|
239
1100
|
await this.refresh();
|
|
@@ -247,6 +1108,14 @@ var TokenManager = class {
|
|
|
247
1108
|
*/
|
|
248
1109
|
async refresh() {
|
|
249
1110
|
if (this.#inflight) return this.#inflight;
|
|
1111
|
+
if (this.#pending) {
|
|
1112
|
+
this.#inflight = this.#publishPending();
|
|
1113
|
+
try {
|
|
1114
|
+
return await this.#inflight;
|
|
1115
|
+
} finally {
|
|
1116
|
+
this.#inflight = void 0;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
250
1119
|
const strategy = this.#recoveryStrategy();
|
|
251
1120
|
if (!strategy) {
|
|
252
1121
|
throw new WefunderAuthError(
|
|
@@ -254,11 +1123,8 @@ var TokenManager = class {
|
|
|
254
1123
|
);
|
|
255
1124
|
}
|
|
256
1125
|
this.#inflight = (async () => {
|
|
257
|
-
|
|
258
|
-
this.#
|
|
259
|
-
await this.#store?.save(next);
|
|
260
|
-
await this.#onTokenRefresh?.(next);
|
|
261
|
-
return next;
|
|
1126
|
+
this.#pending = await strategy();
|
|
1127
|
+
return this.#publishPending();
|
|
262
1128
|
})();
|
|
263
1129
|
try {
|
|
264
1130
|
return await this.#inflight;
|
|
@@ -266,6 +1132,22 @@ var TokenManager = class {
|
|
|
266
1132
|
this.#inflight = void 0;
|
|
267
1133
|
}
|
|
268
1134
|
}
|
|
1135
|
+
// Persist BEFORE publishing: no caller may use the rotated token until it is durable, and a
|
|
1136
|
+
// failed save must not leave the process working in memory but unable to reconnect after a
|
|
1137
|
+
// restart. On failure the set stays pending and WefunderTokenPersistenceError is thrown; the
|
|
1138
|
+
// next call retries the save.
|
|
1139
|
+
async #publishPending() {
|
|
1140
|
+
const tokens = this.#pending;
|
|
1141
|
+
try {
|
|
1142
|
+
await this.#store?.save(tokens);
|
|
1143
|
+
await this.#onTokenRefresh?.(tokens);
|
|
1144
|
+
} catch (err) {
|
|
1145
|
+
throw new WefunderTokenPersistenceError(tokens, err);
|
|
1146
|
+
}
|
|
1147
|
+
this.#pending = void 0;
|
|
1148
|
+
this.#tokens = tokens;
|
|
1149
|
+
return tokens;
|
|
1150
|
+
}
|
|
269
1151
|
// Pick the recovery strategy: refresh_token rotation, else cc re-mint, else none.
|
|
270
1152
|
#recoveryStrategy() {
|
|
271
1153
|
const refreshTokenValue = this.#tokens.refreshToken;
|
|
@@ -315,21 +1197,36 @@ var sdk_gen_exports = {};
|
|
|
315
1197
|
__export(sdk_gen_exports, {
|
|
316
1198
|
approveSyndicateMember: () => approveSyndicateMember,
|
|
317
1199
|
closeSyndicateDeal: () => closeSyndicateDeal,
|
|
1200
|
+
createInstallation: () => createInstallation,
|
|
1201
|
+
createInstallationToken: () => createInstallationToken,
|
|
318
1202
|
createIntent: () => createIntent,
|
|
319
1203
|
createPartnerInvite: () => createPartnerInvite,
|
|
1204
|
+
createWebhookEndpoint: () => createWebhookEndpoint,
|
|
320
1205
|
createWebhookSubscription: () => createWebhookSubscription,
|
|
1206
|
+
deleteWebhookEndpoint: () => deleteWebhookEndpoint,
|
|
321
1207
|
deleteWebhookSubscription: () => deleteWebhookSubscription,
|
|
322
1208
|
demoteSyndicateMember: () => demoteSyndicateMember,
|
|
323
1209
|
exportSyndicateMembersCsv: () => exportSyndicateMembersCsv,
|
|
324
1210
|
finalizeSyndicateDeal: () => finalizeSyndicateDeal,
|
|
1211
|
+
followCompany: () => followCompany,
|
|
325
1212
|
getAttributionMe: () => getAttributionMe,
|
|
326
1213
|
getAttributionStats: () => getAttributionStats,
|
|
1214
|
+
getCompany: () => getCompany,
|
|
1215
|
+
getCompanyDisclosures: () => getCompanyDisclosures,
|
|
1216
|
+
getCompanyPitch: () => getCompanyPitch,
|
|
1217
|
+
getCompanyUpdate: () => getCompanyUpdate,
|
|
327
1218
|
getCurrentUser: () => getCurrentUser,
|
|
1219
|
+
getInstallation: () => getInstallation,
|
|
328
1220
|
getIntent: () => getIntent,
|
|
1221
|
+
getInvestment: () => getInvestment,
|
|
329
1222
|
getOffering: () => getOffering,
|
|
1223
|
+
getOfferingStats: () => getOfferingStats,
|
|
1224
|
+
getPortfolio: () => getPortfolio,
|
|
330
1225
|
getSyndicate: () => getSyndicate,
|
|
331
1226
|
getSyndicateDeal: () => getSyndicateDeal,
|
|
1227
|
+
getSyndicatePortfolio: () => getSyndicatePortfolio,
|
|
332
1228
|
getSyndicateStatistics: () => getSyndicateStatistics,
|
|
1229
|
+
getWebhookEndpoint: () => getWebhookEndpoint,
|
|
333
1230
|
getWebhookSubscription: () => getWebhookSubscription,
|
|
334
1231
|
hideSyndicateMember: () => hideSyndicateMember,
|
|
335
1232
|
inviteSyndicateMember: () => inviteSyndicateMember,
|
|
@@ -337,19 +1234,31 @@ __export(sdk_gen_exports, {
|
|
|
337
1234
|
listAttributedInvestments: () => listAttributedInvestments,
|
|
338
1235
|
listAttributionCampaigns: () => listAttributionCampaigns,
|
|
339
1236
|
listCampaigns: () => listCampaigns,
|
|
1237
|
+
listCompanyInvestmentChanges: () => listCompanyInvestmentChanges,
|
|
1238
|
+
listCompanyQuestions: () => listCompanyQuestions,
|
|
1239
|
+
listCompanyUpdates: () => listCompanyUpdates,
|
|
340
1240
|
listConnectedApps: () => listConnectedApps,
|
|
1241
|
+
listEligibleInstallTargets: () => listEligibleInstallTargets,
|
|
1242
|
+
listFollowedCompanies: () => listFollowedCompanies,
|
|
1243
|
+
listInstallations: () => listInstallations,
|
|
341
1244
|
listIntents: () => listIntents,
|
|
342
1245
|
listInvestments: () => listInvestments,
|
|
1246
|
+
listMyCompanies: () => listMyCompanies,
|
|
343
1247
|
listOfferings: () => listOfferings,
|
|
344
1248
|
listPartnerInvites: () => listPartnerInvites,
|
|
1249
|
+
listPortfolioPositions: () => listPortfolioPositions,
|
|
345
1250
|
listSyndicateDealInvestors: () => listSyndicateDealInvestors,
|
|
346
1251
|
listSyndicateDeals: () => listSyndicateDeals,
|
|
347
1252
|
listSyndicateMemberInvestments: () => listSyndicateMemberInvestments,
|
|
348
1253
|
listSyndicateMembers: () => listSyndicateMembers,
|
|
1254
|
+
listSyndicatePortfolioPositions: () => listSyndicatePortfolioPositions,
|
|
349
1255
|
listSyndicates: () => listSyndicates,
|
|
1256
|
+
listWebhookEndpoints: () => listWebhookEndpoints,
|
|
350
1257
|
listWebhookSubscriptions: () => listWebhookSubscriptions,
|
|
1258
|
+
previewIntent: () => previewIntent,
|
|
351
1259
|
promoteSyndicateMember: () => promoteSyndicateMember,
|
|
352
1260
|
reactivateWebhookSubscription: () => reactivateWebhookSubscription,
|
|
1261
|
+
reenableWebhookEndpoint: () => reenableWebhookEndpoint,
|
|
353
1262
|
regenerateWebhookSecret: () => regenerateWebhookSecret,
|
|
354
1263
|
registerAsPartner: () => registerAsPartner,
|
|
355
1264
|
removeSyndicateMember: () => removeSyndicateMember,
|
|
@@ -357,628 +1266,500 @@ __export(sdk_gen_exports, {
|
|
|
357
1266
|
resendSyndicateInvite: () => resendSyndicateInvite,
|
|
358
1267
|
restoreSyndicateMember: () => restoreSyndicateMember,
|
|
359
1268
|
revokeConnectedApp: () => revokeConnectedApp,
|
|
1269
|
+
revokeInstallation: () => revokeInstallation,
|
|
360
1270
|
revokePartnerInvite: () => revokePartnerInvite,
|
|
1271
|
+
rotateWebhookEndpointSecret: () => rotateWebhookEndpointSecret,
|
|
1272
|
+
searchCompanies: () => searchCompanies,
|
|
1273
|
+
testWebhookEndpoint: () => testWebhookEndpoint,
|
|
361
1274
|
testWebhookSubscription: () => testWebhookSubscription,
|
|
1275
|
+
unfollowCompany: () => unfollowCompany,
|
|
362
1276
|
updateSyndicate: () => updateSyndicate,
|
|
363
|
-
updateSyndicateMember: () => updateSyndicateMember
|
|
1277
|
+
updateSyndicateMember: () => updateSyndicateMember,
|
|
1278
|
+
updateWebhookEndpoint: () => updateWebhookEndpoint
|
|
364
1279
|
});
|
|
365
1280
|
|
|
366
1281
|
// src/generated/client.gen.ts
|
|
367
|
-
|
|
368
|
-
|
|
1282
|
+
var client = createClient(
|
|
1283
|
+
createConfig({ baseUrl: "https://api.wefunder.com" })
|
|
1284
|
+
);
|
|
369
1285
|
|
|
370
1286
|
// src/generated/sdk.gen.ts
|
|
371
|
-
var listOfferings = (options) => {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
{
|
|
375
|
-
|
|
376
|
-
type: "http"
|
|
377
|
-
}
|
|
378
|
-
],
|
|
379
|
-
url: "/explore",
|
|
380
|
-
...options
|
|
381
|
-
});
|
|
382
|
-
};
|
|
383
|
-
var getOffering = (options) => {
|
|
384
|
-
return (options.client ?? client).get({
|
|
385
|
-
security: [
|
|
386
|
-
{
|
|
387
|
-
scheme: "bearer",
|
|
388
|
-
type: "http"
|
|
389
|
-
}
|
|
390
|
-
],
|
|
391
|
-
url: "/offerings/{external_id}",
|
|
392
|
-
...options
|
|
393
|
-
});
|
|
394
|
-
};
|
|
395
|
-
var getCurrentUser = (options) => {
|
|
396
|
-
return (options?.client ?? client).get({
|
|
397
|
-
security: [
|
|
398
|
-
{
|
|
399
|
-
scheme: "bearer",
|
|
400
|
-
type: "http"
|
|
401
|
-
}
|
|
402
|
-
],
|
|
403
|
-
url: "/users/me",
|
|
404
|
-
...options
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
var listInvestments = (options) => {
|
|
408
|
-
return (options?.client ?? client).get({
|
|
409
|
-
security: [
|
|
410
|
-
{
|
|
411
|
-
scheme: "bearer",
|
|
412
|
-
type: "http"
|
|
413
|
-
}
|
|
414
|
-
],
|
|
415
|
-
url: "/investments",
|
|
416
|
-
...options
|
|
417
|
-
});
|
|
418
|
-
};
|
|
419
|
-
var listCampaigns = (options) => {
|
|
420
|
-
return (options?.client ?? client).get({
|
|
421
|
-
security: [
|
|
422
|
-
{
|
|
423
|
-
scheme: "bearer",
|
|
424
|
-
type: "http"
|
|
425
|
-
}
|
|
426
|
-
],
|
|
427
|
-
url: "/campaigns",
|
|
428
|
-
...options
|
|
429
|
-
});
|
|
430
|
-
};
|
|
431
|
-
var listSyndicates = (options) => {
|
|
432
|
-
return (options?.client ?? client).get({
|
|
433
|
-
security: [
|
|
434
|
-
{
|
|
435
|
-
scheme: "bearer",
|
|
436
|
-
type: "http"
|
|
437
|
-
}
|
|
438
|
-
],
|
|
439
|
-
url: "/syndicates",
|
|
440
|
-
...options
|
|
441
|
-
});
|
|
442
|
-
};
|
|
443
|
-
var getSyndicate = (options) => {
|
|
444
|
-
return (options.client ?? client).get({
|
|
445
|
-
security: [
|
|
446
|
-
{
|
|
447
|
-
scheme: "bearer",
|
|
448
|
-
type: "http"
|
|
449
|
-
}
|
|
450
|
-
],
|
|
451
|
-
url: "/syndicates/{syndicate_id}",
|
|
452
|
-
...options
|
|
453
|
-
});
|
|
454
|
-
};
|
|
455
|
-
var updateSyndicate = (options) => {
|
|
456
|
-
return (options.client ?? client).patch({
|
|
457
|
-
security: [
|
|
458
|
-
{
|
|
459
|
-
scheme: "bearer",
|
|
460
|
-
type: "http"
|
|
461
|
-
}
|
|
462
|
-
],
|
|
463
|
-
url: "/syndicates/{syndicate_id}",
|
|
464
|
-
...options,
|
|
465
|
-
headers: {
|
|
466
|
-
"Content-Type": "application/json",
|
|
467
|
-
...options?.headers
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
};
|
|
471
|
-
var listSyndicateMembers = (options) => {
|
|
472
|
-
return (options.client ?? client).get({
|
|
473
|
-
security: [
|
|
474
|
-
{
|
|
475
|
-
scheme: "bearer",
|
|
476
|
-
type: "http"
|
|
477
|
-
}
|
|
478
|
-
],
|
|
479
|
-
url: "/syndicates/{syndicate_id}/members",
|
|
480
|
-
...options
|
|
481
|
-
});
|
|
482
|
-
};
|
|
483
|
-
var inviteSyndicateMember = (options) => {
|
|
484
|
-
return (options.client ?? client).post({
|
|
485
|
-
security: [
|
|
486
|
-
{
|
|
487
|
-
scheme: "bearer",
|
|
488
|
-
type: "http"
|
|
489
|
-
}
|
|
490
|
-
],
|
|
491
|
-
url: "/syndicates/{syndicate_id}/members/invite",
|
|
492
|
-
...options,
|
|
493
|
-
headers: {
|
|
494
|
-
"Content-Type": "application/json",
|
|
495
|
-
...options?.headers
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
};
|
|
499
|
-
var removeSyndicateMember = (options) => {
|
|
500
|
-
return (options.client ?? client).delete({
|
|
501
|
-
security: [
|
|
502
|
-
{
|
|
503
|
-
scheme: "bearer",
|
|
504
|
-
type: "http"
|
|
505
|
-
}
|
|
506
|
-
],
|
|
507
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}",
|
|
508
|
-
...options
|
|
509
|
-
});
|
|
510
|
-
};
|
|
511
|
-
var updateSyndicateMember = (options) => {
|
|
512
|
-
return (options.client ?? client).patch({
|
|
513
|
-
security: [
|
|
514
|
-
{
|
|
515
|
-
scheme: "bearer",
|
|
516
|
-
type: "http"
|
|
517
|
-
}
|
|
518
|
-
],
|
|
519
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}",
|
|
520
|
-
...options,
|
|
521
|
-
headers: {
|
|
522
|
-
"Content-Type": "application/json",
|
|
523
|
-
...options?.headers
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
};
|
|
527
|
-
var approveSyndicateMember = (options) => {
|
|
528
|
-
return (options.client ?? client).post({
|
|
529
|
-
security: [
|
|
530
|
-
{
|
|
531
|
-
scheme: "bearer",
|
|
532
|
-
type: "http"
|
|
533
|
-
}
|
|
534
|
-
],
|
|
535
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}/approve",
|
|
536
|
-
...options
|
|
537
|
-
});
|
|
538
|
-
};
|
|
539
|
-
var hideSyndicateMember = (options) => {
|
|
540
|
-
return (options.client ?? client).post({
|
|
541
|
-
security: [
|
|
542
|
-
{
|
|
543
|
-
scheme: "bearer",
|
|
544
|
-
type: "http"
|
|
545
|
-
}
|
|
546
|
-
],
|
|
547
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}/hide",
|
|
548
|
-
...options
|
|
549
|
-
});
|
|
550
|
-
};
|
|
551
|
-
var promoteSyndicateMember = (options) => {
|
|
552
|
-
return (options.client ?? client).post({
|
|
553
|
-
security: [
|
|
554
|
-
{
|
|
555
|
-
scheme: "bearer",
|
|
556
|
-
type: "http"
|
|
557
|
-
}
|
|
558
|
-
],
|
|
559
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}/promote",
|
|
560
|
-
...options
|
|
561
|
-
});
|
|
562
|
-
};
|
|
563
|
-
var demoteSyndicateMember = (options) => {
|
|
564
|
-
return (options.client ?? client).post({
|
|
565
|
-
security: [
|
|
566
|
-
{
|
|
567
|
-
scheme: "bearer",
|
|
568
|
-
type: "http"
|
|
569
|
-
}
|
|
570
|
-
],
|
|
571
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}/demote",
|
|
572
|
-
...options
|
|
573
|
-
});
|
|
574
|
-
};
|
|
575
|
-
var restoreSyndicateMember = (options) => {
|
|
576
|
-
return (options.client ?? client).post({
|
|
577
|
-
security: [
|
|
578
|
-
{
|
|
579
|
-
scheme: "bearer",
|
|
580
|
-
type: "http"
|
|
581
|
-
}
|
|
582
|
-
],
|
|
583
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}/restore",
|
|
584
|
-
...options
|
|
585
|
-
});
|
|
586
|
-
};
|
|
587
|
-
var resendSyndicateInvite = (options) => {
|
|
588
|
-
return (options.client ?? client).post({
|
|
589
|
-
security: [
|
|
590
|
-
{
|
|
591
|
-
scheme: "bearer",
|
|
592
|
-
type: "http"
|
|
593
|
-
}
|
|
594
|
-
],
|
|
595
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}/resend_invite",
|
|
596
|
-
...options
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
|
-
var reorderSyndicateMembers = (options) => {
|
|
600
|
-
return (options.client ?? client).post({
|
|
601
|
-
security: [
|
|
602
|
-
{
|
|
603
|
-
scheme: "bearer",
|
|
604
|
-
type: "http"
|
|
605
|
-
}
|
|
606
|
-
],
|
|
607
|
-
url: "/syndicates/{syndicate_id}/members/reorder",
|
|
608
|
-
...options,
|
|
609
|
-
headers: {
|
|
610
|
-
"Content-Type": "application/json",
|
|
611
|
-
...options?.headers
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
};
|
|
615
|
-
var exportSyndicateMembersCsv = (options) => {
|
|
616
|
-
return (options.client ?? client).post({
|
|
617
|
-
security: [
|
|
618
|
-
{
|
|
619
|
-
scheme: "bearer",
|
|
620
|
-
type: "http"
|
|
621
|
-
}
|
|
622
|
-
],
|
|
623
|
-
url: "/syndicates/{syndicate_id}/members/export_csv",
|
|
624
|
-
...options
|
|
625
|
-
});
|
|
626
|
-
};
|
|
627
|
-
var listSyndicateDeals = (options) => {
|
|
628
|
-
return (options.client ?? client).get({
|
|
629
|
-
security: [
|
|
630
|
-
{
|
|
631
|
-
scheme: "bearer",
|
|
632
|
-
type: "http"
|
|
633
|
-
}
|
|
634
|
-
],
|
|
635
|
-
url: "/syndicates/{syndicate_id}/deals",
|
|
636
|
-
...options
|
|
637
|
-
});
|
|
638
|
-
};
|
|
639
|
-
var getSyndicateDeal = (options) => {
|
|
640
|
-
return (options.client ?? client).get({
|
|
641
|
-
security: [
|
|
642
|
-
{
|
|
643
|
-
scheme: "bearer",
|
|
644
|
-
type: "http"
|
|
645
|
-
}
|
|
646
|
-
],
|
|
647
|
-
url: "/syndicates/{syndicate_id}/deals/{fundraise_id}",
|
|
648
|
-
...options
|
|
649
|
-
});
|
|
650
|
-
};
|
|
651
|
-
var listSyndicateDealInvestors = (options) => {
|
|
652
|
-
return (options.client ?? client).get({
|
|
653
|
-
security: [
|
|
654
|
-
{
|
|
655
|
-
scheme: "bearer",
|
|
656
|
-
type: "http"
|
|
657
|
-
}
|
|
658
|
-
],
|
|
659
|
-
url: "/syndicates/{syndicate_id}/deals/{fundraise_id}/investors",
|
|
660
|
-
...options
|
|
661
|
-
});
|
|
662
|
-
};
|
|
663
|
-
var listSyndicateMemberInvestments = (options) => {
|
|
664
|
-
return (options.client ?? client).get({
|
|
665
|
-
security: [
|
|
666
|
-
{
|
|
667
|
-
scheme: "bearer",
|
|
668
|
-
type: "http"
|
|
669
|
-
}
|
|
670
|
-
],
|
|
671
|
-
url: "/syndicates/{syndicate_id}/members/{member_id}/investments",
|
|
672
|
-
...options
|
|
673
|
-
});
|
|
674
|
-
};
|
|
675
|
-
var getSyndicateStatistics = (options) => {
|
|
676
|
-
return (options.client ?? client).get({
|
|
677
|
-
security: [
|
|
678
|
-
{
|
|
679
|
-
scheme: "bearer",
|
|
680
|
-
type: "http"
|
|
681
|
-
}
|
|
682
|
-
],
|
|
683
|
-
url: "/syndicates/{syndicate_id}/statistics",
|
|
684
|
-
...options
|
|
685
|
-
});
|
|
686
|
-
};
|
|
687
|
-
var closeSyndicateDeal = (options) => {
|
|
688
|
-
return (options.client ?? client).post({
|
|
689
|
-
security: [
|
|
690
|
-
{
|
|
691
|
-
scheme: "bearer",
|
|
692
|
-
type: "http"
|
|
693
|
-
}
|
|
694
|
-
],
|
|
695
|
-
url: "/syndicates/{syndicate_id}/deals/{fundraise_id}/close",
|
|
696
|
-
...options
|
|
697
|
-
});
|
|
698
|
-
};
|
|
699
|
-
var finalizeSyndicateDeal = (options) => {
|
|
700
|
-
return (options.client ?? client).post({
|
|
701
|
-
security: [
|
|
702
|
-
{
|
|
703
|
-
scheme: "bearer",
|
|
704
|
-
type: "http"
|
|
705
|
-
}
|
|
706
|
-
],
|
|
707
|
-
url: "/syndicates/{syndicate_id}/deals/{fundraise_id}/finalize",
|
|
708
|
-
...options
|
|
709
|
-
});
|
|
710
|
-
};
|
|
711
|
-
var listIntents = (options) => {
|
|
712
|
-
return (options?.client ?? client).get({
|
|
713
|
-
security: [
|
|
714
|
-
{
|
|
715
|
-
scheme: "bearer",
|
|
716
|
-
type: "http"
|
|
717
|
-
}
|
|
718
|
-
],
|
|
719
|
-
url: "/intents",
|
|
720
|
-
...options
|
|
721
|
-
});
|
|
722
|
-
};
|
|
723
|
-
var createIntent = (options) => {
|
|
724
|
-
return (options.client ?? client).post({
|
|
725
|
-
security: [
|
|
726
|
-
{
|
|
727
|
-
scheme: "bearer",
|
|
728
|
-
type: "http"
|
|
729
|
-
}
|
|
730
|
-
],
|
|
731
|
-
url: "/intents",
|
|
732
|
-
...options,
|
|
733
|
-
headers: {
|
|
734
|
-
"Content-Type": "application/json",
|
|
735
|
-
...options?.headers
|
|
1287
|
+
var listOfferings = (options) => (options?.client ?? client).get({
|
|
1288
|
+
querySerializer: {
|
|
1289
|
+
parameters: {
|
|
1290
|
+
industry: { array: { explode: false } },
|
|
1291
|
+
business_model: { array: { explode: false } }
|
|
736
1292
|
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
};
|
|
763
|
-
var
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
};
|
|
823
|
-
var
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
};
|
|
939
|
-
var
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
};
|
|
1293
|
+
},
|
|
1294
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1295
|
+
url: "/explore",
|
|
1296
|
+
...options
|
|
1297
|
+
});
|
|
1298
|
+
var getOffering = (options) => (options.client ?? client).get({
|
|
1299
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1300
|
+
url: "/offerings/{external_id}",
|
|
1301
|
+
...options
|
|
1302
|
+
});
|
|
1303
|
+
var getCompanyDisclosures = (options) => (options.client ?? client).get({
|
|
1304
|
+
querySerializer: {
|
|
1305
|
+
parameters: { sections: { array: { explode: false } } }
|
|
1306
|
+
},
|
|
1307
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1308
|
+
url: "/companies/{id}/disclosures",
|
|
1309
|
+
...options
|
|
1310
|
+
});
|
|
1311
|
+
var getCompanyPitch = (options) => (options.client ?? client).get({
|
|
1312
|
+
querySerializer: {
|
|
1313
|
+
parameters: { sections: { array: { explode: false } } }
|
|
1314
|
+
},
|
|
1315
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1316
|
+
url: "/companies/{id}/pitch",
|
|
1317
|
+
...options
|
|
1318
|
+
});
|
|
1319
|
+
var listCompanyUpdates = (options) => (options.client ?? client).get({
|
|
1320
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1321
|
+
url: "/companies/{id}/updates",
|
|
1322
|
+
...options
|
|
1323
|
+
});
|
|
1324
|
+
var getCompanyUpdate = (options) => (options.client ?? client).get({
|
|
1325
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1326
|
+
url: "/companies/{id}/updates/{update_id}",
|
|
1327
|
+
...options
|
|
1328
|
+
});
|
|
1329
|
+
var listCompanyQuestions = (options) => (options.client ?? client).get({
|
|
1330
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1331
|
+
url: "/companies/{id}/questions",
|
|
1332
|
+
...options
|
|
1333
|
+
});
|
|
1334
|
+
var searchCompanies = (options) => (options.client ?? client).get({
|
|
1335
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1336
|
+
url: "/companies/search",
|
|
1337
|
+
...options
|
|
1338
|
+
});
|
|
1339
|
+
var getCompany = (options) => (options.client ?? client).get({
|
|
1340
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1341
|
+
url: "/companies/{id}",
|
|
1342
|
+
...options
|
|
1343
|
+
});
|
|
1344
|
+
var getCurrentUser = (options) => (options?.client ?? client).get({
|
|
1345
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1346
|
+
url: "/users/me",
|
|
1347
|
+
...options
|
|
1348
|
+
});
|
|
1349
|
+
var listMyCompanies = (options) => (options?.client ?? client).get({
|
|
1350
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1351
|
+
url: "/users/me/companies",
|
|
1352
|
+
...options
|
|
1353
|
+
});
|
|
1354
|
+
var listFollowedCompanies = (options) => (options?.client ?? client).get({
|
|
1355
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1356
|
+
url: "/users/me/follows",
|
|
1357
|
+
...options
|
|
1358
|
+
});
|
|
1359
|
+
var unfollowCompany = (options) => (options.client ?? client).delete({
|
|
1360
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1361
|
+
url: "/users/me/follows/{company_id}",
|
|
1362
|
+
...options
|
|
1363
|
+
});
|
|
1364
|
+
var followCompany = (options) => (options.client ?? client).put({
|
|
1365
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1366
|
+
url: "/users/me/follows/{company_id}",
|
|
1367
|
+
...options
|
|
1368
|
+
});
|
|
1369
|
+
var listInvestments = (options) => (options?.client ?? client).get({
|
|
1370
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1371
|
+
url: "/investments",
|
|
1372
|
+
...options
|
|
1373
|
+
});
|
|
1374
|
+
var getInvestment = (options) => (options.client ?? client).get({
|
|
1375
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1376
|
+
url: "/investments/{id}",
|
|
1377
|
+
...options
|
|
1378
|
+
});
|
|
1379
|
+
var getOfferingStats = (options) => (options.client ?? client).get({
|
|
1380
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1381
|
+
url: "/offerings/{offering_id}/stats",
|
|
1382
|
+
...options
|
|
1383
|
+
});
|
|
1384
|
+
var listCompanyInvestmentChanges = (options) => (options.client ?? client).get({
|
|
1385
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1386
|
+
url: "/companies/{company_id}/investments/changes",
|
|
1387
|
+
...options
|
|
1388
|
+
});
|
|
1389
|
+
var getPortfolio = (options) => (options?.client ?? client).get({
|
|
1390
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1391
|
+
url: "/portfolio",
|
|
1392
|
+
...options
|
|
1393
|
+
});
|
|
1394
|
+
var listPortfolioPositions = (options) => (options?.client ?? client).get({
|
|
1395
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1396
|
+
url: "/portfolio/positions",
|
|
1397
|
+
...options
|
|
1398
|
+
});
|
|
1399
|
+
var listCampaigns = (options) => (options?.client ?? client).get({
|
|
1400
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1401
|
+
url: "/campaigns",
|
|
1402
|
+
...options
|
|
1403
|
+
});
|
|
1404
|
+
var listSyndicates = (options) => (options?.client ?? client).get({
|
|
1405
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1406
|
+
url: "/syndicates",
|
|
1407
|
+
...options
|
|
1408
|
+
});
|
|
1409
|
+
var getSyndicate = (options) => (options.client ?? client).get({
|
|
1410
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1411
|
+
url: "/syndicates/{syndicate_id}",
|
|
1412
|
+
...options
|
|
1413
|
+
});
|
|
1414
|
+
var updateSyndicate = (options) => (options.client ?? client).patch({
|
|
1415
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1416
|
+
url: "/syndicates/{syndicate_id}",
|
|
1417
|
+
...options,
|
|
1418
|
+
headers: {
|
|
1419
|
+
"Content-Type": "application/json",
|
|
1420
|
+
...options.headers
|
|
1421
|
+
}
|
|
1422
|
+
});
|
|
1423
|
+
var listSyndicateMembers = (options) => (options.client ?? client).get({
|
|
1424
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1425
|
+
url: "/syndicates/{syndicate_id}/members",
|
|
1426
|
+
...options
|
|
1427
|
+
});
|
|
1428
|
+
var inviteSyndicateMember = (options) => (options.client ?? client).post({
|
|
1429
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1430
|
+
url: "/syndicates/{syndicate_id}/members/invite",
|
|
1431
|
+
...options,
|
|
1432
|
+
headers: {
|
|
1433
|
+
"Content-Type": "application/json",
|
|
1434
|
+
...options.headers
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
var removeSyndicateMember = (options) => (options.client ?? client).delete({
|
|
1438
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1439
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}",
|
|
1440
|
+
...options
|
|
1441
|
+
});
|
|
1442
|
+
var updateSyndicateMember = (options) => (options.client ?? client).patch({
|
|
1443
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1444
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}",
|
|
1445
|
+
...options,
|
|
1446
|
+
headers: {
|
|
1447
|
+
"Content-Type": "application/json",
|
|
1448
|
+
...options.headers
|
|
1449
|
+
}
|
|
1450
|
+
});
|
|
1451
|
+
var approveSyndicateMember = (options) => (options.client ?? client).post({
|
|
1452
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1453
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}/approve",
|
|
1454
|
+
...options
|
|
1455
|
+
});
|
|
1456
|
+
var hideSyndicateMember = (options) => (options.client ?? client).post({
|
|
1457
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1458
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}/hide",
|
|
1459
|
+
...options
|
|
1460
|
+
});
|
|
1461
|
+
var promoteSyndicateMember = (options) => (options.client ?? client).post({
|
|
1462
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1463
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}/promote",
|
|
1464
|
+
...options
|
|
1465
|
+
});
|
|
1466
|
+
var demoteSyndicateMember = (options) => (options.client ?? client).post({
|
|
1467
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1468
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}/demote",
|
|
1469
|
+
...options
|
|
1470
|
+
});
|
|
1471
|
+
var restoreSyndicateMember = (options) => (options.client ?? client).post({
|
|
1472
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1473
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}/restore",
|
|
1474
|
+
...options
|
|
1475
|
+
});
|
|
1476
|
+
var resendSyndicateInvite = (options) => (options.client ?? client).post({
|
|
1477
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1478
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}/resend_invite",
|
|
1479
|
+
...options
|
|
1480
|
+
});
|
|
1481
|
+
var reorderSyndicateMembers = (options) => (options.client ?? client).post({
|
|
1482
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1483
|
+
url: "/syndicates/{syndicate_id}/members/reorder",
|
|
1484
|
+
...options,
|
|
1485
|
+
headers: {
|
|
1486
|
+
"Content-Type": "application/json",
|
|
1487
|
+
...options.headers
|
|
1488
|
+
}
|
|
1489
|
+
});
|
|
1490
|
+
var exportSyndicateMembersCsv = (options) => (options.client ?? client).post({
|
|
1491
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1492
|
+
url: "/syndicates/{syndicate_id}/members/export_csv",
|
|
1493
|
+
...options
|
|
1494
|
+
});
|
|
1495
|
+
var listSyndicateDeals = (options) => (options.client ?? client).get({
|
|
1496
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1497
|
+
url: "/syndicates/{syndicate_id}/deals",
|
|
1498
|
+
...options
|
|
1499
|
+
});
|
|
1500
|
+
var getSyndicateDeal = (options) => (options.client ?? client).get({
|
|
1501
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1502
|
+
url: "/syndicates/{syndicate_id}/deals/{fundraise_id}",
|
|
1503
|
+
...options
|
|
1504
|
+
});
|
|
1505
|
+
var listSyndicateDealInvestors = (options) => (options.client ?? client).get({
|
|
1506
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1507
|
+
url: "/syndicates/{syndicate_id}/deals/{fundraise_id}/investors",
|
|
1508
|
+
...options
|
|
1509
|
+
});
|
|
1510
|
+
var listSyndicateMemberInvestments = (options) => (options.client ?? client).get({
|
|
1511
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1512
|
+
url: "/syndicates/{syndicate_id}/members/{member_id}/investments",
|
|
1513
|
+
...options
|
|
1514
|
+
});
|
|
1515
|
+
var getSyndicateStatistics = (options) => (options.client ?? client).get({
|
|
1516
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1517
|
+
url: "/syndicates/{syndicate_id}/statistics",
|
|
1518
|
+
...options
|
|
1519
|
+
});
|
|
1520
|
+
var getSyndicatePortfolio = (options) => (options.client ?? client).get({
|
|
1521
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1522
|
+
url: "/syndicates/{syndicate_id}/portfolio",
|
|
1523
|
+
...options
|
|
1524
|
+
});
|
|
1525
|
+
var listSyndicatePortfolioPositions = (options) => (options.client ?? client).get({
|
|
1526
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1527
|
+
url: "/syndicates/{syndicate_id}/portfolio/positions",
|
|
1528
|
+
...options
|
|
1529
|
+
});
|
|
1530
|
+
var closeSyndicateDeal = (options) => (options.client ?? client).post({
|
|
1531
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1532
|
+
url: "/syndicates/{syndicate_id}/deals/{fundraise_id}/close",
|
|
1533
|
+
...options
|
|
1534
|
+
});
|
|
1535
|
+
var finalizeSyndicateDeal = (options) => (options.client ?? client).post({
|
|
1536
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1537
|
+
url: "/syndicates/{syndicate_id}/deals/{fundraise_id}/finalize",
|
|
1538
|
+
...options
|
|
1539
|
+
});
|
|
1540
|
+
var previewIntent = (options) => (options.client ?? client).post({
|
|
1541
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1542
|
+
url: "/intents/preview",
|
|
1543
|
+
...options,
|
|
1544
|
+
headers: {
|
|
1545
|
+
"Content-Type": "application/json",
|
|
1546
|
+
...options.headers
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1549
|
+
var listIntents = (options) => (options?.client ?? client).get({
|
|
1550
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1551
|
+
url: "/intents",
|
|
1552
|
+
...options
|
|
1553
|
+
});
|
|
1554
|
+
var createIntent = (options) => (options.client ?? client).post({
|
|
1555
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1556
|
+
url: "/intents",
|
|
1557
|
+
...options,
|
|
1558
|
+
headers: {
|
|
1559
|
+
"Content-Type": "application/json",
|
|
1560
|
+
...options.headers
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
var getIntent = (options) => (options.client ?? client).get({
|
|
1564
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1565
|
+
url: "/intents/{intent_id}",
|
|
1566
|
+
...options
|
|
1567
|
+
});
|
|
1568
|
+
var listActivity = (options) => (options?.client ?? client).get({
|
|
1569
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1570
|
+
url: "/activity",
|
|
1571
|
+
...options
|
|
1572
|
+
});
|
|
1573
|
+
var listConnectedApps = (options) => (options?.client ?? client).get({
|
|
1574
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1575
|
+
url: "/connected-apps",
|
|
1576
|
+
...options
|
|
1577
|
+
});
|
|
1578
|
+
var revokeConnectedApp = (options) => (options.client ?? client).delete({
|
|
1579
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1580
|
+
url: "/connected-apps/{app_id}",
|
|
1581
|
+
...options
|
|
1582
|
+
});
|
|
1583
|
+
var getAttributionStats = (options) => (options.client ?? client).get({
|
|
1584
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1585
|
+
url: "/campaigns/{campaign_id}/attribution/stats",
|
|
1586
|
+
...options
|
|
1587
|
+
});
|
|
1588
|
+
var listAttributedInvestments = (options) => (options.client ?? client).get({
|
|
1589
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1590
|
+
url: "/campaigns/{campaign_id}/attribution/investments",
|
|
1591
|
+
...options
|
|
1592
|
+
});
|
|
1593
|
+
var listInstallations = (options) => (options?.client ?? client).get({
|
|
1594
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1595
|
+
url: "/installations",
|
|
1596
|
+
...options
|
|
1597
|
+
});
|
|
1598
|
+
var createInstallation = (options) => (options.client ?? client).post({
|
|
1599
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1600
|
+
url: "/installations",
|
|
1601
|
+
...options,
|
|
1602
|
+
headers: {
|
|
1603
|
+
"Content-Type": "application/json",
|
|
1604
|
+
...options.headers
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
var listEligibleInstallTargets = (options) => (options?.client ?? client).get({
|
|
1608
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1609
|
+
url: "/installations/eligible",
|
|
1610
|
+
...options
|
|
1611
|
+
});
|
|
1612
|
+
var revokeInstallation = (options) => (options.client ?? client).delete({
|
|
1613
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1614
|
+
url: "/installations/{external_id}",
|
|
1615
|
+
...options
|
|
1616
|
+
});
|
|
1617
|
+
var getInstallation = (options) => (options.client ?? client).get({
|
|
1618
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1619
|
+
url: "/installations/{external_id}",
|
|
1620
|
+
...options
|
|
1621
|
+
});
|
|
1622
|
+
var createInstallationToken = (options) => (options.client ?? client).post({
|
|
1623
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1624
|
+
url: "/installations/{external_id}/tokens",
|
|
1625
|
+
...options,
|
|
1626
|
+
headers: {
|
|
1627
|
+
"Content-Type": "application/json",
|
|
1628
|
+
...options.headers
|
|
1629
|
+
}
|
|
1630
|
+
});
|
|
1631
|
+
var listWebhookEndpoints = (options) => (options?.client ?? client).get({
|
|
1632
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1633
|
+
url: "/webhook_endpoints",
|
|
1634
|
+
...options
|
|
1635
|
+
});
|
|
1636
|
+
var createWebhookEndpoint = (options) => (options.client ?? client).post({
|
|
1637
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1638
|
+
url: "/webhook_endpoints",
|
|
1639
|
+
...options,
|
|
1640
|
+
headers: {
|
|
1641
|
+
"Content-Type": "application/json",
|
|
1642
|
+
...options.headers
|
|
1643
|
+
}
|
|
1644
|
+
});
|
|
1645
|
+
var deleteWebhookEndpoint = (options) => (options.client ?? client).delete({
|
|
1646
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1647
|
+
url: "/webhook_endpoints/{external_id}",
|
|
1648
|
+
...options
|
|
1649
|
+
});
|
|
1650
|
+
var getWebhookEndpoint = (options) => (options.client ?? client).get({
|
|
1651
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1652
|
+
url: "/webhook_endpoints/{external_id}",
|
|
1653
|
+
...options
|
|
1654
|
+
});
|
|
1655
|
+
var updateWebhookEndpoint = (options) => (options.client ?? client).patch({
|
|
1656
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1657
|
+
url: "/webhook_endpoints/{external_id}",
|
|
1658
|
+
...options,
|
|
1659
|
+
headers: {
|
|
1660
|
+
"Content-Type": "application/json",
|
|
1661
|
+
...options.headers
|
|
1662
|
+
}
|
|
1663
|
+
});
|
|
1664
|
+
var rotateWebhookEndpointSecret = (options) => (options.client ?? client).post({
|
|
1665
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1666
|
+
url: "/webhook_endpoints/{external_id}/rotate_secret",
|
|
1667
|
+
...options
|
|
1668
|
+
});
|
|
1669
|
+
var reenableWebhookEndpoint = (options) => (options.client ?? client).post({
|
|
1670
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1671
|
+
url: "/webhook_endpoints/{external_id}/reenable",
|
|
1672
|
+
...options
|
|
1673
|
+
});
|
|
1674
|
+
var testWebhookEndpoint = (options) => (options.client ?? client).post({
|
|
1675
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1676
|
+
url: "/webhook_endpoints/{external_id}/test",
|
|
1677
|
+
...options,
|
|
1678
|
+
headers: {
|
|
1679
|
+
"Content-Type": "application/json",
|
|
1680
|
+
...options.headers
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
var listWebhookSubscriptions = (options) => (options.client ?? client).get({
|
|
1684
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1685
|
+
url: "/campaigns/{campaign_id}/attribution/webhooks",
|
|
1686
|
+
...options
|
|
1687
|
+
});
|
|
1688
|
+
var createWebhookSubscription = (options) => (options.client ?? client).post({
|
|
1689
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1690
|
+
url: "/campaigns/{campaign_id}/attribution/webhooks",
|
|
1691
|
+
...options,
|
|
1692
|
+
headers: {
|
|
1693
|
+
"Content-Type": "application/json",
|
|
1694
|
+
...options.headers
|
|
1695
|
+
}
|
|
1696
|
+
});
|
|
1697
|
+
var deleteWebhookSubscription = (options) => (options.client ?? client).delete({
|
|
1698
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1699
|
+
url: "/campaigns/{campaign_id}/attribution/webhooks/{webhook_id}",
|
|
1700
|
+
...options
|
|
1701
|
+
});
|
|
1702
|
+
var getWebhookSubscription = (options) => (options.client ?? client).get({
|
|
1703
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1704
|
+
url: "/campaigns/{campaign_id}/attribution/webhooks/{webhook_id}",
|
|
1705
|
+
...options
|
|
1706
|
+
});
|
|
1707
|
+
var testWebhookSubscription = (options) => (options.client ?? client).post({
|
|
1708
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1709
|
+
url: "/campaigns/{campaign_id}/attribution/webhooks/{webhook_id}/test",
|
|
1710
|
+
...options
|
|
1711
|
+
});
|
|
1712
|
+
var regenerateWebhookSecret = (options) => (options.client ?? client).post({
|
|
1713
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1714
|
+
url: "/campaigns/{campaign_id}/attribution/webhooks/{webhook_id}/regenerate_secret",
|
|
1715
|
+
...options
|
|
1716
|
+
});
|
|
1717
|
+
var reactivateWebhookSubscription = (options) => (options.client ?? client).post({
|
|
1718
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1719
|
+
url: "/campaigns/{campaign_id}/attribution/webhooks/{webhook_id}/reactivate",
|
|
1720
|
+
...options
|
|
1721
|
+
});
|
|
1722
|
+
var getAttributionMe = (options) => (options?.client ?? client).get({
|
|
1723
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1724
|
+
url: "/attribution/me",
|
|
1725
|
+
...options
|
|
1726
|
+
});
|
|
1727
|
+
var listAttributionCampaigns = (options) => (options?.client ?? client).get({
|
|
1728
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1729
|
+
url: "/attribution/campaigns",
|
|
1730
|
+
...options
|
|
1731
|
+
});
|
|
1732
|
+
var registerAsPartner = (options) => (options.client ?? client).post({
|
|
1733
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1734
|
+
url: "/attribution/partners/register",
|
|
1735
|
+
...options,
|
|
1736
|
+
headers: {
|
|
1737
|
+
"Content-Type": "application/json",
|
|
1738
|
+
...options.headers
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
var listPartnerInvites = (options) => (options?.client ?? client).get({
|
|
1742
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1743
|
+
url: "/attribution/invites",
|
|
1744
|
+
...options
|
|
1745
|
+
});
|
|
1746
|
+
var createPartnerInvite = (options) => (options.client ?? client).post({
|
|
1747
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1748
|
+
url: "/attribution/invites",
|
|
1749
|
+
...options,
|
|
1750
|
+
headers: {
|
|
1751
|
+
"Content-Type": "application/json",
|
|
1752
|
+
...options.headers
|
|
1753
|
+
}
|
|
1754
|
+
});
|
|
1755
|
+
var revokePartnerInvite = (options) => (options.client ?? client).delete({
|
|
1756
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1757
|
+
url: "/attribution/invites/{token}",
|
|
1758
|
+
...options
|
|
1759
|
+
});
|
|
979
1760
|
|
|
980
1761
|
// src/client.ts
|
|
981
|
-
var DEFAULT_API_BASE_URL = "https://api.wefunder.com
|
|
1762
|
+
var DEFAULT_API_BASE_URL = "https://api.wefunder.com";
|
|
982
1763
|
var DEFAULT_API_VERSION = "2025-01-15";
|
|
983
1764
|
function modeForToken(token) {
|
|
984
1765
|
if (token.startsWith("at_live_")) return "live";
|
|
@@ -1025,7 +1806,7 @@ var Wefunder = class _Wefunder {
|
|
|
1025
1806
|
random: opts.random,
|
|
1026
1807
|
retry: opts.retry
|
|
1027
1808
|
});
|
|
1028
|
-
this.#client =
|
|
1809
|
+
this.#client = createClient({
|
|
1029
1810
|
baseUrl: opts.baseUrl ?? DEFAULT_API_BASE_URL,
|
|
1030
1811
|
headers: { "Wefunder-Version": opts.apiVersion ?? DEFAULT_API_VERSION },
|
|
1031
1812
|
auth: () => this.#tokens.getAccessToken(),
|
|
@@ -1059,12 +1840,22 @@ var Wefunder = class _Wefunder {
|
|
|
1059
1840
|
});
|
|
1060
1841
|
}
|
|
1061
1842
|
/** The live token set (e.g. to persist after construction). */
|
|
1843
|
+
/** A rotated set awaiting a successful save (see `WefunderTokenPersistenceError`). */
|
|
1844
|
+
get pendingTokens() {
|
|
1845
|
+
return this.#tokens.pendingTokens;
|
|
1846
|
+
}
|
|
1847
|
+
/** Acknowledge an out-of-band save of `tokens`; false if that set is no longer pending. */
|
|
1848
|
+
markPersisted(tokens) {
|
|
1849
|
+
return this.#tokens.markPersisted(tokens);
|
|
1850
|
+
}
|
|
1062
1851
|
get tokens() {
|
|
1063
1852
|
return this.#tokens.current;
|
|
1064
1853
|
}
|
|
1065
1854
|
// ---- unwrap: turn the {data,error,response} result into data-or-throw ----
|
|
1066
1855
|
async #unwrap(p) {
|
|
1067
1856
|
const { data, error, response } = await p;
|
|
1857
|
+
if (error instanceof WefunderTokenPersistenceError || error instanceof WefunderError)
|
|
1858
|
+
throw error;
|
|
1068
1859
|
if (response && response.ok && error === void 0) return data;
|
|
1069
1860
|
const status = response?.status ?? 0;
|
|
1070
1861
|
const env = error ?? {};
|
|
@@ -1073,7 +1864,10 @@ var Wefunder = class _Wefunder {
|
|
|
1073
1864
|
type: env.error?.type ?? "api_error",
|
|
1074
1865
|
message: env.error?.message ?? response?.statusText ?? "Request failed",
|
|
1075
1866
|
// X-Wf-Request-Id header is primary (present even on non-JSON edge errors).
|
|
1076
|
-
requestId: requestIdFrom(
|
|
1867
|
+
requestId: requestIdFrom(
|
|
1868
|
+
response,
|
|
1869
|
+
env.error?.request_id ?? env.request_id
|
|
1870
|
+
),
|
|
1077
1871
|
details: env.error?.details,
|
|
1078
1872
|
remediation: env.error?.remediation
|
|
1079
1873
|
});
|
|
@@ -1109,17 +1903,59 @@ var Wefunder = class _Wefunder {
|
|
|
1109
1903
|
me: () => this.#unwrapData(getCurrentUser({ client: this.#client }))
|
|
1110
1904
|
};
|
|
1111
1905
|
offerings = {
|
|
1112
|
-
list: this.#page(
|
|
1906
|
+
list: this.#page(
|
|
1907
|
+
listOfferings
|
|
1908
|
+
),
|
|
1113
1909
|
all: (query) => paginate((cursor) => this.offerings.list({ ...query, cursor })),
|
|
1114
1910
|
collect: (query) => collect((cursor) => this.offerings.list({ ...query, cursor })),
|
|
1115
1911
|
get: (externalId) => this.#unwrapData(
|
|
1116
|
-
getOffering({
|
|
1912
|
+
getOffering({
|
|
1913
|
+
client: this.#client,
|
|
1914
|
+
path: { external_id: externalId }
|
|
1915
|
+
})
|
|
1117
1916
|
)
|
|
1118
1917
|
};
|
|
1918
|
+
/**
|
|
1919
|
+
* Investments (`read:investments`). `list` is a bootstrap listing; pass `updated_since`
|
|
1920
|
+
* or a saved `cursor` for sync mode (`meta.mode === "delta"`). Persist `meta.next_cursor`
|
|
1921
|
+
* from your last page — it is always present — and resume from it next time.
|
|
1922
|
+
*/
|
|
1119
1923
|
investments = {
|
|
1120
|
-
list: this.#page(
|
|
1121
|
-
|
|
1122
|
-
|
|
1924
|
+
list: this.#page(
|
|
1925
|
+
listInvestments
|
|
1926
|
+
),
|
|
1927
|
+
all: (query) => paginate(
|
|
1928
|
+
(cursor) => this.investments.list({
|
|
1929
|
+
...query,
|
|
1930
|
+
cursor
|
|
1931
|
+
})
|
|
1932
|
+
),
|
|
1933
|
+
collect: (query) => collect(
|
|
1934
|
+
(cursor) => this.investments.list({
|
|
1935
|
+
...query,
|
|
1936
|
+
cursor
|
|
1937
|
+
})
|
|
1938
|
+
),
|
|
1939
|
+
/** The current record (not the published projection) for one investment (`inv_…`). */
|
|
1940
|
+
get: (id) => this.#unwrapData(
|
|
1941
|
+
getInvestment({ client: this.#client, path: { id } })
|
|
1942
|
+
)
|
|
1943
|
+
};
|
|
1944
|
+
portfolio = {
|
|
1945
|
+
get: (query) => this.#unwrapData(
|
|
1946
|
+
getPortfolio({ client: this.#client, query })
|
|
1947
|
+
),
|
|
1948
|
+
positions: {
|
|
1949
|
+
list: this.#page(
|
|
1950
|
+
listPortfolioPositions
|
|
1951
|
+
),
|
|
1952
|
+
all: (query) => paginate(
|
|
1953
|
+
(cursor) => this.portfolio.positions.list({ ...query, cursor })
|
|
1954
|
+
),
|
|
1955
|
+
collect: (query) => collect(
|
|
1956
|
+
(cursor) => this.portfolio.positions.list({ ...query, cursor })
|
|
1957
|
+
)
|
|
1958
|
+
}
|
|
1123
1959
|
};
|
|
1124
1960
|
campaigns = {
|
|
1125
1961
|
list: this.#page(listCampaigns),
|
|
@@ -1127,29 +1963,116 @@ var Wefunder = class _Wefunder {
|
|
|
1127
1963
|
collect: () => collect((cursor) => this.campaigns.list({ cursor }))
|
|
1128
1964
|
};
|
|
1129
1965
|
syndicates = {
|
|
1130
|
-
list: this.#page(
|
|
1131
|
-
|
|
1132
|
-
|
|
1966
|
+
list: this.#page(
|
|
1967
|
+
listSyndicates
|
|
1968
|
+
),
|
|
1969
|
+
all: (query) => paginate((cursor) => this.syndicates.list({ ...query, cursor })),
|
|
1970
|
+
get: (id) => this.#unwrapData(
|
|
1971
|
+
getSyndicate({ client: this.#client, path: { id } })
|
|
1972
|
+
)
|
|
1133
1973
|
};
|
|
1134
1974
|
intents = {
|
|
1135
1975
|
list: this.#page(listIntents),
|
|
1136
|
-
all: () => paginate((cursor) => this.intents.list({ cursor })),
|
|
1137
|
-
get: (id) => this.#unwrapData(
|
|
1976
|
+
all: (query) => paginate((cursor) => this.intents.list({ ...query, cursor })),
|
|
1977
|
+
get: (id) => this.#unwrapData(
|
|
1978
|
+
getIntent({ client: this.#client, path: { id } })
|
|
1979
|
+
)
|
|
1138
1980
|
};
|
|
1139
1981
|
attribution = {
|
|
1140
|
-
me: () => this.#unwrapData(
|
|
1982
|
+
me: () => this.#unwrapData(
|
|
1983
|
+
getAttributionMe({ client: this.#client })
|
|
1984
|
+
)
|
|
1985
|
+
};
|
|
1986
|
+
/**
|
|
1987
|
+
* Webhook endpoints (`/webhook_endpoints`, scopes `read:webhooks` / `write:webhooks`).
|
|
1988
|
+
* Endpoints belong to your application and are managed through the LIVE API —
|
|
1989
|
+
* create sandbox receivers there with `mode: "test"`; they're mirrored into
|
|
1990
|
+
* sandbox. The signing `secret` is returned ONLY by `create` and `rotateSecret`.
|
|
1991
|
+
* Verify deliveries with `constructEvent` (see the webhooks module).
|
|
1992
|
+
*/
|
|
1993
|
+
webhookEndpoints = {
|
|
1994
|
+
/** All of your app's endpoints (secret omitted). `meta.quota` is the per-app limit. */
|
|
1995
|
+
list: () => this.#unwrap(
|
|
1996
|
+
listWebhookEndpoints({ client: this.#client })
|
|
1997
|
+
),
|
|
1998
|
+
get: (id) => this.#unwrapData(
|
|
1999
|
+
getWebhookEndpoint({
|
|
2000
|
+
client: this.#client,
|
|
2001
|
+
path: { external_id: id }
|
|
2002
|
+
})
|
|
2003
|
+
),
|
|
2004
|
+
/** Store `attributes.secret` from the result — it is never shown again. */
|
|
2005
|
+
create: (input) => this.#unwrapData(
|
|
2006
|
+
createWebhookEndpoint({ client: this.#client, body: input })
|
|
2007
|
+
),
|
|
2008
|
+
/** `events` replaces the subscription list wholesale (no merge); omit to leave unchanged. */
|
|
2009
|
+
update: (id, input) => this.#unwrapData(
|
|
2010
|
+
updateWebhookEndpoint({
|
|
2011
|
+
client: this.#client,
|
|
2012
|
+
path: { external_id: id },
|
|
2013
|
+
body: input
|
|
2014
|
+
})
|
|
2015
|
+
),
|
|
2016
|
+
/** Stops deliveries immediately. Removal is permanent — create a new endpoint to resume. */
|
|
2017
|
+
remove: (id) => this.#unwrapData(
|
|
2018
|
+
deleteWebhookEndpoint({
|
|
2019
|
+
client: this.#client,
|
|
2020
|
+
path: { external_id: id }
|
|
2021
|
+
})
|
|
2022
|
+
),
|
|
2023
|
+
/**
|
|
2024
|
+
* New secret (shown once). The old one keeps signing for a 24h overlap — deliveries
|
|
2025
|
+
* carry a `v1` for both, and `constructEvent` accepts either.
|
|
2026
|
+
*/
|
|
2027
|
+
rotateSecret: (id) => this.#unwrapData(
|
|
2028
|
+
rotateWebhookEndpointSecret({
|
|
2029
|
+
client: this.#client,
|
|
2030
|
+
path: { external_id: id }
|
|
2031
|
+
})
|
|
2032
|
+
),
|
|
2033
|
+
/** Recover an auto-disabled endpoint after fixing your server. Idempotent. */
|
|
2034
|
+
reenable: (id) => this.#unwrapData(
|
|
2035
|
+
reenableWebhookEndpoint({
|
|
2036
|
+
client: this.#client,
|
|
2037
|
+
path: { external_id: id }
|
|
2038
|
+
})
|
|
2039
|
+
),
|
|
2040
|
+
/**
|
|
2041
|
+
* POST a real, signed example event at the endpoint (production envelope + signature)
|
|
2042
|
+
* and report the outcome inline. Defaults to the endpoint's first subscribed event.
|
|
2043
|
+
* Doesn't affect delivery health. Rate-limited to 10/min per endpoint.
|
|
2044
|
+
*/
|
|
2045
|
+
test: (id, event) => this.#unwrapData(
|
|
2046
|
+
testWebhookEndpoint({
|
|
2047
|
+
client: this.#client,
|
|
2048
|
+
path: { external_id: id },
|
|
2049
|
+
body: event ? { event } : void 0
|
|
2050
|
+
})
|
|
2051
|
+
)
|
|
1141
2052
|
};
|
|
1142
2053
|
};
|
|
1143
2054
|
|
|
1144
2055
|
// src/webhooks.ts
|
|
1145
2056
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
1146
|
-
var SIGNATURE_HEADER = "
|
|
1147
|
-
var
|
|
1148
|
-
var
|
|
1149
|
-
var
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
2057
|
+
var SIGNATURE_HEADER = "wefunder-signature";
|
|
2058
|
+
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
2059
|
+
var LEGACY_SIGNATURE_HEADER = "x-wefunder-signature";
|
|
2060
|
+
var LEGACY_TIMESTAMP_HEADER = "x-wefunder-timestamp";
|
|
2061
|
+
var LEGACY_EVENT_HEADER = "x-wefunder-event";
|
|
2062
|
+
var LEGACY_DELIVERY_ID_HEADER = "x-wefunder-delivery-id";
|
|
2063
|
+
var WebhookSignatureError = class extends Error {
|
|
2064
|
+
reason;
|
|
2065
|
+
constructor(reason, message) {
|
|
2066
|
+
super(message);
|
|
2067
|
+
this.name = "WebhookSignatureError";
|
|
2068
|
+
this.reason = reason;
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
function bodyBuffer(payload) {
|
|
2072
|
+
return typeof payload === "string" ? Buffer.from(payload, "utf8") : Buffer.from(payload);
|
|
2073
|
+
}
|
|
2074
|
+
function computeWebhookSignature(secret, timestamp, payload) {
|
|
2075
|
+
return createHmac("sha256", secret).update(`${timestamp}.`).update(bodyBuffer(payload)).digest("hex");
|
|
1153
2076
|
}
|
|
1154
2077
|
function constantTimeEqual(a, b) {
|
|
1155
2078
|
const ab = Buffer.from(a);
|
|
@@ -1157,65 +2080,177 @@ function constantTimeEqual(a, b) {
|
|
|
1157
2080
|
if (ab.length !== bb.length) return false;
|
|
1158
2081
|
return timingSafeEqual(ab, bb);
|
|
1159
2082
|
}
|
|
2083
|
+
function parseSignatureHeader(header) {
|
|
2084
|
+
let timestamp;
|
|
2085
|
+
const signatures = [];
|
|
2086
|
+
for (const part of header.split(",")) {
|
|
2087
|
+
const eq = part.indexOf("=");
|
|
2088
|
+
if (eq < 0) continue;
|
|
2089
|
+
const key = part.slice(0, eq).trim();
|
|
2090
|
+
const value = part.slice(eq + 1).trim();
|
|
2091
|
+
if (key === "t") {
|
|
2092
|
+
if (!/^\d+$/.test(value)) return null;
|
|
2093
|
+
timestamp = Number(value);
|
|
2094
|
+
} else if (key === "v1" && value) {
|
|
2095
|
+
signatures.push(value);
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
if (timestamp === void 0 || signatures.length === 0) return null;
|
|
2099
|
+
return { timestamp, signatures };
|
|
2100
|
+
}
|
|
2101
|
+
function signWebhook(opts) {
|
|
2102
|
+
const t = opts.timestamp ?? Math.floor(Date.now() / 1e3);
|
|
2103
|
+
const secrets = [opts.secret, ...opts.additionalSecrets ?? []];
|
|
2104
|
+
const entries = secrets.map((s) => `v1=${computeWebhookSignature(s, t, opts.payload)}`);
|
|
2105
|
+
return [`t=${t}`, ...entries].join(",");
|
|
2106
|
+
}
|
|
2107
|
+
function checkWebhookSignature(opts) {
|
|
2108
|
+
const parsed = parseSignatureHeader(opts.header);
|
|
2109
|
+
if (!parsed) return "malformed_header";
|
|
2110
|
+
const tolerance = opts.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS;
|
|
2111
|
+
if (tolerance > 0) {
|
|
2112
|
+
const nowSec = (opts.now ?? Date.now)() / 1e3;
|
|
2113
|
+
if (Math.abs(nowSec - parsed.timestamp) > tolerance) return "timestamp_out_of_tolerance";
|
|
2114
|
+
}
|
|
2115
|
+
const expected = computeWebhookSignature(opts.secret, parsed.timestamp, opts.payload);
|
|
2116
|
+
return parsed.signatures.some((sig) => constantTimeEqual(sig, expected)) ? null : "signature_mismatch";
|
|
2117
|
+
}
|
|
1160
2118
|
function verifyWebhook(opts) {
|
|
1161
|
-
|
|
1162
|
-
|
|
2119
|
+
if ("header" in opts) return checkWebhookSignature(opts) === null;
|
|
2120
|
+
return verifyLegacyWebhook(opts);
|
|
2121
|
+
}
|
|
2122
|
+
function verifyLegacyWebhook(opts) {
|
|
2123
|
+
const tolerance = opts.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS;
|
|
1163
2124
|
const ts = Number(opts.timestamp);
|
|
1164
2125
|
if (!Number.isFinite(ts)) return false;
|
|
1165
|
-
if (tolerance > 0 && Math.abs(now / 1e3 - ts) > tolerance) return false;
|
|
1166
|
-
const expected =
|
|
2126
|
+
if (tolerance > 0 && Math.abs((opts.now ?? Date.now)() / 1e3 - ts) > tolerance) return false;
|
|
2127
|
+
const expected = `sha256=${computeWebhookSignature(opts.secret, opts.timestamp, opts.payload)}`;
|
|
1167
2128
|
return constantTimeEqual(opts.signature, expected);
|
|
1168
2129
|
}
|
|
1169
|
-
function
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
2130
|
+
function headerGetter(headers) {
|
|
2131
|
+
if (typeof headers === "string") {
|
|
2132
|
+
return (name) => name === SIGNATURE_HEADER ? headers : void 0;
|
|
2133
|
+
}
|
|
2134
|
+
if (headers instanceof Headers) return (name) => headers.get(name) ?? void 0;
|
|
2135
|
+
return (name) => {
|
|
2136
|
+
let v = headers[name];
|
|
2137
|
+
if (v === void 0) {
|
|
2138
|
+
const hit = Object.keys(headers).find((k) => k.toLowerCase() === name);
|
|
2139
|
+
if (hit) v = headers[hit];
|
|
2140
|
+
}
|
|
1173
2141
|
return Array.isArray(v) ? v[0] : v;
|
|
1174
2142
|
};
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
2143
|
+
}
|
|
2144
|
+
function constructEvent(payload, headers, secret, opts) {
|
|
2145
|
+
const get = headerGetter(headers);
|
|
2146
|
+
const header = get(SIGNATURE_HEADER);
|
|
2147
|
+
if (!header) {
|
|
2148
|
+
const legacySig = get(LEGACY_SIGNATURE_HEADER);
|
|
2149
|
+
const legacyTs = get(LEGACY_TIMESTAMP_HEADER);
|
|
2150
|
+
if (legacySig && legacyTs) return constructLegacyEvent(payload, get, legacySig, legacyTs, secret, opts);
|
|
2151
|
+
throw new WebhookSignatureError("missing_header", describeFailure("missing_header"));
|
|
2152
|
+
}
|
|
2153
|
+
const failure = checkWebhookSignature({ payload, header, secret, ...opts });
|
|
2154
|
+
if (failure) throw new WebhookSignatureError(failure, describeFailure(failure));
|
|
2155
|
+
const parsed = parseSignatureHeader(header);
|
|
2156
|
+
const env = parseEnvelope(payload);
|
|
1189
2157
|
return {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
2158
|
+
id: String(env.id ?? ""),
|
|
2159
|
+
event: String(env.event ?? ""),
|
|
2160
|
+
created_at: String(env.created_at ?? ""),
|
|
2161
|
+
mode: env.mode === "test" ? "test" : "live",
|
|
2162
|
+
data: env.data,
|
|
2163
|
+
timestamp: parsed.timestamp
|
|
1194
2164
|
};
|
|
1195
2165
|
}
|
|
2166
|
+
function constructLegacyEvent(payload, get, signature, timestamp, secret, opts) {
|
|
2167
|
+
if (!verifyLegacyWebhook({ payload, signature, timestamp, secret, ...opts })) {
|
|
2168
|
+
throw new WebhookSignatureError("signature_mismatch", describeFailure("signature_mismatch"));
|
|
2169
|
+
}
|
|
2170
|
+
const env = parseEnvelope(payload);
|
|
2171
|
+
return {
|
|
2172
|
+
id: String(env.id ?? get(LEGACY_DELIVERY_ID_HEADER) ?? ""),
|
|
2173
|
+
event: String(env.event ?? get(LEGACY_EVENT_HEADER) ?? ""),
|
|
2174
|
+
created_at: String(env.created_at ?? ""),
|
|
2175
|
+
mode: env.mode === "test" ? "test" : "live",
|
|
2176
|
+
data: env.data ?? env,
|
|
2177
|
+
timestamp: Number(timestamp)
|
|
2178
|
+
};
|
|
2179
|
+
}
|
|
2180
|
+
function parseEnvelope(payload) {
|
|
2181
|
+
try {
|
|
2182
|
+
const parsed = JSON.parse(bodyBuffer(payload).toString("utf8"));
|
|
2183
|
+
if (parsed === null || typeof parsed !== "object") throw new Error("not an object");
|
|
2184
|
+
return parsed;
|
|
2185
|
+
} catch {
|
|
2186
|
+
throw new WebhookSignatureError("invalid_payload", describeFailure("invalid_payload"));
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
function describeFailure(reason) {
|
|
2190
|
+
switch (reason) {
|
|
2191
|
+
case "missing_header":
|
|
2192
|
+
return "Missing Wefunder-Signature header";
|
|
2193
|
+
case "malformed_header":
|
|
2194
|
+
return "Wefunder-Signature header is malformed (expected t=<unix>,v1=<hex>)";
|
|
2195
|
+
case "timestamp_out_of_tolerance":
|
|
2196
|
+
return "Webhook timestamp is outside the replay tolerance";
|
|
2197
|
+
case "signature_mismatch":
|
|
2198
|
+
return "Webhook signature verification failed";
|
|
2199
|
+
case "invalid_payload":
|
|
2200
|
+
return "Webhook body is not a JSON object";
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
async function constructEventFromRequest(request, secret, opts) {
|
|
2204
|
+
const payload = await request.text();
|
|
2205
|
+
return constructEvent(payload, request.headers, secret, opts);
|
|
2206
|
+
}
|
|
2207
|
+
async function dispatchWebhook(event, handlers) {
|
|
2208
|
+
const specific = event.event === "default" ? void 0 : handlers[event.event];
|
|
2209
|
+
if (specific) {
|
|
2210
|
+
await specific(event);
|
|
2211
|
+
return true;
|
|
2212
|
+
}
|
|
2213
|
+
if (handlers.default) {
|
|
2214
|
+
await handlers.default(event);
|
|
2215
|
+
return true;
|
|
2216
|
+
}
|
|
2217
|
+
return false;
|
|
2218
|
+
}
|
|
1196
2219
|
export {
|
|
1197
2220
|
DEFAULT_API_BASE_URL,
|
|
1198
2221
|
DEFAULT_API_VERSION,
|
|
1199
2222
|
DEFAULT_AUTHORIZE_BASE_URL,
|
|
1200
2223
|
DEFAULT_OAUTH_BASE_URL,
|
|
1201
2224
|
DEFAULT_TOKEN_BASE_URL,
|
|
1202
|
-
|
|
1203
|
-
|
|
2225
|
+
DEFAULT_TOLERANCE_SECONDS,
|
|
2226
|
+
LEGACY_DELIVERY_ID_HEADER,
|
|
2227
|
+
LEGACY_EVENT_HEADER,
|
|
2228
|
+
LEGACY_SIGNATURE_HEADER,
|
|
2229
|
+
LEGACY_TIMESTAMP_HEADER,
|
|
1204
2230
|
REQUEST_ID_HEADER,
|
|
2231
|
+
SANDBOX_AUTHORIZE_BASE_URL,
|
|
1205
2232
|
SIGNATURE_HEADER,
|
|
1206
|
-
|
|
2233
|
+
TokenManager,
|
|
2234
|
+
WebhookSignatureError,
|
|
1207
2235
|
Wefunder,
|
|
1208
2236
|
WefunderAuthError,
|
|
1209
2237
|
WefunderError,
|
|
2238
|
+
WefunderTokenPersistenceError,
|
|
2239
|
+
checkWebhookSignature,
|
|
1210
2240
|
clientCredentialsGrant,
|
|
1211
2241
|
collect,
|
|
2242
|
+
computeWebhookSignature,
|
|
1212
2243
|
constructEvent,
|
|
2244
|
+
constructEventFromRequest,
|
|
1213
2245
|
createAuthorizationUrl,
|
|
2246
|
+
dispatchWebhook,
|
|
1214
2247
|
exchangeCode,
|
|
1215
2248
|
generatePkce,
|
|
1216
2249
|
modeForToken,
|
|
1217
2250
|
paginate,
|
|
2251
|
+
parseSignatureHeader,
|
|
1218
2252
|
refreshToken,
|
|
2253
|
+
signWebhook,
|
|
1219
2254
|
verifyWebhook
|
|
1220
2255
|
};
|
|
1221
2256
|
//# sourceMappingURL=index.js.map
|