@dereekb/nestjs 13.0.0 → 13.0.1
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/index.cjs.default.js +1 -0
- package/index.cjs.js +136 -118
- package/index.cjs.mjs +2 -0
- package/index.esm.js +136 -118
- package/mailgun/index.cjs.default.js +1 -0
- package/mailgun/index.cjs.js +496 -503
- package/mailgun/index.cjs.mjs +2 -0
- package/mailgun/index.esm.js +496 -503
- package/mailgun/package.json +19 -20
- package/openai/index.cjs.default.js +1 -0
- package/openai/index.cjs.js +194 -161
- package/openai/index.cjs.mjs +2 -0
- package/openai/index.esm.js +194 -161
- package/openai/package.json +19 -20
- package/package.json +32 -55
- package/stripe/index.cjs.default.js +1 -0
- package/stripe/index.cjs.js +158 -128
- package/stripe/index.cjs.mjs +2 -0
- package/stripe/index.esm.js +158 -128
- package/stripe/package.json +19 -20
- package/typeform/index.cjs.default.js +1 -0
- package/typeform/index.cjs.js +257 -240
- package/typeform/index.cjs.mjs +2 -0
- package/typeform/index.esm.js +257 -240
- package/typeform/package.json +19 -20
- package/vapiai/index.cjs.default.js +1 -0
- package/vapiai/index.cjs.js +203 -190
- package/vapiai/index.cjs.mjs +2 -0
- package/vapiai/index.esm.js +203 -190
- package/vapiai/package.json +19 -20
package/mailgun/package.json
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/nestjs/mailgun",
|
|
3
|
-
"version": "13.0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"version": "13.0.1",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@dereekb/date": "13.0.1",
|
|
6
|
+
"@dereekb/model": "13.0.1",
|
|
7
|
+
"@dereekb/nestjs": "13.0.1",
|
|
8
|
+
"@dereekb/rxjs": "13.0.1",
|
|
9
|
+
"@dereekb/util": "13.0.1",
|
|
10
|
+
"@nestjs/common": "^11.0.0",
|
|
11
|
+
"@nestjs/config": "^4.0.0",
|
|
12
|
+
"form-data": "^4.0.0",
|
|
13
|
+
"mailgun.js": "^12.0.0"
|
|
14
|
+
},
|
|
7
15
|
"exports": {
|
|
16
|
+
"./package.json": "./package.json",
|
|
8
17
|
".": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
"browser": {
|
|
14
|
-
"require": "./index.cjs.js",
|
|
15
|
-
"import": "./index.esm.js"
|
|
16
|
-
},
|
|
18
|
+
"module": "./index.esm.js",
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"import": "./index.cjs.mjs",
|
|
17
21
|
"default": "./index.cjs.js"
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"@dereekb/model": "13.0.0",
|
|
24
|
-
"@dereekb/rxjs": "13.0.0",
|
|
25
|
-
"@dereekb/util": "13.0.0",
|
|
26
|
-
"core-js": "^3.0.0"
|
|
27
|
-
}
|
|
24
|
+
"module": "./index.esm.js",
|
|
25
|
+
"main": "./index.cjs.js",
|
|
26
|
+
"types": "./index.d.ts"
|
|
28
27
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./index.cjs.js').default;
|
package/openai/index.cjs.js
CHANGED
|
@@ -13,32 +13,32 @@ var config = require('@nestjs/config');
|
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
15
|
function openAIWebhookEvent(event) {
|
|
16
|
-
|
|
16
|
+
return event;
|
|
17
17
|
}
|
|
18
|
-
const openaiEventHandlerFactory = util.handlerFactory(x => x.type);
|
|
18
|
+
const openaiEventHandlerFactory = util.handlerFactory((x) => x.type);
|
|
19
19
|
const openaiEventHandlerConfigurerFactory = util.handlerConfigurerFactory({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
20
|
+
configurerForAccessor: (accessor) => {
|
|
21
|
+
// eslint-disable-next-line
|
|
22
|
+
const fnWithKey = util.handlerMappedSetFunctionFactory(accessor, openAIWebhookEvent);
|
|
23
|
+
const configurer = {
|
|
24
|
+
...accessor,
|
|
25
|
+
handleBatchCancelled: fnWithKey('batch.cancelled'),
|
|
26
|
+
handleBatchCompleted: fnWithKey('batch.completed'),
|
|
27
|
+
handleBatchExpired: fnWithKey('batch.expired'),
|
|
28
|
+
handleBatchFailed: fnWithKey('batch.failed'),
|
|
29
|
+
handleEvalRunCanceled: fnWithKey('eval.run.canceled'),
|
|
30
|
+
handleEvalRunFailed: fnWithKey('eval.run.failed'),
|
|
31
|
+
handleEvalRunSucceeded: fnWithKey('eval.run.succeeded'),
|
|
32
|
+
handleFineTuningJobCancelled: fnWithKey('fine_tuning.job.cancelled'),
|
|
33
|
+
handleFineTuningJobFailed: fnWithKey('fine_tuning.job.failed'),
|
|
34
|
+
handleFineTuningJobSucceeded: fnWithKey('fine_tuning.job.succeeded'),
|
|
35
|
+
handleResponseCancelled: fnWithKey('response.cancelled'),
|
|
36
|
+
handleResponseCompleted: fnWithKey('response.completed'),
|
|
37
|
+
handleResponseFailed: fnWithKey('response.failed'),
|
|
38
|
+
handleResponseIncomplete: fnWithKey('response.incomplete')
|
|
39
|
+
};
|
|
40
|
+
return configurer;
|
|
41
|
+
}
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
const OPENAI_WEBHOOK_SECRET_TOKEN_ENV_VAR = 'OPENAI_WEBHOOK_SECRET_TOKEN';
|
|
@@ -46,12 +46,12 @@ const OPENAI_WEBHOOK_SECRET_TOKEN_ENV_VAR = 'OPENAI_WEBHOOK_SECRET_TOKEN';
|
|
|
46
46
|
* Configuration for OpenAIService
|
|
47
47
|
*/
|
|
48
48
|
class OpenAIWebhookServiceConfig {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
openaiWebhook;
|
|
50
|
+
static assertValidConfig(config) {
|
|
51
|
+
if (!config.openaiWebhook.webhookSecret) {
|
|
52
|
+
throw new Error('No OpenAI webhook secret specified.');
|
|
53
|
+
}
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/******************************************************************************
|
|
@@ -102,27 +102,33 @@ const OPENAI_PROJECT_ID_ENV_VAR = 'OPENAI_PROJECT_ID';
|
|
|
102
102
|
* Configuration for OpenAIService
|
|
103
103
|
*/
|
|
104
104
|
class OpenAIServiceConfig {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
openai;
|
|
106
|
+
static assertValidConfig(config) {
|
|
107
|
+
if (!config.openai.config.apiKey) {
|
|
108
|
+
throw new Error('No OpenAI API key specified.');
|
|
109
|
+
}
|
|
110
|
+
else if (!config.openai.config.organization) {
|
|
111
|
+
throw new Error('No OpenAI organization specified.');
|
|
112
|
+
}
|
|
113
|
+
else if (!config.openai.config.project) {
|
|
114
|
+
throw new Error('No OpenAI project specified.');
|
|
115
|
+
}
|
|
113
116
|
}
|
|
114
|
-
}
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
exports.OpenAIApi = class OpenAIApi {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
config;
|
|
121
|
+
openAIClient;
|
|
122
|
+
constructor(config) {
|
|
123
|
+
this.config = config;
|
|
124
|
+
this.openAIClient = new openai.OpenAI(config.openai.config);
|
|
125
|
+
}
|
|
124
126
|
};
|
|
125
|
-
exports.OpenAIApi = __decorate([
|
|
127
|
+
exports.OpenAIApi = __decorate([
|
|
128
|
+
common.Injectable(),
|
|
129
|
+
__param(0, common.Inject(OpenAIServiceConfig)),
|
|
130
|
+
__metadata("design:paramtypes", [OpenAIServiceConfig])
|
|
131
|
+
], exports.OpenAIApi);
|
|
126
132
|
|
|
127
133
|
/**
|
|
128
134
|
* Verifies a OpenAI webhook event header.
|
|
@@ -131,124 +137,150 @@ exports.OpenAIApi = __decorate([common.Injectable(), __param(0, common.Inject(Op
|
|
|
131
137
|
* @returns A function that verifies a OpenAI webhook event.
|
|
132
138
|
*/
|
|
133
139
|
function openAIWebhookEventVerifier(config) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
140
|
+
const { secret, client } = config;
|
|
141
|
+
return async (request, rawBody) => {
|
|
142
|
+
const headers = request.headers;
|
|
143
|
+
const requestBodyString = String(request.body);
|
|
144
|
+
let event;
|
|
145
|
+
let valid = false;
|
|
146
|
+
try {
|
|
147
|
+
event = await client.webhooks.unwrap(requestBodyString, headers, secret);
|
|
148
|
+
valid = true;
|
|
149
|
+
}
|
|
150
|
+
catch (e) {
|
|
151
|
+
if (e instanceof openai.InvalidWebhookSignatureError) {
|
|
152
|
+
valid = false;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
throw e;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const result = {
|
|
159
|
+
valid,
|
|
160
|
+
event
|
|
161
|
+
};
|
|
162
|
+
return result;
|
|
156
163
|
};
|
|
157
|
-
return result;
|
|
158
|
-
};
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
/**
|
|
162
167
|
* Service that makes system changes based on OpenAI webhook events.
|
|
163
168
|
*/
|
|
164
169
|
exports.OpenAIWebhookService = class OpenAIWebhookService {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
client: openAiApi.openAIClient
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
async updateForWebhook(req, rawBody) {
|
|
179
|
-
const result = await this._verifier(req, rawBody);
|
|
180
|
-
if (!result.valid) {
|
|
181
|
-
this.logger.warn('Received invalid OpenAI event.', req);
|
|
182
|
-
} else {
|
|
183
|
-
await this.updateForOpenAIEvent(result.event);
|
|
170
|
+
logger = new common.Logger('OpenAIWebhookService');
|
|
171
|
+
_verifier;
|
|
172
|
+
handler = openaiEventHandlerFactory();
|
|
173
|
+
configure = openaiEventHandlerConfigurerFactory(this.handler);
|
|
174
|
+
constructor(openAiApi, openAIWebhookServiceConfig) {
|
|
175
|
+
const { webhookSecret } = openAIWebhookServiceConfig.openaiWebhook;
|
|
176
|
+
this._verifier = openAIWebhookEventVerifier({
|
|
177
|
+
secret: webhookSecret,
|
|
178
|
+
client: openAiApi.openAIClient
|
|
179
|
+
});
|
|
184
180
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
181
|
+
async updateForWebhook(req, rawBody) {
|
|
182
|
+
const result = await this._verifier(req, rawBody);
|
|
183
|
+
if (!result.valid) {
|
|
184
|
+
this.logger.warn('Received invalid OpenAI event.', req);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
await this.updateForOpenAIEvent(result.event);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async updateForOpenAIEvent(event) {
|
|
191
|
+
const result = await this.handler(event);
|
|
192
|
+
if (!result) {
|
|
193
|
+
this.logger.warn('Received unexpected/unhandled OpenAI event.', event);
|
|
194
|
+
}
|
|
190
195
|
}
|
|
191
|
-
}
|
|
192
196
|
};
|
|
193
|
-
exports.OpenAIWebhookService = __decorate([
|
|
197
|
+
exports.OpenAIWebhookService = __decorate([
|
|
198
|
+
common.Injectable(),
|
|
199
|
+
__param(0, common.Inject(exports.OpenAIApi)),
|
|
200
|
+
__param(1, common.Inject(OpenAIWebhookServiceConfig)),
|
|
201
|
+
__metadata("design:paramtypes", [exports.OpenAIApi, OpenAIWebhookServiceConfig])
|
|
202
|
+
], exports.OpenAIWebhookService);
|
|
194
203
|
|
|
195
204
|
exports.OpenAIWebhookController = class OpenAIWebhookController {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
205
|
+
_openaiWebhookService;
|
|
206
|
+
constructor(openaiWebhookService) {
|
|
207
|
+
this._openaiWebhookService = openaiWebhookService;
|
|
208
|
+
}
|
|
209
|
+
async handleOpenAIWebhook(req, rawBody) {
|
|
210
|
+
await this._openaiWebhookService.updateForWebhook(req, rawBody);
|
|
211
|
+
}
|
|
203
212
|
};
|
|
204
|
-
__decorate([
|
|
205
|
-
|
|
213
|
+
__decorate([
|
|
214
|
+
common.Post(),
|
|
215
|
+
__param(0, common.Req()),
|
|
216
|
+
__param(1, nestjs.RawBody()),
|
|
217
|
+
__metadata("design:type", Function),
|
|
218
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
219
|
+
__metadata("design:returntype", Promise)
|
|
220
|
+
], exports.OpenAIWebhookController.prototype, "handleOpenAIWebhook", null);
|
|
221
|
+
exports.OpenAIWebhookController = __decorate([
|
|
222
|
+
common.Controller('/webhook/openai'),
|
|
223
|
+
__param(0, common.Inject(exports.OpenAIWebhookService)),
|
|
224
|
+
__metadata("design:paramtypes", [exports.OpenAIWebhookService])
|
|
225
|
+
], exports.OpenAIWebhookController);
|
|
206
226
|
|
|
207
227
|
function openAIServiceConfigFactory(configService) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
228
|
+
const config = {
|
|
229
|
+
openai: {
|
|
230
|
+
config: {
|
|
231
|
+
apiKey: configService.get(OPENAI_API_KEY_ENV_VAR),
|
|
232
|
+
baseURL: configService.get(OPENAI_BASE_URL_ENV_VAR) ?? undefined,
|
|
233
|
+
organization: configService.get(OPENAI_ORGANIZATION_ID_ENV_VAR),
|
|
234
|
+
project: configService.get(OPENAI_PROJECT_ID_ENV_VAR)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
OpenAIServiceConfig.assertValidConfig(config);
|
|
239
|
+
return config;
|
|
220
240
|
}
|
|
221
|
-
exports.OpenAIModule = class OpenAIModule {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
241
|
+
exports.OpenAIModule = class OpenAIModule {
|
|
242
|
+
};
|
|
243
|
+
exports.OpenAIModule = __decorate([
|
|
244
|
+
common.Module({
|
|
245
|
+
imports: [config.ConfigModule],
|
|
246
|
+
providers: [
|
|
247
|
+
{
|
|
248
|
+
provide: OpenAIServiceConfig,
|
|
249
|
+
inject: [config.ConfigService],
|
|
250
|
+
useFactory: openAIServiceConfigFactory
|
|
251
|
+
},
|
|
252
|
+
exports.OpenAIApi
|
|
253
|
+
],
|
|
254
|
+
exports: [exports.OpenAIApi]
|
|
255
|
+
})
|
|
256
|
+
], exports.OpenAIModule);
|
|
231
257
|
|
|
232
258
|
function openAIWebhookServiceConfigFactory(configService) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
259
|
+
const config = {
|
|
260
|
+
openaiWebhook: {
|
|
261
|
+
webhookSecret: configService.get(OPENAI_WEBHOOK_SECRET_TOKEN_ENV_VAR)
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
OpenAIWebhookServiceConfig.assertValidConfig(config);
|
|
265
|
+
return config;
|
|
240
266
|
}
|
|
241
|
-
exports.OpenAIWebhookModule = class OpenAIWebhookModule {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
267
|
+
exports.OpenAIWebhookModule = class OpenAIWebhookModule {
|
|
268
|
+
};
|
|
269
|
+
exports.OpenAIWebhookModule = __decorate([
|
|
270
|
+
common.Module({
|
|
271
|
+
imports: [config.ConfigModule, exports.OpenAIModule],
|
|
272
|
+
controllers: [exports.OpenAIWebhookController],
|
|
273
|
+
providers: [
|
|
274
|
+
{
|
|
275
|
+
provide: OpenAIWebhookServiceConfig,
|
|
276
|
+
inject: [config.ConfigService],
|
|
277
|
+
useFactory: openAIWebhookServiceConfigFactory
|
|
278
|
+
},
|
|
279
|
+
exports.OpenAIWebhookService
|
|
280
|
+
],
|
|
281
|
+
exports: [exports.OpenAIWebhookService]
|
|
282
|
+
})
|
|
283
|
+
], exports.OpenAIWebhookModule);
|
|
252
284
|
|
|
253
285
|
/**
|
|
254
286
|
* Returns true if the response has a json response.
|
|
@@ -257,7 +289,7 @@ exports.OpenAIWebhookModule = __decorate([common.Module({
|
|
|
257
289
|
* @returns
|
|
258
290
|
*/
|
|
259
291
|
function isParsedOpenAIJsonResponseWithJson(response) {
|
|
260
|
-
|
|
292
|
+
return response.isJsonResponse && Boolean(response.jsonResponse) && Boolean(response.jsonResponseFieldMap);
|
|
261
293
|
}
|
|
262
294
|
/**
|
|
263
295
|
* Parses the OpenAI response into a ParsedOpenAIJsonResponse.
|
|
@@ -266,21 +298,22 @@ function isParsedOpenAIJsonResponseWithJson(response) {
|
|
|
266
298
|
* @returns The parsed OpenAI response.
|
|
267
299
|
*/
|
|
268
300
|
function parseOpenAIJsonResponse(response) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
301
|
+
const output_text = typeof response === 'string' ? response : response.output_text;
|
|
302
|
+
let jsonResponse = undefined;
|
|
303
|
+
let jsonResponseFieldMap = undefined;
|
|
304
|
+
try {
|
|
305
|
+
jsonResponse = JSON.parse(output_text);
|
|
306
|
+
jsonResponseFieldMap = openAIJsonResponseFieldsMap(jsonResponse);
|
|
307
|
+
}
|
|
308
|
+
catch (e) {
|
|
309
|
+
// ignore
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
output_text,
|
|
313
|
+
isJsonResponse: Boolean(jsonResponse),
|
|
314
|
+
jsonResponse,
|
|
315
|
+
jsonResponseFieldMap
|
|
316
|
+
};
|
|
284
317
|
}
|
|
285
318
|
/**
|
|
286
319
|
* Creates a map of the OpenAI json response fields.
|
|
@@ -289,7 +322,7 @@ function parseOpenAIJsonResponse(response) {
|
|
|
289
322
|
* @returns The map of the OpenAI json response fields.
|
|
290
323
|
*/
|
|
291
324
|
function openAIJsonResponseFieldsMap(response) {
|
|
292
|
-
|
|
325
|
+
return new Map(response.fields.map((x) => [x.field_name, x.field_value]));
|
|
293
326
|
}
|
|
294
327
|
|
|
295
328
|
exports.OPENAI_API_KEY_ENV_VAR = OPENAI_API_KEY_ENV_VAR;
|