@dereekb/nestjs 13.38.0 → 13.40.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/eslint/package.json +7 -7
- package/mailgun/package.json +11 -11
- package/openai/package.json +11 -11
- package/openrouter/package.json +8 -8
- package/package.json +27 -35
- package/stripe/package.json +11 -11
- package/twilio/index.esm.js +18 -1
- package/twilio/package.json +11 -11
- package/twilio/src/lib/twilio.api.d.ts +1 -1
- package/twilio/src/lib/twilio.interop.d.ts +7 -0
- package/typeform/package.json +11 -11
- package/vapiai/package.json +11 -11
- package/eslint/index.cjs.default.js +0 -1
- package/eslint/index.cjs.js +0 -418
- package/eslint/index.cjs.mjs +0 -2
- package/index.cjs.default.js +0 -1
- package/index.cjs.js +0 -2789
- package/index.cjs.mjs +0 -2
- package/mailgun/index.cjs.default.js +0 -1
- package/mailgun/index.cjs.js +0 -1802
- package/mailgun/index.cjs.mjs +0 -2
- package/openai/index.cjs.default.js +0 -1
- package/openai/index.cjs.js +0 -1068
- package/openai/index.cjs.mjs +0 -2
- package/openrouter/index.cjs.default.js +0 -1
- package/openrouter/index.cjs.js +0 -1200
- package/openrouter/index.cjs.mjs +0 -2
- package/stripe/index.cjs.default.js +0 -1
- package/stripe/index.cjs.js +0 -780
- package/stripe/index.cjs.mjs +0 -2
- package/twilio/index.cjs.default.js +0 -1
- package/twilio/index.cjs.js +0 -2184
- package/twilio/index.cjs.mjs +0 -2
- package/typeform/index.cjs.default.js +0 -1
- package/typeform/index.cjs.js +0 -1182
- package/typeform/index.cjs.mjs +0 -2
- package/vapiai/index.cjs.default.js +0 -1
- package/vapiai/index.cjs.js +0 -1055
- package/vapiai/index.cjs.mjs +0 -2
package/openai/index.cjs.js
DELETED
|
@@ -1,1068 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var util = require('@dereekb/util');
|
|
4
|
-
var nestjs = require('@dereekb/nestjs');
|
|
5
|
-
var common = require('@nestjs/common');
|
|
6
|
-
var openai = require('openai');
|
|
7
|
-
var config = require('@nestjs/config');
|
|
8
|
-
|
|
9
|
-
function _define_property$5(obj, key, value) {
|
|
10
|
-
if (key in obj) {
|
|
11
|
-
Object.defineProperty(obj, key, {
|
|
12
|
-
value: value,
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true
|
|
16
|
-
});
|
|
17
|
-
} else {
|
|
18
|
-
obj[key] = value;
|
|
19
|
-
}
|
|
20
|
-
return obj;
|
|
21
|
-
}
|
|
22
|
-
function _object_spread(target) {
|
|
23
|
-
for(var i = 1; i < arguments.length; i++){
|
|
24
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
25
|
-
var ownKeys = Object.keys(source);
|
|
26
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
27
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
28
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
ownKeys.forEach(function(key) {
|
|
32
|
-
_define_property$5(target, key, source[key]);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
}
|
|
37
|
-
function ownKeys(object, enumerableOnly) {
|
|
38
|
-
var keys = Object.keys(object);
|
|
39
|
-
if (Object.getOwnPropertySymbols) {
|
|
40
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
41
|
-
keys.push.apply(keys, symbols);
|
|
42
|
-
}
|
|
43
|
-
return keys;
|
|
44
|
-
}
|
|
45
|
-
function _object_spread_props(target, source) {
|
|
46
|
-
source = source != null ? source : {};
|
|
47
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
48
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
49
|
-
} else {
|
|
50
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
51
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return target;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Creates a OpenAIWebhookEvent and treats the data as the input type.
|
|
58
|
-
*
|
|
59
|
-
* @param event
|
|
60
|
-
* @returns
|
|
61
|
-
*/ function openAIWebhookEvent(event) {
|
|
62
|
-
return event;
|
|
63
|
-
}
|
|
64
|
-
var openaiEventHandlerFactory = util.handlerFactory(function(x) {
|
|
65
|
-
return x.type;
|
|
66
|
-
});
|
|
67
|
-
var openaiEventHandlerConfigurerFactory = util.handlerConfigurerFactory({
|
|
68
|
-
configurerForAccessor: function configurerForAccessor(accessor) {
|
|
69
|
-
var fnWithKey = util.handlerMappedSetFunctionFactory(accessor, openAIWebhookEvent);
|
|
70
|
-
var configurer = _object_spread_props(_object_spread({}, accessor), {
|
|
71
|
-
handleBatchCancelled: fnWithKey('batch.cancelled'),
|
|
72
|
-
handleBatchCompleted: fnWithKey('batch.completed'),
|
|
73
|
-
handleBatchExpired: fnWithKey('batch.expired'),
|
|
74
|
-
handleBatchFailed: fnWithKey('batch.failed'),
|
|
75
|
-
handleEvalRunCanceled: fnWithKey('eval.run.canceled'),
|
|
76
|
-
handleEvalRunFailed: fnWithKey('eval.run.failed'),
|
|
77
|
-
handleEvalRunSucceeded: fnWithKey('eval.run.succeeded'),
|
|
78
|
-
handleFineTuningJobCancelled: fnWithKey('fine_tuning.job.cancelled'),
|
|
79
|
-
handleFineTuningJobFailed: fnWithKey('fine_tuning.job.failed'),
|
|
80
|
-
handleFineTuningJobSucceeded: fnWithKey('fine_tuning.job.succeeded'),
|
|
81
|
-
handleResponseCancelled: fnWithKey('response.cancelled'),
|
|
82
|
-
handleResponseCompleted: fnWithKey('response.completed'),
|
|
83
|
-
handleResponseFailed: fnWithKey('response.failed'),
|
|
84
|
-
handleResponseIncomplete: fnWithKey('response.incomplete')
|
|
85
|
-
});
|
|
86
|
-
return configurer;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
function _class_call_check$6(instance, Constructor) {
|
|
91
|
-
if (!(instance instanceof Constructor)) {
|
|
92
|
-
throw new TypeError("Cannot call a class as a function");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function _defineProperties$3(target, props) {
|
|
96
|
-
for(var i = 0; i < props.length; i++){
|
|
97
|
-
var descriptor = props[i];
|
|
98
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
99
|
-
descriptor.configurable = true;
|
|
100
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
101
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function _create_class$3(Constructor, protoProps, staticProps) {
|
|
105
|
-
if (staticProps) _defineProperties$3(Constructor, staticProps);
|
|
106
|
-
return Constructor;
|
|
107
|
-
}
|
|
108
|
-
function _define_property$4(obj, key, value) {
|
|
109
|
-
if (key in obj) {
|
|
110
|
-
Object.defineProperty(obj, key, {
|
|
111
|
-
value: value,
|
|
112
|
-
enumerable: true,
|
|
113
|
-
configurable: true,
|
|
114
|
-
writable: true
|
|
115
|
-
});
|
|
116
|
-
} else {
|
|
117
|
-
obj[key] = value;
|
|
118
|
-
}
|
|
119
|
-
return obj;
|
|
120
|
-
}
|
|
121
|
-
var OPENAI_WEBHOOK_SECRET_TOKEN_ENV_VAR = 'OPENAI_WEBHOOK_SECRET_TOKEN';
|
|
122
|
-
/**
|
|
123
|
-
* Configuration for OpenAIService
|
|
124
|
-
*/ var OpenAIWebhookServiceConfig = /*#__PURE__*/ function() {
|
|
125
|
-
function OpenAIWebhookServiceConfig() {
|
|
126
|
-
_class_call_check$6(this, OpenAIWebhookServiceConfig);
|
|
127
|
-
_define_property$4(this, "openaiWebhook", void 0);
|
|
128
|
-
}
|
|
129
|
-
_create_class$3(OpenAIWebhookServiceConfig, null, [
|
|
130
|
-
{
|
|
131
|
-
key: "assertValidConfig",
|
|
132
|
-
value: function assertValidConfig(config) {
|
|
133
|
-
if (!config.openaiWebhook.webhookSecret) {
|
|
134
|
-
throw new Error('No OpenAI webhook secret specified.');
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
]);
|
|
139
|
-
return OpenAIWebhookServiceConfig;
|
|
140
|
-
}
|
|
141
|
-
();
|
|
142
|
-
|
|
143
|
-
function _type_of(obj) {
|
|
144
|
-
"@swc/helpers - typeof";
|
|
145
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
146
|
-
}
|
|
147
|
-
function __decorate(decorators, target, key, desc) {
|
|
148
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
149
|
-
if ((typeof Reflect === "undefined" ? "undefined" : _type_of(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
150
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
151
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
152
|
-
}
|
|
153
|
-
function __param(paramIndex, decorator) {
|
|
154
|
-
return function(target, key) {
|
|
155
|
-
decorator(target, key, paramIndex);
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
159
|
-
var e = new Error(message);
|
|
160
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
function _class_call_check$5(instance, Constructor) {
|
|
164
|
-
if (!(instance instanceof Constructor)) {
|
|
165
|
-
throw new TypeError("Cannot call a class as a function");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function _defineProperties$2(target, props) {
|
|
169
|
-
for(var i = 0; i < props.length; i++){
|
|
170
|
-
var descriptor = props[i];
|
|
171
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
172
|
-
descriptor.configurable = true;
|
|
173
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
174
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
178
|
-
if (staticProps) _defineProperties$2(Constructor, staticProps);
|
|
179
|
-
return Constructor;
|
|
180
|
-
}
|
|
181
|
-
function _define_property$3(obj, key, value) {
|
|
182
|
-
if (key in obj) {
|
|
183
|
-
Object.defineProperty(obj, key, {
|
|
184
|
-
value: value,
|
|
185
|
-
enumerable: true,
|
|
186
|
-
configurable: true,
|
|
187
|
-
writable: true
|
|
188
|
-
});
|
|
189
|
-
} else {
|
|
190
|
-
obj[key] = value;
|
|
191
|
-
}
|
|
192
|
-
return obj;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Default environment variable for the OpenAI API key.
|
|
196
|
-
*/ var OPENAI_API_KEY_ENV_VAR = 'OPENAI_API_KEY';
|
|
197
|
-
var OPENAI_BASE_URL_ENV_VAR = 'OPENAI_BASE_URL';
|
|
198
|
-
var OPENAI_ORGANIZATION_ID_ENV_VAR = 'OPENAI_ORG_ID';
|
|
199
|
-
var OPENAI_PROJECT_ID_ENV_VAR = 'OPENAI_PROJECT_ID';
|
|
200
|
-
/**
|
|
201
|
-
* Configuration for OpenAIService
|
|
202
|
-
*/ var OpenAIServiceConfig = /*#__PURE__*/ function() {
|
|
203
|
-
function OpenAIServiceConfig() {
|
|
204
|
-
_class_call_check$5(this, OpenAIServiceConfig);
|
|
205
|
-
_define_property$3(this, "openai", void 0);
|
|
206
|
-
}
|
|
207
|
-
_create_class$2(OpenAIServiceConfig, null, [
|
|
208
|
-
{
|
|
209
|
-
key: "assertValidConfig",
|
|
210
|
-
value: function assertValidConfig(config) {
|
|
211
|
-
if (!config.openai.config.apiKey) {
|
|
212
|
-
throw new Error('No OpenAI API key specified.');
|
|
213
|
-
} else if (!config.openai.config.organization) {
|
|
214
|
-
throw new Error('No OpenAI organization specified.');
|
|
215
|
-
} else if (!config.openai.config.project) {
|
|
216
|
-
throw new Error('No OpenAI project specified.');
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
]);
|
|
221
|
-
return OpenAIServiceConfig;
|
|
222
|
-
}
|
|
223
|
-
();
|
|
224
|
-
|
|
225
|
-
function _class_call_check$4(instance, Constructor) {
|
|
226
|
-
if (!(instance instanceof Constructor)) {
|
|
227
|
-
throw new TypeError("Cannot call a class as a function");
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function _define_property$2(obj, key, value) {
|
|
231
|
-
if (key in obj) {
|
|
232
|
-
Object.defineProperty(obj, key, {
|
|
233
|
-
value: value,
|
|
234
|
-
enumerable: true,
|
|
235
|
-
configurable: true,
|
|
236
|
-
writable: true
|
|
237
|
-
});
|
|
238
|
-
} else {
|
|
239
|
-
obj[key] = value;
|
|
240
|
-
}
|
|
241
|
-
return obj;
|
|
242
|
-
}
|
|
243
|
-
exports.OpenAIApi = function OpenAIApi(config) {
|
|
244
|
-
_class_call_check$4(this, OpenAIApi);
|
|
245
|
-
_define_property$2(this, "config", void 0);
|
|
246
|
-
_define_property$2(this, "openAIClient", void 0);
|
|
247
|
-
this.config = config;
|
|
248
|
-
this.openAIClient = new openai.OpenAI(config.openai.config);
|
|
249
|
-
};
|
|
250
|
-
exports.OpenAIApi = __decorate([
|
|
251
|
-
common.Injectable(),
|
|
252
|
-
__param(0, common.Inject(OpenAIServiceConfig))
|
|
253
|
-
], exports.OpenAIApi);
|
|
254
|
-
|
|
255
|
-
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
256
|
-
try {
|
|
257
|
-
var info = gen[key](arg);
|
|
258
|
-
var value = info.value;
|
|
259
|
-
} catch (error) {
|
|
260
|
-
reject(error);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
if (info.done) {
|
|
264
|
-
resolve(value);
|
|
265
|
-
} else {
|
|
266
|
-
Promise.resolve(value).then(_next, _throw);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
function _async_to_generator$2(fn) {
|
|
270
|
-
return function() {
|
|
271
|
-
var self = this, args = arguments;
|
|
272
|
-
return new Promise(function(resolve, reject) {
|
|
273
|
-
var gen = fn.apply(self, args);
|
|
274
|
-
function _next(value) {
|
|
275
|
-
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
276
|
-
}
|
|
277
|
-
function _throw(err) {
|
|
278
|
-
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
279
|
-
}
|
|
280
|
-
_next(undefined);
|
|
281
|
-
});
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
function _instanceof(left, right) {
|
|
285
|
-
"@swc/helpers - instanceof";
|
|
286
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
287
|
-
return !!right[Symbol.hasInstance](left);
|
|
288
|
-
} else {
|
|
289
|
-
return left instanceof right;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
function _ts_generator$2(thisArg, body) {
|
|
293
|
-
var f, y, t, _ = {
|
|
294
|
-
label: 0,
|
|
295
|
-
sent: function() {
|
|
296
|
-
if (t[0] & 1) throw t[1];
|
|
297
|
-
return t[1];
|
|
298
|
-
},
|
|
299
|
-
trys: [],
|
|
300
|
-
ops: []
|
|
301
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
302
|
-
return d(g, "next", {
|
|
303
|
-
value: verb(0)
|
|
304
|
-
}), d(g, "throw", {
|
|
305
|
-
value: verb(1)
|
|
306
|
-
}), d(g, "return", {
|
|
307
|
-
value: verb(2)
|
|
308
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
309
|
-
value: function() {
|
|
310
|
-
return this;
|
|
311
|
-
}
|
|
312
|
-
}), g;
|
|
313
|
-
function verb(n) {
|
|
314
|
-
return function(v) {
|
|
315
|
-
return step([
|
|
316
|
-
n,
|
|
317
|
-
v
|
|
318
|
-
]);
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
function step(op) {
|
|
322
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
323
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
324
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
325
|
-
if (y = 0, t) op = [
|
|
326
|
-
op[0] & 2,
|
|
327
|
-
t.value
|
|
328
|
-
];
|
|
329
|
-
switch(op[0]){
|
|
330
|
-
case 0:
|
|
331
|
-
case 1:
|
|
332
|
-
t = op;
|
|
333
|
-
break;
|
|
334
|
-
case 4:
|
|
335
|
-
_.label++;
|
|
336
|
-
return {
|
|
337
|
-
value: op[1],
|
|
338
|
-
done: false
|
|
339
|
-
};
|
|
340
|
-
case 5:
|
|
341
|
-
_.label++;
|
|
342
|
-
y = op[1];
|
|
343
|
-
op = [
|
|
344
|
-
0
|
|
345
|
-
];
|
|
346
|
-
continue;
|
|
347
|
-
case 7:
|
|
348
|
-
op = _.ops.pop();
|
|
349
|
-
_.trys.pop();
|
|
350
|
-
continue;
|
|
351
|
-
default:
|
|
352
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
353
|
-
_ = 0;
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
357
|
-
_.label = op[1];
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
361
|
-
_.label = t[1];
|
|
362
|
-
t = op;
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
if (t && _.label < t[2]) {
|
|
366
|
-
_.label = t[2];
|
|
367
|
-
_.ops.push(op);
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
if (t[2]) _.ops.pop();
|
|
371
|
-
_.trys.pop();
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
op = body.call(thisArg, _);
|
|
375
|
-
} catch (e) {
|
|
376
|
-
op = [
|
|
377
|
-
6,
|
|
378
|
-
e
|
|
379
|
-
];
|
|
380
|
-
y = 0;
|
|
381
|
-
} finally{
|
|
382
|
-
f = t = 0;
|
|
383
|
-
}
|
|
384
|
-
if (op[0] & 5) throw op[1];
|
|
385
|
-
return {
|
|
386
|
-
value: op[0] ? op[1] : void 0,
|
|
387
|
-
done: true
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Verifies an OpenAI webhook event header using the OpenAI client's built-in signature verification.
|
|
393
|
-
*
|
|
394
|
-
* @param config - Verification config containing the OpenAI webhook secret and client.
|
|
395
|
-
* @returns Verifier function that validates the webhook signature on each request.
|
|
396
|
-
*/ function openAIWebhookEventVerifier(config) {
|
|
397
|
-
var secret = config.secret, client = config.client;
|
|
398
|
-
return function(request, _rawBody) {
|
|
399
|
-
return _async_to_generator$2(function() {
|
|
400
|
-
var headers, requestBodyString, event, valid, e, result;
|
|
401
|
-
return _ts_generator$2(this, function(_state) {
|
|
402
|
-
switch(_state.label){
|
|
403
|
-
case 0:
|
|
404
|
-
headers = request.headers;
|
|
405
|
-
requestBodyString = String(request.body);
|
|
406
|
-
valid = false;
|
|
407
|
-
_state.label = 1;
|
|
408
|
-
case 1:
|
|
409
|
-
_state.trys.push([
|
|
410
|
-
1,
|
|
411
|
-
3,
|
|
412
|
-
,
|
|
413
|
-
4
|
|
414
|
-
]);
|
|
415
|
-
return [
|
|
416
|
-
4,
|
|
417
|
-
client.webhooks.unwrap(requestBodyString, headers, secret)
|
|
418
|
-
];
|
|
419
|
-
case 2:
|
|
420
|
-
event = _state.sent();
|
|
421
|
-
valid = true;
|
|
422
|
-
return [
|
|
423
|
-
3,
|
|
424
|
-
4
|
|
425
|
-
];
|
|
426
|
-
case 3:
|
|
427
|
-
e = _state.sent();
|
|
428
|
-
if (_instanceof(e, openai.InvalidWebhookSignatureError)) {
|
|
429
|
-
valid = false;
|
|
430
|
-
} else {
|
|
431
|
-
throw e;
|
|
432
|
-
}
|
|
433
|
-
return [
|
|
434
|
-
3,
|
|
435
|
-
4
|
|
436
|
-
];
|
|
437
|
-
case 4:
|
|
438
|
-
result = {
|
|
439
|
-
valid: valid,
|
|
440
|
-
event: event
|
|
441
|
-
};
|
|
442
|
-
return [
|
|
443
|
-
2,
|
|
444
|
-
result
|
|
445
|
-
];
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
})();
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
453
|
-
try {
|
|
454
|
-
var info = gen[key](arg);
|
|
455
|
-
var value = info.value;
|
|
456
|
-
} catch (error) {
|
|
457
|
-
reject(error);
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
if (info.done) {
|
|
461
|
-
resolve(value);
|
|
462
|
-
} else {
|
|
463
|
-
Promise.resolve(value).then(_next, _throw);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
function _async_to_generator$1(fn) {
|
|
467
|
-
return function() {
|
|
468
|
-
var self = this, args = arguments;
|
|
469
|
-
return new Promise(function(resolve, reject) {
|
|
470
|
-
var gen = fn.apply(self, args);
|
|
471
|
-
function _next(value) {
|
|
472
|
-
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
473
|
-
}
|
|
474
|
-
function _throw(err) {
|
|
475
|
-
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
476
|
-
}
|
|
477
|
-
_next(undefined);
|
|
478
|
-
});
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
function _class_call_check$3(instance, Constructor) {
|
|
482
|
-
if (!(instance instanceof Constructor)) {
|
|
483
|
-
throw new TypeError("Cannot call a class as a function");
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
function _defineProperties$1(target, props) {
|
|
487
|
-
for(var i = 0; i < props.length; i++){
|
|
488
|
-
var descriptor = props[i];
|
|
489
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
490
|
-
descriptor.configurable = true;
|
|
491
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
492
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
496
|
-
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
497
|
-
return Constructor;
|
|
498
|
-
}
|
|
499
|
-
function _define_property$1(obj, key, value) {
|
|
500
|
-
if (key in obj) {
|
|
501
|
-
Object.defineProperty(obj, key, {
|
|
502
|
-
value: value,
|
|
503
|
-
enumerable: true,
|
|
504
|
-
configurable: true,
|
|
505
|
-
writable: true
|
|
506
|
-
});
|
|
507
|
-
} else {
|
|
508
|
-
obj[key] = value;
|
|
509
|
-
}
|
|
510
|
-
return obj;
|
|
511
|
-
}
|
|
512
|
-
function _ts_generator$1(thisArg, body) {
|
|
513
|
-
var f, y, t, _ = {
|
|
514
|
-
label: 0,
|
|
515
|
-
sent: function() {
|
|
516
|
-
if (t[0] & 1) throw t[1];
|
|
517
|
-
return t[1];
|
|
518
|
-
},
|
|
519
|
-
trys: [],
|
|
520
|
-
ops: []
|
|
521
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
522
|
-
return d(g, "next", {
|
|
523
|
-
value: verb(0)
|
|
524
|
-
}), d(g, "throw", {
|
|
525
|
-
value: verb(1)
|
|
526
|
-
}), d(g, "return", {
|
|
527
|
-
value: verb(2)
|
|
528
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
529
|
-
value: function() {
|
|
530
|
-
return this;
|
|
531
|
-
}
|
|
532
|
-
}), g;
|
|
533
|
-
function verb(n) {
|
|
534
|
-
return function(v) {
|
|
535
|
-
return step([
|
|
536
|
-
n,
|
|
537
|
-
v
|
|
538
|
-
]);
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
function step(op) {
|
|
542
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
543
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
544
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
545
|
-
if (y = 0, t) op = [
|
|
546
|
-
op[0] & 2,
|
|
547
|
-
t.value
|
|
548
|
-
];
|
|
549
|
-
switch(op[0]){
|
|
550
|
-
case 0:
|
|
551
|
-
case 1:
|
|
552
|
-
t = op;
|
|
553
|
-
break;
|
|
554
|
-
case 4:
|
|
555
|
-
_.label++;
|
|
556
|
-
return {
|
|
557
|
-
value: op[1],
|
|
558
|
-
done: false
|
|
559
|
-
};
|
|
560
|
-
case 5:
|
|
561
|
-
_.label++;
|
|
562
|
-
y = op[1];
|
|
563
|
-
op = [
|
|
564
|
-
0
|
|
565
|
-
];
|
|
566
|
-
continue;
|
|
567
|
-
case 7:
|
|
568
|
-
op = _.ops.pop();
|
|
569
|
-
_.trys.pop();
|
|
570
|
-
continue;
|
|
571
|
-
default:
|
|
572
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
573
|
-
_ = 0;
|
|
574
|
-
continue;
|
|
575
|
-
}
|
|
576
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
577
|
-
_.label = op[1];
|
|
578
|
-
break;
|
|
579
|
-
}
|
|
580
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
581
|
-
_.label = t[1];
|
|
582
|
-
t = op;
|
|
583
|
-
break;
|
|
584
|
-
}
|
|
585
|
-
if (t && _.label < t[2]) {
|
|
586
|
-
_.label = t[2];
|
|
587
|
-
_.ops.push(op);
|
|
588
|
-
break;
|
|
589
|
-
}
|
|
590
|
-
if (t[2]) _.ops.pop();
|
|
591
|
-
_.trys.pop();
|
|
592
|
-
continue;
|
|
593
|
-
}
|
|
594
|
-
op = body.call(thisArg, _);
|
|
595
|
-
} catch (e) {
|
|
596
|
-
op = [
|
|
597
|
-
6,
|
|
598
|
-
e
|
|
599
|
-
];
|
|
600
|
-
y = 0;
|
|
601
|
-
} finally{
|
|
602
|
-
f = t = 0;
|
|
603
|
-
}
|
|
604
|
-
if (op[0] & 5) throw op[1];
|
|
605
|
-
return {
|
|
606
|
-
value: op[0] ? op[1] : void 0,
|
|
607
|
-
done: true
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* Service that makes system changes based on OpenAI webhook events.
|
|
613
|
-
*/ exports.OpenAIWebhookService = /*#__PURE__*/ function() {
|
|
614
|
-
function OpenAIWebhookService(openAiApi, openAIWebhookServiceConfig) {
|
|
615
|
-
_class_call_check$3(this, OpenAIWebhookService);
|
|
616
|
-
_define_property$1(this, "logger", new common.Logger('OpenAIWebhookService'));
|
|
617
|
-
_define_property$1(this, "_verifier", void 0);
|
|
618
|
-
_define_property$1(this, "handler", openaiEventHandlerFactory());
|
|
619
|
-
_define_property$1(this, "configure", openaiEventHandlerConfigurerFactory(this.handler));
|
|
620
|
-
var webhookSecret = openAIWebhookServiceConfig.openaiWebhook.webhookSecret;
|
|
621
|
-
this._verifier = openAIWebhookEventVerifier({
|
|
622
|
-
secret: webhookSecret,
|
|
623
|
-
client: openAiApi.openAIClient
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
_create_class$1(OpenAIWebhookService, [
|
|
627
|
-
{
|
|
628
|
-
key: "updateForWebhook",
|
|
629
|
-
value: function updateForWebhook(req, rawBody) {
|
|
630
|
-
return _async_to_generator$1(function() {
|
|
631
|
-
var result;
|
|
632
|
-
return _ts_generator$1(this, function(_state) {
|
|
633
|
-
switch(_state.label){
|
|
634
|
-
case 0:
|
|
635
|
-
return [
|
|
636
|
-
4,
|
|
637
|
-
this._verifier(req, rawBody)
|
|
638
|
-
];
|
|
639
|
-
case 1:
|
|
640
|
-
result = _state.sent();
|
|
641
|
-
if (!result.valid) return [
|
|
642
|
-
3,
|
|
643
|
-
3
|
|
644
|
-
];
|
|
645
|
-
return [
|
|
646
|
-
4,
|
|
647
|
-
this.updateForOpenAIEvent(result.event)
|
|
648
|
-
];
|
|
649
|
-
case 2:
|
|
650
|
-
_state.sent();
|
|
651
|
-
return [
|
|
652
|
-
3,
|
|
653
|
-
4
|
|
654
|
-
];
|
|
655
|
-
case 3:
|
|
656
|
-
this.logger.warn('Received invalid OpenAI event.', req);
|
|
657
|
-
_state.label = 4;
|
|
658
|
-
case 4:
|
|
659
|
-
return [
|
|
660
|
-
2
|
|
661
|
-
];
|
|
662
|
-
}
|
|
663
|
-
});
|
|
664
|
-
}).call(this);
|
|
665
|
-
}
|
|
666
|
-
},
|
|
667
|
-
{
|
|
668
|
-
key: "updateForOpenAIEvent",
|
|
669
|
-
value: function updateForOpenAIEvent(event) {
|
|
670
|
-
return _async_to_generator$1(function() {
|
|
671
|
-
var result;
|
|
672
|
-
return _ts_generator$1(this, function(_state) {
|
|
673
|
-
switch(_state.label){
|
|
674
|
-
case 0:
|
|
675
|
-
return [
|
|
676
|
-
4,
|
|
677
|
-
this.handler(event)
|
|
678
|
-
];
|
|
679
|
-
case 1:
|
|
680
|
-
result = _state.sent();
|
|
681
|
-
if (!result) {
|
|
682
|
-
this.logger.warn('Received unexpected/unhandled OpenAI event.', event);
|
|
683
|
-
}
|
|
684
|
-
return [
|
|
685
|
-
2
|
|
686
|
-
];
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
}).call(this);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
]);
|
|
693
|
-
return OpenAIWebhookService;
|
|
694
|
-
}();
|
|
695
|
-
exports.OpenAIWebhookService = __decorate([
|
|
696
|
-
common.Injectable(),
|
|
697
|
-
__param(0, common.Inject(exports.OpenAIApi)),
|
|
698
|
-
__param(1, common.Inject(OpenAIWebhookServiceConfig))
|
|
699
|
-
], exports.OpenAIWebhookService);
|
|
700
|
-
|
|
701
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
702
|
-
try {
|
|
703
|
-
var info = gen[key](arg);
|
|
704
|
-
var value = info.value;
|
|
705
|
-
} catch (error) {
|
|
706
|
-
reject(error);
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
if (info.done) {
|
|
710
|
-
resolve(value);
|
|
711
|
-
} else {
|
|
712
|
-
Promise.resolve(value).then(_next, _throw);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
function _async_to_generator(fn) {
|
|
716
|
-
return function() {
|
|
717
|
-
var self = this, args = arguments;
|
|
718
|
-
return new Promise(function(resolve, reject) {
|
|
719
|
-
var gen = fn.apply(self, args);
|
|
720
|
-
function _next(value) {
|
|
721
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
722
|
-
}
|
|
723
|
-
function _throw(err) {
|
|
724
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
725
|
-
}
|
|
726
|
-
_next(undefined);
|
|
727
|
-
});
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
function _class_call_check$2(instance, Constructor) {
|
|
731
|
-
if (!(instance instanceof Constructor)) {
|
|
732
|
-
throw new TypeError("Cannot call a class as a function");
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
function _defineProperties(target, props) {
|
|
736
|
-
for(var i = 0; i < props.length; i++){
|
|
737
|
-
var descriptor = props[i];
|
|
738
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
739
|
-
descriptor.configurable = true;
|
|
740
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
741
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
745
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
746
|
-
return Constructor;
|
|
747
|
-
}
|
|
748
|
-
function _define_property(obj, key, value) {
|
|
749
|
-
if (key in obj) {
|
|
750
|
-
Object.defineProperty(obj, key, {
|
|
751
|
-
value: value,
|
|
752
|
-
enumerable: true,
|
|
753
|
-
configurable: true,
|
|
754
|
-
writable: true
|
|
755
|
-
});
|
|
756
|
-
} else {
|
|
757
|
-
obj[key] = value;
|
|
758
|
-
}
|
|
759
|
-
return obj;
|
|
760
|
-
}
|
|
761
|
-
function _ts_generator(thisArg, body) {
|
|
762
|
-
var f, y, t, _ = {
|
|
763
|
-
label: 0,
|
|
764
|
-
sent: function() {
|
|
765
|
-
if (t[0] & 1) throw t[1];
|
|
766
|
-
return t[1];
|
|
767
|
-
},
|
|
768
|
-
trys: [],
|
|
769
|
-
ops: []
|
|
770
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
771
|
-
return d(g, "next", {
|
|
772
|
-
value: verb(0)
|
|
773
|
-
}), d(g, "throw", {
|
|
774
|
-
value: verb(1)
|
|
775
|
-
}), d(g, "return", {
|
|
776
|
-
value: verb(2)
|
|
777
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
778
|
-
value: function() {
|
|
779
|
-
return this;
|
|
780
|
-
}
|
|
781
|
-
}), g;
|
|
782
|
-
function verb(n) {
|
|
783
|
-
return function(v) {
|
|
784
|
-
return step([
|
|
785
|
-
n,
|
|
786
|
-
v
|
|
787
|
-
]);
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
function step(op) {
|
|
791
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
792
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
793
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
794
|
-
if (y = 0, t) op = [
|
|
795
|
-
op[0] & 2,
|
|
796
|
-
t.value
|
|
797
|
-
];
|
|
798
|
-
switch(op[0]){
|
|
799
|
-
case 0:
|
|
800
|
-
case 1:
|
|
801
|
-
t = op;
|
|
802
|
-
break;
|
|
803
|
-
case 4:
|
|
804
|
-
_.label++;
|
|
805
|
-
return {
|
|
806
|
-
value: op[1],
|
|
807
|
-
done: false
|
|
808
|
-
};
|
|
809
|
-
case 5:
|
|
810
|
-
_.label++;
|
|
811
|
-
y = op[1];
|
|
812
|
-
op = [
|
|
813
|
-
0
|
|
814
|
-
];
|
|
815
|
-
continue;
|
|
816
|
-
case 7:
|
|
817
|
-
op = _.ops.pop();
|
|
818
|
-
_.trys.pop();
|
|
819
|
-
continue;
|
|
820
|
-
default:
|
|
821
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
822
|
-
_ = 0;
|
|
823
|
-
continue;
|
|
824
|
-
}
|
|
825
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
826
|
-
_.label = op[1];
|
|
827
|
-
break;
|
|
828
|
-
}
|
|
829
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
830
|
-
_.label = t[1];
|
|
831
|
-
t = op;
|
|
832
|
-
break;
|
|
833
|
-
}
|
|
834
|
-
if (t && _.label < t[2]) {
|
|
835
|
-
_.label = t[2];
|
|
836
|
-
_.ops.push(op);
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
if (t[2]) _.ops.pop();
|
|
840
|
-
_.trys.pop();
|
|
841
|
-
continue;
|
|
842
|
-
}
|
|
843
|
-
op = body.call(thisArg, _);
|
|
844
|
-
} catch (e) {
|
|
845
|
-
op = [
|
|
846
|
-
6,
|
|
847
|
-
e
|
|
848
|
-
];
|
|
849
|
-
y = 0;
|
|
850
|
-
} finally{
|
|
851
|
-
f = t = 0;
|
|
852
|
-
}
|
|
853
|
-
if (op[0] & 5) throw op[1];
|
|
854
|
-
return {
|
|
855
|
-
value: op[0] ? op[1] : void 0,
|
|
856
|
-
done: true
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
exports.OpenAIWebhookController = /*#__PURE__*/ function() {
|
|
861
|
-
function OpenAIWebhookController(openaiWebhookService) {
|
|
862
|
-
_class_call_check$2(this, OpenAIWebhookController);
|
|
863
|
-
_define_property(this, "_openaiWebhookService", void 0);
|
|
864
|
-
this._openaiWebhookService = openaiWebhookService;
|
|
865
|
-
}
|
|
866
|
-
_create_class(OpenAIWebhookController, [
|
|
867
|
-
{
|
|
868
|
-
key: "handleOpenAIWebhook",
|
|
869
|
-
value: function handleOpenAIWebhook(req, rawBody) {
|
|
870
|
-
return _async_to_generator(function() {
|
|
871
|
-
return _ts_generator(this, function(_state) {
|
|
872
|
-
switch(_state.label){
|
|
873
|
-
case 0:
|
|
874
|
-
return [
|
|
875
|
-
4,
|
|
876
|
-
this._openaiWebhookService.updateForWebhook(req, rawBody)
|
|
877
|
-
];
|
|
878
|
-
case 1:
|
|
879
|
-
_state.sent();
|
|
880
|
-
return [
|
|
881
|
-
2
|
|
882
|
-
];
|
|
883
|
-
}
|
|
884
|
-
});
|
|
885
|
-
}).call(this);
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
]);
|
|
889
|
-
return OpenAIWebhookController;
|
|
890
|
-
}();
|
|
891
|
-
__decorate([
|
|
892
|
-
common.Post(),
|
|
893
|
-
__param(0, common.Req()),
|
|
894
|
-
__param(1, nestjs.RawBody())
|
|
895
|
-
], exports.OpenAIWebhookController.prototype, "handleOpenAIWebhook", null);
|
|
896
|
-
exports.OpenAIWebhookController = __decorate([
|
|
897
|
-
common.Controller('/webhook/openai'),
|
|
898
|
-
__param(0, common.Inject(exports.OpenAIWebhookService))
|
|
899
|
-
], exports.OpenAIWebhookController);
|
|
900
|
-
|
|
901
|
-
function _class_call_check$1(instance, Constructor) {
|
|
902
|
-
if (!(instance instanceof Constructor)) {
|
|
903
|
-
throw new TypeError("Cannot call a class as a function");
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Factory that creates an OpenAIServiceConfig from environment variables.
|
|
908
|
-
*
|
|
909
|
-
* Reads the API key, base URL, organization ID, and project ID from environment variables.
|
|
910
|
-
*
|
|
911
|
-
* @param configService - NestJS config service for reading environment variables.
|
|
912
|
-
* @returns A validated OpenAIServiceConfig.
|
|
913
|
-
*/ function openAIServiceConfigFactory(configService) {
|
|
914
|
-
var _configService_get;
|
|
915
|
-
var config = {
|
|
916
|
-
openai: {
|
|
917
|
-
config: {
|
|
918
|
-
apiKey: configService.get(OPENAI_API_KEY_ENV_VAR),
|
|
919
|
-
baseURL: (_configService_get = configService.get(OPENAI_BASE_URL_ENV_VAR)) !== null && _configService_get !== void 0 ? _configService_get : undefined,
|
|
920
|
-
organization: configService.get(OPENAI_ORGANIZATION_ID_ENV_VAR),
|
|
921
|
-
project: configService.get(OPENAI_PROJECT_ID_ENV_VAR)
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
};
|
|
925
|
-
OpenAIServiceConfig.assertValidConfig(config);
|
|
926
|
-
return config;
|
|
927
|
-
}
|
|
928
|
-
/**
|
|
929
|
-
* NestJS module that provides the OpenAIApi service.
|
|
930
|
-
*
|
|
931
|
-
* Reads the OpenAI API key, organization ID, and project ID from environment variables.
|
|
932
|
-
*/ exports.OpenAIModule = function OpenAIModule() {
|
|
933
|
-
_class_call_check$1(this, OpenAIModule);
|
|
934
|
-
};
|
|
935
|
-
exports.OpenAIModule = __decorate([
|
|
936
|
-
common.Module({
|
|
937
|
-
imports: [
|
|
938
|
-
config.ConfigModule
|
|
939
|
-
],
|
|
940
|
-
providers: [
|
|
941
|
-
{
|
|
942
|
-
provide: OpenAIServiceConfig,
|
|
943
|
-
inject: [
|
|
944
|
-
config.ConfigService
|
|
945
|
-
],
|
|
946
|
-
useFactory: openAIServiceConfigFactory
|
|
947
|
-
},
|
|
948
|
-
exports.OpenAIApi
|
|
949
|
-
],
|
|
950
|
-
exports: [
|
|
951
|
-
exports.OpenAIApi
|
|
952
|
-
]
|
|
953
|
-
})
|
|
954
|
-
], exports.OpenAIModule);
|
|
955
|
-
|
|
956
|
-
function _class_call_check(instance, Constructor) {
|
|
957
|
-
if (!(instance instanceof Constructor)) {
|
|
958
|
-
throw new TypeError("Cannot call a class as a function");
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* Factory that creates an OpenAIWebhookServiceConfig from environment variables.
|
|
963
|
-
*
|
|
964
|
-
* Reads the OpenAI webhook secret token from environment variables.
|
|
965
|
-
*
|
|
966
|
-
* @param configService - NestJS config service for reading environment variables.
|
|
967
|
-
* @returns A validated OpenAIWebhookServiceConfig.
|
|
968
|
-
*/ function openAIWebhookServiceConfigFactory(configService) {
|
|
969
|
-
var config = {
|
|
970
|
-
openaiWebhook: {
|
|
971
|
-
webhookSecret: configService.get(OPENAI_WEBHOOK_SECRET_TOKEN_ENV_VAR)
|
|
972
|
-
}
|
|
973
|
-
};
|
|
974
|
-
OpenAIWebhookServiceConfig.assertValidConfig(config);
|
|
975
|
-
return config;
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* NestJS module that handles incoming OpenAI webhook events.
|
|
979
|
-
*
|
|
980
|
-
* Provides the OpenAIWebhookService and controller for verifying and processing webhook payloads.
|
|
981
|
-
*/ exports.OpenAIWebhookModule = function OpenAIWebhookModule() {
|
|
982
|
-
_class_call_check(this, OpenAIWebhookModule);
|
|
983
|
-
};
|
|
984
|
-
exports.OpenAIWebhookModule = __decorate([
|
|
985
|
-
common.Module({
|
|
986
|
-
imports: [
|
|
987
|
-
config.ConfigModule,
|
|
988
|
-
exports.OpenAIModule
|
|
989
|
-
],
|
|
990
|
-
controllers: [
|
|
991
|
-
exports.OpenAIWebhookController
|
|
992
|
-
],
|
|
993
|
-
providers: [
|
|
994
|
-
{
|
|
995
|
-
provide: OpenAIWebhookServiceConfig,
|
|
996
|
-
inject: [
|
|
997
|
-
config.ConfigService
|
|
998
|
-
],
|
|
999
|
-
useFactory: openAIWebhookServiceConfigFactory
|
|
1000
|
-
},
|
|
1001
|
-
exports.OpenAIWebhookService
|
|
1002
|
-
],
|
|
1003
|
-
exports: [
|
|
1004
|
-
exports.OpenAIWebhookService
|
|
1005
|
-
]
|
|
1006
|
-
})
|
|
1007
|
-
], exports.OpenAIWebhookModule);
|
|
1008
|
-
|
|
1009
|
-
/**
|
|
1010
|
-
* Returns true if the response has a json response.
|
|
1011
|
-
*
|
|
1012
|
-
* @param response
|
|
1013
|
-
* @returns
|
|
1014
|
-
*/ function isParsedOpenAIJsonResponseWithJson(response) {
|
|
1015
|
-
return response.isJsonResponse && Boolean(response.jsonResponse) && Boolean(response.jsonResponseFieldMap);
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* Parses the OpenAI response into a ParsedOpenAIJsonResponse.
|
|
1019
|
-
*
|
|
1020
|
-
* @param response - The OpenAI response to parse.
|
|
1021
|
-
* @returns The parsed OpenAI response.
|
|
1022
|
-
*/ function parseOpenAIJsonResponse(response) {
|
|
1023
|
-
var output_text = typeof response === 'string' ? response : response.output_text;
|
|
1024
|
-
var jsonResponse = undefined;
|
|
1025
|
-
var jsonResponseFieldMap = undefined;
|
|
1026
|
-
try {
|
|
1027
|
-
jsonResponse = JSON.parse(output_text);
|
|
1028
|
-
jsonResponseFieldMap = openAIJsonResponseFieldsMap(jsonResponse);
|
|
1029
|
-
} catch (unused) {
|
|
1030
|
-
// ignore
|
|
1031
|
-
}
|
|
1032
|
-
return {
|
|
1033
|
-
output_text: output_text,
|
|
1034
|
-
isJsonResponse: Boolean(jsonResponse),
|
|
1035
|
-
jsonResponse: jsonResponse,
|
|
1036
|
-
jsonResponseFieldMap: jsonResponseFieldMap
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
/**
|
|
1040
|
-
* Creates a map of the OpenAI json response fields.
|
|
1041
|
-
*
|
|
1042
|
-
* @param response - OpenAI json response to index.
|
|
1043
|
-
* @returns Map keyed by field name for direct lookup.
|
|
1044
|
-
*/ function openAIJsonResponseFieldsMap(response) {
|
|
1045
|
-
return new Map(response.fields.map(function(x) {
|
|
1046
|
-
return [
|
|
1047
|
-
x.field_name,
|
|
1048
|
-
x.field_value
|
|
1049
|
-
];
|
|
1050
|
-
}));
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
exports.OPENAI_API_KEY_ENV_VAR = OPENAI_API_KEY_ENV_VAR;
|
|
1054
|
-
exports.OPENAI_BASE_URL_ENV_VAR = OPENAI_BASE_URL_ENV_VAR;
|
|
1055
|
-
exports.OPENAI_ORGANIZATION_ID_ENV_VAR = OPENAI_ORGANIZATION_ID_ENV_VAR;
|
|
1056
|
-
exports.OPENAI_PROJECT_ID_ENV_VAR = OPENAI_PROJECT_ID_ENV_VAR;
|
|
1057
|
-
exports.OPENAI_WEBHOOK_SECRET_TOKEN_ENV_VAR = OPENAI_WEBHOOK_SECRET_TOKEN_ENV_VAR;
|
|
1058
|
-
exports.OpenAIServiceConfig = OpenAIServiceConfig;
|
|
1059
|
-
exports.OpenAIWebhookServiceConfig = OpenAIWebhookServiceConfig;
|
|
1060
|
-
exports.isParsedOpenAIJsonResponseWithJson = isParsedOpenAIJsonResponseWithJson;
|
|
1061
|
-
exports.openAIJsonResponseFieldsMap = openAIJsonResponseFieldsMap;
|
|
1062
|
-
exports.openAIServiceConfigFactory = openAIServiceConfigFactory;
|
|
1063
|
-
exports.openAIWebhookEvent = openAIWebhookEvent;
|
|
1064
|
-
exports.openAIWebhookEventVerifier = openAIWebhookEventVerifier;
|
|
1065
|
-
exports.openAIWebhookServiceConfigFactory = openAIWebhookServiceConfigFactory;
|
|
1066
|
-
exports.openaiEventHandlerConfigurerFactory = openaiEventHandlerConfigurerFactory;
|
|
1067
|
-
exports.openaiEventHandlerFactory = openaiEventHandlerFactory;
|
|
1068
|
-
exports.parseOpenAIJsonResponse = parseOpenAIJsonResponse;
|