@withone/sdk 0.0.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/dist/index.d.mts +449 -33
- package/dist/index.d.ts +449 -33
- package/dist/index.js +422 -42
- package/dist/index.mjs +423 -43
- package/native.d.ts +52 -3
- package/native.js +1 -0
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,9 +1,370 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;
|
|
2
2
|
|
|
3
3
|
var _chunkKPQGG74Ujs = require('./chunk-KPQGG74U.js');
|
|
4
4
|
|
|
5
5
|
// src/client.ts
|
|
6
6
|
var _nativejs = require('../native.js');
|
|
7
|
+
|
|
8
|
+
// src/errors.ts
|
|
9
|
+
var OneError = class extends Error {
|
|
10
|
+
constructor(code, message, status, body, retryable) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.body = body;
|
|
15
|
+
this.retryable = retryable;
|
|
16
|
+
this.name = "OneError";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
};
|
|
23
|
+
function toOneError(error) {
|
|
24
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
25
|
+
try {
|
|
26
|
+
const envelope = JSON.parse(message);
|
|
27
|
+
return new OneError(envelope.code, envelope.message, envelope.status, envelope.body, envelope.retryable);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return new OneError("unknown", message, void 0, void 0, false);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/webhooks.ts
|
|
34
|
+
|
|
35
|
+
var WebhooksBase = (_class = class {
|
|
36
|
+
constructor(client, options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
37
|
+
this.client = client;
|
|
38
|
+
this.options = options;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
__init() {this.handlers = /* @__PURE__ */ new Map()}
|
|
43
|
+
__init2() {this.anyHandlers = []}
|
|
44
|
+
/** @internal Registers a typed handler; generated methods wrap this. */
|
|
45
|
+
register(event, connection, run) {
|
|
46
|
+
const existing = _nullishCoalesce(this.handlers.get(event), () => ( []));
|
|
47
|
+
existing.push({ connection, run });
|
|
48
|
+
this.handlers.set(event, existing);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Registers handlers scoped to one connection: they fire only for deliveries
|
|
53
|
+
* carrying that connection's key.
|
|
54
|
+
*
|
|
55
|
+
* The block keeps the scope lexical, so a reader never has to scan backwards
|
|
56
|
+
* to work out which connection a handler belongs to, and only the
|
|
57
|
+
* connection-carrying events are offered inside it.
|
|
58
|
+
*/
|
|
59
|
+
connection(key, block) {
|
|
60
|
+
const scope = new (this.scopeConstructor())(key);
|
|
61
|
+
block(scope);
|
|
62
|
+
for (const [event, registered] of scope.drain()) {
|
|
63
|
+
const existing = _nullishCoalesce(this.handlers.get(event), () => ( []));
|
|
64
|
+
existing.push(...registered);
|
|
65
|
+
this.handlers.set(event, existing);
|
|
66
|
+
}
|
|
67
|
+
this.anyHandlers.push(...scope.drainAny());
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/** @internal The generated subclass supplies its own scope type. */
|
|
71
|
+
scopeConstructor() {
|
|
72
|
+
return ConnectionWebhooksBase;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Registers a handler fired for every verified delivery, including event
|
|
76
|
+
* types this SDK build does not recognize. Runs after event-specific
|
|
77
|
+
* handlers.
|
|
78
|
+
*/
|
|
79
|
+
onAny(handler) {
|
|
80
|
+
this.anyHandlers.push({ connection: null, run: handler });
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The event types `listen` subscribes to.
|
|
85
|
+
*
|
|
86
|
+
* An unscoped catch-all subscribes to this build's whole catalog; the server
|
|
87
|
+
* matches exact event strings, so events added after this build are not
|
|
88
|
+
* covered. A catch-all scoped to a connection adds only the
|
|
89
|
+
* connection-carrying events, since the server cannot filter by connection
|
|
90
|
+
* and the rest would just be discarded on arrival.
|
|
91
|
+
*/
|
|
92
|
+
events() {
|
|
93
|
+
if (this.anyHandlers.some((handler) => handler.connection === null)) return [...this.catalog()];
|
|
94
|
+
const events = new Set(this.handlers.keys());
|
|
95
|
+
if (this.anyHandlers.length > 0) {
|
|
96
|
+
for (const event of this.connectionCatalog()) events.add(event);
|
|
97
|
+
}
|
|
98
|
+
return [...events].sort();
|
|
99
|
+
}
|
|
100
|
+
/** @internal The generated subclass supplies the full event catalog. */
|
|
101
|
+
catalog() {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
/** @internal The generated subclass supplies the connection-carrying subset. */
|
|
105
|
+
connectionCatalog() {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Verifies the signature and freshness of a delivery without dispatching.
|
|
110
|
+
* Use it when you want to route deliveries yourself.
|
|
111
|
+
*
|
|
112
|
+
* `rawBody` must be the exact bytes One sent. A JSON body parser that has
|
|
113
|
+
* already re-serialized the request will fail verification.
|
|
114
|
+
*/
|
|
115
|
+
verify(rawBody, signature) {
|
|
116
|
+
try {
|
|
117
|
+
const verified = _nativejs.verifyWebhook.call(void 0, rawBody, signature, this.options.secret, this.options.toleranceMs);
|
|
118
|
+
return {
|
|
119
|
+
event: verified.event,
|
|
120
|
+
id: verified.eventId,
|
|
121
|
+
timestamp: new Date(verified.timestamp),
|
|
122
|
+
payload: verified.payload,
|
|
123
|
+
metadata: _nullishCoalesce(verified.metadata, () => ( null)),
|
|
124
|
+
connection: _nullishCoalesce(verified.connection, () => ( null)),
|
|
125
|
+
isTest: verified.isTest
|
|
126
|
+
};
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw toOneError(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Verifies, parses, and dispatches a delivery to every handler registered for
|
|
133
|
+
* its event type, then to the catch-all handlers. Handlers run sequentially
|
|
134
|
+
* and are awaited.
|
|
135
|
+
*/
|
|
136
|
+
async handle(rawBody, signature) {
|
|
137
|
+
const delivery = this.verify(rawBody, signature);
|
|
138
|
+
const accepts = (registered) => registered.connection === null || registered.connection === delivery.connection;
|
|
139
|
+
let failure;
|
|
140
|
+
const run = async (registered) => {
|
|
141
|
+
try {
|
|
142
|
+
await registered.run(delivery);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
failure ??= { error };
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
if (!delivery.isTest) {
|
|
148
|
+
for (const registered of (_nullishCoalesce(this.handlers.get(delivery.event), () => ( []))).filter(accepts)) {
|
|
149
|
+
await run(registered);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
for (const registered of this.anyHandlers.filter(accepts)) {
|
|
153
|
+
await run(registered);
|
|
154
|
+
}
|
|
155
|
+
if (failure) throw failure.error;
|
|
156
|
+
return delivery;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Registers this listener with One under the stable name `key`, pointing at
|
|
160
|
+
* `url` and subscribing to exactly the events handlers were attached for.
|
|
161
|
+
*
|
|
162
|
+
* Idempotent: calling it on every boot reconciles the one listener named
|
|
163
|
+
* `key` rather than accumulating duplicates.
|
|
164
|
+
*/
|
|
165
|
+
async listen(key, url) {
|
|
166
|
+
return this.client.registerWebhook(key, url, this.events(), this.options.secret);
|
|
167
|
+
}
|
|
168
|
+
}, _class);
|
|
169
|
+
var ConnectionWebhooksBase = (_class2 = class {
|
|
170
|
+
constructor(key) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);
|
|
171
|
+
this.key = key;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
__init3() {this.handlers = /* @__PURE__ */ new Map()}
|
|
175
|
+
__init4() {this.anyHandlers = []}
|
|
176
|
+
/** @internal Registers a typed handler; generated methods wrap this. */
|
|
177
|
+
register(event, run) {
|
|
178
|
+
const existing = _nullishCoalesce(this.handlers.get(event), () => ( []));
|
|
179
|
+
existing.push({ connection: this.key, run });
|
|
180
|
+
this.handlers.set(event, existing);
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
/** Registers a handler for every event concerning this connection. */
|
|
184
|
+
onAny(handler) {
|
|
185
|
+
this.anyHandlers.push({ connection: this.key, run: handler });
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
/** @internal Hands the collected handlers to the parent registry. */
|
|
189
|
+
drain() {
|
|
190
|
+
return this.handlers;
|
|
191
|
+
}
|
|
192
|
+
/** @internal Hands the collected catch-all handlers to the parent registry. */
|
|
193
|
+
drainAny() {
|
|
194
|
+
return this.anyHandlers;
|
|
195
|
+
}
|
|
196
|
+
}, _class2);
|
|
197
|
+
|
|
198
|
+
// src/webhooks.generated.ts
|
|
199
|
+
var ALL_WEBHOOK_EVENTS = [
|
|
200
|
+
"api_key.created",
|
|
201
|
+
"api_key.revoked",
|
|
202
|
+
"connection.created",
|
|
203
|
+
"connection.deleted",
|
|
204
|
+
"connection.oauth.created",
|
|
205
|
+
"connection.updated",
|
|
206
|
+
"member.added",
|
|
207
|
+
"member.removed",
|
|
208
|
+
"member.role_updated",
|
|
209
|
+
"oauth.failed",
|
|
210
|
+
"oauth.refreshed",
|
|
211
|
+
"organization.created",
|
|
212
|
+
"organization.deleted",
|
|
213
|
+
"organization.updated",
|
|
214
|
+
"passthrough.executed",
|
|
215
|
+
"project.created",
|
|
216
|
+
"project.deleted",
|
|
217
|
+
"project.updated"
|
|
218
|
+
];
|
|
219
|
+
var CONNECTION_SCOPED_EVENTS = [
|
|
220
|
+
"connection.created",
|
|
221
|
+
"connection.deleted",
|
|
222
|
+
"connection.oauth.created",
|
|
223
|
+
"connection.updated",
|
|
224
|
+
"oauth.failed",
|
|
225
|
+
"oauth.refreshed",
|
|
226
|
+
"passthrough.executed"
|
|
227
|
+
];
|
|
228
|
+
var Webhooks = class extends WebhooksBase {
|
|
229
|
+
/** Scopes to the generated connection registry, so a `connection(..)` block
|
|
230
|
+
* offers the typed per-event methods rather than the bare base. */
|
|
231
|
+
scopeConstructor() {
|
|
232
|
+
return ConnectionWebhooks;
|
|
233
|
+
}
|
|
234
|
+
/** The full catalog, so an unscoped catch-all subscribes to everything. */
|
|
235
|
+
catalog() {
|
|
236
|
+
return ALL_WEBHOOK_EVENTS;
|
|
237
|
+
}
|
|
238
|
+
/** The connection-carrying subset, for a catch-all scoped to a connection. */
|
|
239
|
+
connectionCatalog() {
|
|
240
|
+
return CONNECTION_SCOPED_EVENTS;
|
|
241
|
+
}
|
|
242
|
+
/** Narrows the block's scope to the typed registry. */
|
|
243
|
+
connection(key, block) {
|
|
244
|
+
return super.connection(key, block);
|
|
245
|
+
}
|
|
246
|
+
/** Registers a handler for `api_key.created`. */
|
|
247
|
+
apiKeyCreated(handler) {
|
|
248
|
+
return this.register("api_key.created", null, handler);
|
|
249
|
+
}
|
|
250
|
+
/** Registers a handler for `api_key.revoked`. */
|
|
251
|
+
apiKeyRevoked(handler) {
|
|
252
|
+
return this.register("api_key.revoked", null, handler);
|
|
253
|
+
}
|
|
254
|
+
/** Registers a handler for `connection.created`. */
|
|
255
|
+
connectionCreated(handler) {
|
|
256
|
+
return this.register("connection.created", null, handler);
|
|
257
|
+
}
|
|
258
|
+
/** Registers a handler for `connection.deleted`. */
|
|
259
|
+
connectionDeleted(handler) {
|
|
260
|
+
return this.register("connection.deleted", null, handler);
|
|
261
|
+
}
|
|
262
|
+
/** Registers a handler for `connection.oauth.created`. */
|
|
263
|
+
connectionOauthCreated(handler) {
|
|
264
|
+
return this.register("connection.oauth.created", null, handler);
|
|
265
|
+
}
|
|
266
|
+
/** Registers a handler for `connection.updated`. */
|
|
267
|
+
connectionUpdated(handler) {
|
|
268
|
+
return this.register("connection.updated", null, handler);
|
|
269
|
+
}
|
|
270
|
+
/** Registers a handler for `member.added`. */
|
|
271
|
+
memberAdded(handler) {
|
|
272
|
+
return this.register("member.added", null, handler);
|
|
273
|
+
}
|
|
274
|
+
/** Registers a handler for `member.removed`. */
|
|
275
|
+
memberRemoved(handler) {
|
|
276
|
+
return this.register("member.removed", null, handler);
|
|
277
|
+
}
|
|
278
|
+
/** Registers a handler for `member.role_updated`. */
|
|
279
|
+
memberRoleUpdated(handler) {
|
|
280
|
+
return this.register("member.role_updated", null, handler);
|
|
281
|
+
}
|
|
282
|
+
/** Registers a handler for `oauth.failed`. */
|
|
283
|
+
oauthFailed(handler) {
|
|
284
|
+
return this.register("oauth.failed", null, handler);
|
|
285
|
+
}
|
|
286
|
+
/** Registers a handler for `oauth.refreshed`. */
|
|
287
|
+
oauthRefreshed(handler) {
|
|
288
|
+
return this.register("oauth.refreshed", null, handler);
|
|
289
|
+
}
|
|
290
|
+
/** Registers a handler for `organization.created`. */
|
|
291
|
+
organizationCreated(handler) {
|
|
292
|
+
return this.register("organization.created", null, handler);
|
|
293
|
+
}
|
|
294
|
+
/** Registers a handler for `organization.deleted`. */
|
|
295
|
+
organizationDeleted(handler) {
|
|
296
|
+
return this.register("organization.deleted", null, handler);
|
|
297
|
+
}
|
|
298
|
+
/** Registers a handler for `organization.updated`. */
|
|
299
|
+
organizationUpdated(handler) {
|
|
300
|
+
return this.register("organization.updated", null, handler);
|
|
301
|
+
}
|
|
302
|
+
/** Registers a handler for `passthrough.executed`. */
|
|
303
|
+
passthroughExecuted(handler) {
|
|
304
|
+
return this.register("passthrough.executed", null, handler);
|
|
305
|
+
}
|
|
306
|
+
/** Registers a handler for `project.created`. */
|
|
307
|
+
projectCreated(handler) {
|
|
308
|
+
return this.register("project.created", null, handler);
|
|
309
|
+
}
|
|
310
|
+
/** Registers a handler for `project.deleted`. */
|
|
311
|
+
projectDeleted(handler) {
|
|
312
|
+
return this.register("project.deleted", null, handler);
|
|
313
|
+
}
|
|
314
|
+
/** Registers a handler for `project.updated`. */
|
|
315
|
+
projectUpdated(handler) {
|
|
316
|
+
return this.register("project.updated", null, handler);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
var ConnectionWebhooks = class extends ConnectionWebhooksBase {
|
|
320
|
+
/** Registers a handler for `connection.created` on this connection. */
|
|
321
|
+
connectionCreated(handler) {
|
|
322
|
+
return this.register("connection.created", handler);
|
|
323
|
+
}
|
|
324
|
+
/** Registers a handler for `connection.deleted` on this connection. */
|
|
325
|
+
connectionDeleted(handler) {
|
|
326
|
+
return this.register("connection.deleted", handler);
|
|
327
|
+
}
|
|
328
|
+
/** Registers a handler for `connection.oauth.created` on this connection. */
|
|
329
|
+
connectionOauthCreated(handler) {
|
|
330
|
+
return this.register("connection.oauth.created", handler);
|
|
331
|
+
}
|
|
332
|
+
/** Registers a handler for `connection.updated` on this connection. */
|
|
333
|
+
connectionUpdated(handler) {
|
|
334
|
+
return this.register("connection.updated", handler);
|
|
335
|
+
}
|
|
336
|
+
/** Registers a handler for `oauth.failed` on this connection. */
|
|
337
|
+
oauthFailed(handler) {
|
|
338
|
+
return this.register("oauth.failed", handler);
|
|
339
|
+
}
|
|
340
|
+
/** Registers a handler for `oauth.refreshed` on this connection. */
|
|
341
|
+
oauthRefreshed(handler) {
|
|
342
|
+
return this.register("oauth.refreshed", handler);
|
|
343
|
+
}
|
|
344
|
+
/** Registers a handler for `passthrough.executed` on this connection. */
|
|
345
|
+
passthroughExecuted(handler) {
|
|
346
|
+
return this.register("passthrough.executed", handler);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// src/client.ts
|
|
351
|
+
var CallLifecycle = class {
|
|
352
|
+
constructor(hooks) {
|
|
353
|
+
this.hooks = hooks;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async execute(call, complete) {
|
|
357
|
+
try {
|
|
358
|
+
const completed = complete(await call());
|
|
359
|
+
_optionalChain([this, 'access', _ => _.hooks, 'access', _2 => _2.onSuccess, 'optionalCall', _3 => _3(completed.result)]);
|
|
360
|
+
return completed.output;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
const err = toOneError(error);
|
|
363
|
+
_optionalChain([this, 'access', _4 => _4.hooks, 'access', _5 => _5.onError, 'optionalCall', _6 => _6(err)]);
|
|
364
|
+
throw err;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
7
368
|
var One = class _One {
|
|
8
369
|
|
|
9
370
|
|
|
@@ -14,30 +375,73 @@ var One = class _One {
|
|
|
14
375
|
} catch (error) {
|
|
15
376
|
throw toOneError(error);
|
|
16
377
|
}
|
|
17
|
-
this.
|
|
378
|
+
this.lifecycle = new CallLifecycle({ onSuccess, onError });
|
|
18
379
|
}
|
|
19
|
-
/**
|
|
380
|
+
/**
|
|
381
|
+
* Creates a client that authenticates on an end user's OAuth grant.
|
|
382
|
+
*
|
|
383
|
+
* The counterpart to the constructor, as a factory because a class can only
|
|
384
|
+
* have one constructor and the two credentials are alternatives: a client
|
|
385
|
+
* authenticates as an agency with its secret key, or on a user's grant with
|
|
386
|
+
* their token, never both. What the token may reach is the scopes the user
|
|
387
|
+
* consented to, so a call outside them fails at the API, not here.
|
|
388
|
+
*/
|
|
389
|
+
static withAccessToken(accessToken, options) {
|
|
390
|
+
const { onSuccess, onError, ...native } = _nullishCoalesce(options, () => ( {}));
|
|
391
|
+
return _One.wrapping(() => _nativejs.One.withAccessToken(accessToken, native), { onSuccess, onError });
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Creates a client from the environment: `ONE_SECRET` or `ONE_ACCESS_TOKEN`
|
|
395
|
+
* for the credential, plus the optional `ONE_BASE_URL`. `ONE_SECRET` wins
|
|
396
|
+
* when both are set.
|
|
397
|
+
*/
|
|
20
398
|
static fromEnv() {
|
|
399
|
+
return _One.wrapping(() => _nativejs.One.fromEnv(), {});
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Builds a facade around a native client a factory produced, bypassing the
|
|
403
|
+
* constructor because that one takes a secret key. One place assigns the
|
|
404
|
+
* fields, so a new factory cannot forget the lifecycle and leave hooks
|
|
405
|
+
* silently unfired.
|
|
406
|
+
*/
|
|
407
|
+
static wrapping(build, hooks) {
|
|
21
408
|
const client = Object.create(_One.prototype);
|
|
22
409
|
const fields = client;
|
|
23
410
|
try {
|
|
24
|
-
fields.native =
|
|
411
|
+
fields.native = build();
|
|
25
412
|
} catch (error) {
|
|
26
413
|
throw toOneError(error);
|
|
27
414
|
}
|
|
28
|
-
fields.
|
|
415
|
+
fields.lifecycle = new CallLifecycle(hooks);
|
|
29
416
|
return client;
|
|
30
417
|
}
|
|
31
418
|
/** Scopes subsequent calls to a connection by its key. */
|
|
32
419
|
connection(key) {
|
|
33
|
-
return new ConnectionScope(this.native, key, this.
|
|
420
|
+
return new ConnectionScope(this.native, key, this.lifecycle);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Starts building a webhook listener, verified with the subscription's
|
|
424
|
+
* signing secret.
|
|
425
|
+
*/
|
|
426
|
+
webhooks(options) {
|
|
427
|
+
return new Webhooks(this, options);
|
|
428
|
+
}
|
|
429
|
+
/** @internal Registers a webhook listener; the route and request shape live in Rust. */
|
|
430
|
+
async registerWebhook(key, url, events, secret) {
|
|
431
|
+
return this.lifecycle.execute(
|
|
432
|
+
() => this.native.registerWebhook(key, url, events, secret),
|
|
433
|
+
(result) => {
|
|
434
|
+
const out = new CallResult(result.status, result.headers, result.data);
|
|
435
|
+
return { output: result.data, result: out };
|
|
436
|
+
}
|
|
437
|
+
);
|
|
34
438
|
}
|
|
35
439
|
};
|
|
36
440
|
var ConnectionScope = class {
|
|
37
|
-
constructor(native, key,
|
|
441
|
+
constructor(native, key, lifecycle) {
|
|
38
442
|
this.native = native;
|
|
39
443
|
this.key = key;
|
|
40
|
-
this.
|
|
444
|
+
this.lifecycle = lifecycle;
|
|
41
445
|
}
|
|
42
446
|
|
|
43
447
|
|
|
@@ -56,16 +460,13 @@ var ConnectionScope = class {
|
|
|
56
460
|
return this.execute({ connectionKey: this.key, ...request }, options);
|
|
57
461
|
}
|
|
58
462
|
async execute(request, options) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_optionalChain([this, 'access', _4 => _4.hooks, 'access', _5 => _5.onError, 'optionalCall', _6 => _6(err)]);
|
|
67
|
-
throw err;
|
|
68
|
-
}
|
|
463
|
+
return this.lifecycle.execute(
|
|
464
|
+
() => this.native.run({ ...request, ..._nullishCoalesce(options, () => ( {})) }),
|
|
465
|
+
(result) => {
|
|
466
|
+
const out = new CallResult(result.status, result.headers, result.data);
|
|
467
|
+
return { output: out, result: out };
|
|
468
|
+
}
|
|
469
|
+
);
|
|
69
470
|
}
|
|
70
471
|
};
|
|
71
472
|
var CallResult = class {
|
|
@@ -82,33 +483,12 @@ var CallResult = class {
|
|
|
82
483
|
return this.data;
|
|
83
484
|
}
|
|
84
485
|
};
|
|
85
|
-
var OneError = class extends Error {
|
|
86
|
-
constructor(code, message, status, body, retryable) {
|
|
87
|
-
super(message);
|
|
88
|
-
this.code = code;
|
|
89
|
-
this.status = status;
|
|
90
|
-
this.body = body;
|
|
91
|
-
this.retryable = retryable;
|
|
92
|
-
this.name = "OneError";
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
99
|
-
function toOneError(error) {
|
|
100
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
101
|
-
try {
|
|
102
|
-
const envelope = JSON.parse(message);
|
|
103
|
-
return new OneError(envelope.code, envelope.message, envelope.status, envelope.body, envelope.retryable);
|
|
104
|
-
} catch (e) {
|
|
105
|
-
return new OneError("unknown", message, void 0, void 0, false);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
486
|
|
|
109
487
|
|
|
110
488
|
|
|
111
489
|
|
|
112
490
|
|
|
113
491
|
|
|
114
|
-
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
exports.Action = _chunkKPQGG74Ujs.Action; exports.CallResult = CallResult; exports.ConnectionScope = ConnectionScope; exports.ConnectionWebhooks = ConnectionWebhooks; exports.One = One; exports.OneError = OneError; exports.Webhooks = Webhooks;
|