@fonoster/common 0.8.59 → 0.9.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.
@@ -164,31 +164,21 @@ declare const assistantSchema: z.ZodObject<{
164
164
  required?: string[];
165
165
  }>;
166
166
  requestStartMessage: z.ZodOptional<z.ZodString>;
167
- operation: z.ZodEffects<z.ZodObject<{
168
- type: z.ZodNativeEnum<typeof import("./tools/AllowedOperations").AllowedOperations>;
169
- url: z.ZodOptional<z.ZodString>;
170
- waitForResponse: z.ZodOptional<z.ZodBoolean>;
167
+ operation: z.ZodObject<{
168
+ method: z.ZodDefault<z.ZodNativeEnum<typeof import("..").AllowedHttpMethod>>;
169
+ url: z.ZodString;
170
+ waitForResponse: z.ZodDefault<z.ZodBoolean>;
171
171
  headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
172
172
  }, "strip", z.ZodTypeAny, {
173
- type?: import("./tools/AllowedOperations").AllowedOperations;
174
173
  url?: string;
175
- waitForResponse?: boolean;
174
+ method?: import("..").AllowedHttpMethod;
176
175
  headers?: Record<string, string>;
177
- }, {
178
- type?: import("./tools/AllowedOperations").AllowedOperations;
179
- url?: string;
180
176
  waitForResponse?: boolean;
181
- headers?: Record<string, string>;
182
- }>, {
183
- type?: import("./tools/AllowedOperations").AllowedOperations;
184
- url?: string;
185
- waitForResponse?: boolean;
186
- headers?: Record<string, string>;
187
177
  }, {
188
- type?: import("./tools/AllowedOperations").AllowedOperations;
189
178
  url?: string;
190
- waitForResponse?: boolean;
179
+ method?: import("..").AllowedHttpMethod;
191
180
  headers?: Record<string, string>;
181
+ waitForResponse?: boolean;
192
182
  }>;
193
183
  }, "strip", z.ZodTypeAny, {
194
184
  name?: string;
@@ -204,10 +194,10 @@ declare const assistantSchema: z.ZodObject<{
204
194
  };
205
195
  requestStartMessage?: string;
206
196
  operation?: {
207
- type?: import("./tools/AllowedOperations").AllowedOperations;
208
197
  url?: string;
209
- waitForResponse?: boolean;
198
+ method?: import("..").AllowedHttpMethod;
210
199
  headers?: Record<string, string>;
200
+ waitForResponse?: boolean;
211
201
  };
212
202
  }, {
213
203
  name?: string;
@@ -223,10 +213,10 @@ declare const assistantSchema: z.ZodObject<{
223
213
  };
224
214
  requestStartMessage?: string;
225
215
  operation?: {
226
- type?: import("./tools/AllowedOperations").AllowedOperations;
227
216
  url?: string;
228
- waitForResponse?: boolean;
217
+ method?: import("..").AllowedHttpMethod;
229
218
  headers?: Record<string, string>;
219
+ waitForResponse?: boolean;
230
220
  };
231
221
  }>, "many">>;
232
222
  }, "strip", z.ZodTypeAny, {
@@ -255,10 +245,10 @@ declare const assistantSchema: z.ZodObject<{
255
245
  };
256
246
  requestStartMessage?: string;
257
247
  operation?: {
258
- type?: import("./tools/AllowedOperations").AllowedOperations;
259
248
  url?: string;
260
- waitForResponse?: boolean;
249
+ method?: import("..").AllowedHttpMethod;
261
250
  headers?: Record<string, string>;
251
+ waitForResponse?: boolean;
262
252
  };
263
253
  }[];
264
254
  }, {
@@ -287,13 +277,26 @@ declare const assistantSchema: z.ZodObject<{
287
277
  };
288
278
  requestStartMessage?: string;
289
279
  operation?: {
290
- type?: import("./tools/AllowedOperations").AllowedOperations;
291
280
  url?: string;
292
- waitForResponse?: boolean;
281
+ method?: import("..").AllowedHttpMethod;
293
282
  headers?: Record<string, string>;
283
+ waitForResponse?: boolean;
294
284
  };
295
285
  }[];
296
286
  }>;
287
+ eventsHook: z.ZodOptional<z.ZodObject<{
288
+ url: z.ZodString;
289
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
290
+ events: z.ZodDefault<z.ZodArray<z.ZodNativeEnum<typeof import("./eventsHookSchema").EventsHookAllowedEvents>, "many">>;
291
+ }, "strip", z.ZodTypeAny, {
292
+ url?: string;
293
+ headers?: Record<string, string>;
294
+ events?: import("./eventsHookSchema").EventsHookAllowedEvents[];
295
+ }, {
296
+ url?: string;
297
+ headers?: Record<string, string>;
298
+ events?: import("./eventsHookSchema").EventsHookAllowedEvents[];
299
+ }>>;
297
300
  testCases: z.ZodOptional<z.ZodObject<{
298
301
  evalsLanguageModel: z.ZodObject<{
299
302
  provider: z.ZodEnum<["openai"]>;
@@ -546,13 +549,18 @@ declare const assistantSchema: z.ZodObject<{
546
549
  };
547
550
  requestStartMessage?: string;
548
551
  operation?: {
549
- type?: import("./tools/AllowedOperations").AllowedOperations;
550
552
  url?: string;
551
- waitForResponse?: boolean;
553
+ method?: import("..").AllowedHttpMethod;
552
554
  headers?: Record<string, string>;
555
+ waitForResponse?: boolean;
553
556
  };
554
557
  }[];
555
558
  };
559
+ eventsHook?: {
560
+ url?: string;
561
+ headers?: Record<string, string>;
562
+ events?: import("./eventsHookSchema").EventsHookAllowedEvents[];
563
+ };
556
564
  testCases?: {
557
565
  evalsLanguageModel?: {
558
566
  provider?: "openai";
@@ -635,13 +643,18 @@ declare const assistantSchema: z.ZodObject<{
635
643
  };
636
644
  requestStartMessage?: string;
637
645
  operation?: {
638
- type?: import("./tools/AllowedOperations").AllowedOperations;
639
646
  url?: string;
640
- waitForResponse?: boolean;
647
+ method?: import("..").AllowedHttpMethod;
641
648
  headers?: Record<string, string>;
649
+ waitForResponse?: boolean;
642
650
  };
643
651
  }[];
644
652
  };
653
+ eventsHook?: {
654
+ url?: string;
655
+ headers?: Record<string, string>;
656
+ events?: import("./eventsHookSchema").EventsHookAllowedEvents[];
657
+ };
645
658
  testCases?: {
646
659
  evalsLanguageModel?: {
647
660
  provider?: "openai";
@@ -23,9 +23,11 @@ const zod_1 = require("zod");
23
23
  const conversationSettingsSchema_1 = require("./conversationSettingsSchema");
24
24
  const languageModelConfigSchema_1 = require("./languageModelConfigSchema");
25
25
  const testCasesSchema_1 = require("./testCasesSchema");
26
+ const eventsHookSchema_1 = require("./eventsHookSchema");
26
27
  const assistantSchema = zod_1.z.object({
27
28
  conversationSettings: conversationSettingsSchema_1.conversationSettingsSchema,
28
29
  languageModel: languageModelConfigSchema_1.languageModelConfigSchema,
30
+ eventsHook: eventsHookSchema_1.eventsHookSchema.optional(),
29
31
  testCases: testCasesSchema_1.testCasesSchema.optional()
30
32
  });
31
33
  exports.assistantSchema = assistantSchema;
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ declare enum EventsHookAllowedEvents {
3
+ ALL = "all",
4
+ CONVERSATION_STARTED = "conversation.started",
5
+ CONVERSATION_ENDED = "conversation.ended"
6
+ }
7
+ declare const eventsHookSchema: z.ZodObject<{
8
+ url: z.ZodString;
9
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
10
+ events: z.ZodDefault<z.ZodArray<z.ZodNativeEnum<typeof EventsHookAllowedEvents>, "many">>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ url?: string;
13
+ headers?: Record<string, string>;
14
+ events?: EventsHookAllowedEvents[];
15
+ }, {
16
+ url?: string;
17
+ headers?: Record<string, string>;
18
+ events?: EventsHookAllowedEvents[];
19
+ }>;
20
+ export { eventsHookSchema, EventsHookAllowedEvents };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.EventsHookAllowedEvents = exports.eventsHookSchema = void 0;
37
+ /*
38
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
39
+ * http://github.com/fonoster/fonoster
40
+ *
41
+ * This file is part of Fonoster
42
+ *
43
+ * Licensed under the MIT License (the "License");
44
+ * you may not use this file except in compliance with
45
+ * the License. You may obtain a copy of the License at
46
+ *
47
+ * https://opensource.org/licenses/MIT
48
+ *
49
+ * Unless required by applicable law or agreed to in writing, software
50
+ * distributed under the License is distributed on an "AS IS" BASIS,
51
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52
+ * See the License for the specific language governing permissions and
53
+ * limitations under the License.
54
+ */
55
+ const zod_1 = require("zod");
56
+ const Messages = __importStar(require("../messages"));
57
+ var EventsHookAllowedEvents;
58
+ (function (EventsHookAllowedEvents) {
59
+ EventsHookAllowedEvents["ALL"] = "all";
60
+ EventsHookAllowedEvents["CONVERSATION_STARTED"] = "conversation.started";
61
+ EventsHookAllowedEvents["CONVERSATION_ENDED"] = "conversation.ended";
62
+ })(EventsHookAllowedEvents || (exports.EventsHookAllowedEvents = EventsHookAllowedEvents = {}));
63
+ const eventsHookSchema = zod_1.z.object({
64
+ url: zod_1.z.string().url({ message: Messages.VALID_URL }),
65
+ headers: zod_1.z.record(zod_1.z.string()).optional(),
66
+ events: zod_1.z
67
+ .array(zod_1.z.nativeEnum(EventsHookAllowedEvents))
68
+ .min(1)
69
+ .default([EventsHookAllowedEvents.ALL])
70
+ });
71
+ exports.eventsHookSchema = eventsHookSchema;
@@ -3,3 +3,4 @@ export * from "./assistantSchema";
3
3
  export * from "./LanguageModelProvider";
4
4
  export * from "./conversationSettingsSchema";
5
5
  export * from "./languageModelConfigSchema";
6
+ export * from "./eventsHookSchema";
@@ -37,3 +37,4 @@ __exportStar(require("./assistantSchema"), exports);
37
37
  __exportStar(require("./LanguageModelProvider"), exports);
38
38
  __exportStar(require("./conversationSettingsSchema"), exports);
39
39
  __exportStar(require("./languageModelConfigSchema"), exports);
40
+ __exportStar(require("./eventsHookSchema"), exports);
@@ -65,31 +65,21 @@ declare const languageModelConfigSchema: z.ZodObject<{
65
65
  required?: string[];
66
66
  }>;
67
67
  requestStartMessage: z.ZodOptional<z.ZodString>;
68
- operation: z.ZodEffects<z.ZodObject<{
69
- type: z.ZodNativeEnum<typeof import("./tools/AllowedOperations").AllowedOperations>;
70
- url: z.ZodOptional<z.ZodString>;
71
- waitForResponse: z.ZodOptional<z.ZodBoolean>;
68
+ operation: z.ZodObject<{
69
+ method: z.ZodDefault<z.ZodNativeEnum<typeof import("..").AllowedHttpMethod>>;
70
+ url: z.ZodString;
71
+ waitForResponse: z.ZodDefault<z.ZodBoolean>;
72
72
  headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
73
73
  }, "strip", z.ZodTypeAny, {
74
- type?: import("./tools/AllowedOperations").AllowedOperations;
75
74
  url?: string;
76
- waitForResponse?: boolean;
75
+ method?: import("..").AllowedHttpMethod;
77
76
  headers?: Record<string, string>;
78
- }, {
79
- type?: import("./tools/AllowedOperations").AllowedOperations;
80
- url?: string;
81
77
  waitForResponse?: boolean;
82
- headers?: Record<string, string>;
83
- }>, {
84
- type?: import("./tools/AllowedOperations").AllowedOperations;
85
- url?: string;
86
- waitForResponse?: boolean;
87
- headers?: Record<string, string>;
88
78
  }, {
89
- type?: import("./tools/AllowedOperations").AllowedOperations;
90
79
  url?: string;
91
- waitForResponse?: boolean;
80
+ method?: import("..").AllowedHttpMethod;
92
81
  headers?: Record<string, string>;
82
+ waitForResponse?: boolean;
93
83
  }>;
94
84
  }, "strip", z.ZodTypeAny, {
95
85
  name?: string;
@@ -105,10 +95,10 @@ declare const languageModelConfigSchema: z.ZodObject<{
105
95
  };
106
96
  requestStartMessage?: string;
107
97
  operation?: {
108
- type?: import("./tools/AllowedOperations").AllowedOperations;
109
98
  url?: string;
110
- waitForResponse?: boolean;
99
+ method?: import("..").AllowedHttpMethod;
111
100
  headers?: Record<string, string>;
101
+ waitForResponse?: boolean;
112
102
  };
113
103
  }, {
114
104
  name?: string;
@@ -124,10 +114,10 @@ declare const languageModelConfigSchema: z.ZodObject<{
124
114
  };
125
115
  requestStartMessage?: string;
126
116
  operation?: {
127
- type?: import("./tools/AllowedOperations").AllowedOperations;
128
117
  url?: string;
129
- waitForResponse?: boolean;
118
+ method?: import("..").AllowedHttpMethod;
130
119
  headers?: Record<string, string>;
120
+ waitForResponse?: boolean;
131
121
  };
132
122
  }>, "many">>;
133
123
  }, "strip", z.ZodTypeAny, {
@@ -156,10 +146,10 @@ declare const languageModelConfigSchema: z.ZodObject<{
156
146
  };
157
147
  requestStartMessage?: string;
158
148
  operation?: {
159
- type?: import("./tools/AllowedOperations").AllowedOperations;
160
149
  url?: string;
161
- waitForResponse?: boolean;
150
+ method?: import("..").AllowedHttpMethod;
162
151
  headers?: Record<string, string>;
152
+ waitForResponse?: boolean;
163
153
  };
164
154
  }[];
165
155
  }, {
@@ -188,10 +178,10 @@ declare const languageModelConfigSchema: z.ZodObject<{
188
178
  };
189
179
  requestStartMessage?: string;
190
180
  operation?: {
191
- type?: import("./tools/AllowedOperations").AllowedOperations;
192
181
  url?: string;
193
- waitForResponse?: boolean;
182
+ method?: import("..").AllowedHttpMethod;
194
183
  headers?: Record<string, string>;
184
+ waitForResponse?: boolean;
195
185
  };
196
186
  }[];
197
187
  }>;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { AllowedOperations } from "./AllowedOperations";
2
+ import { AllowedHttpMethod } from "../../utils/sendHttpRequest";
3
3
  declare const toolSchema: z.ZodObject<{
4
4
  name: z.ZodString;
5
5
  description: z.ZodString;
@@ -45,31 +45,21 @@ declare const toolSchema: z.ZodObject<{
45
45
  required?: string[];
46
46
  }>;
47
47
  requestStartMessage: z.ZodOptional<z.ZodString>;
48
- operation: z.ZodEffects<z.ZodObject<{
49
- type: z.ZodNativeEnum<typeof AllowedOperations>;
50
- url: z.ZodOptional<z.ZodString>;
51
- waitForResponse: z.ZodOptional<z.ZodBoolean>;
48
+ operation: z.ZodObject<{
49
+ method: z.ZodDefault<z.ZodNativeEnum<typeof AllowedHttpMethod>>;
50
+ url: z.ZodString;
51
+ waitForResponse: z.ZodDefault<z.ZodBoolean>;
52
52
  headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
53
53
  }, "strip", z.ZodTypeAny, {
54
- type?: AllowedOperations;
55
54
  url?: string;
56
- waitForResponse?: boolean;
55
+ method?: AllowedHttpMethod;
57
56
  headers?: Record<string, string>;
58
- }, {
59
- type?: AllowedOperations;
60
- url?: string;
61
57
  waitForResponse?: boolean;
62
- headers?: Record<string, string>;
63
- }>, {
64
- type?: AllowedOperations;
65
- url?: string;
66
- waitForResponse?: boolean;
67
- headers?: Record<string, string>;
68
58
  }, {
69
- type?: AllowedOperations;
70
59
  url?: string;
71
- waitForResponse?: boolean;
60
+ method?: AllowedHttpMethod;
72
61
  headers?: Record<string, string>;
62
+ waitForResponse?: boolean;
73
63
  }>;
74
64
  }, "strip", z.ZodTypeAny, {
75
65
  name?: string;
@@ -85,10 +75,10 @@ declare const toolSchema: z.ZodObject<{
85
75
  };
86
76
  requestStartMessage?: string;
87
77
  operation?: {
88
- type?: AllowedOperations;
89
78
  url?: string;
90
- waitForResponse?: boolean;
79
+ method?: AllowedHttpMethod;
91
80
  headers?: Record<string, string>;
81
+ waitForResponse?: boolean;
92
82
  };
93
83
  }, {
94
84
  name?: string;
@@ -104,10 +94,10 @@ declare const toolSchema: z.ZodObject<{
104
94
  };
105
95
  requestStartMessage?: string;
106
96
  operation?: {
107
- type?: AllowedOperations;
108
97
  url?: string;
109
- waitForResponse?: boolean;
98
+ method?: AllowedHttpMethod;
110
99
  headers?: Record<string, string>;
100
+ waitForResponse?: boolean;
111
101
  };
112
102
  }>;
113
103
  export { toolSchema };
@@ -55,7 +55,7 @@ exports.toolSchema = void 0;
55
55
  const zod_1 = require("zod");
56
56
  const propertySchema_1 = require("./propertySchema");
57
57
  const Messages = __importStar(require("../../messages"));
58
- const AllowedOperations_1 = require("./AllowedOperations");
58
+ const sendHttpRequest_1 = require("../../utils/sendHttpRequest");
59
59
  const toolSchema = zod_1.z.object({
60
60
  name: zod_1.z.string(),
61
61
  description: zod_1.z.string(),
@@ -65,23 +65,15 @@ const toolSchema = zod_1.z.object({
65
65
  required: zod_1.z.array(zod_1.z.string()).optional()
66
66
  }),
67
67
  requestStartMessage: zod_1.z.string().optional(),
68
- operation: zod_1.z
69
- .object({
70
- type: zod_1.z.nativeEnum(AllowedOperations_1.AllowedOperations, {
71
- message: "Invalid operation type"
72
- }),
73
- // Make url required if operation type is not built-in
74
- url: zod_1.z.string().url({ message: Messages.VALID_URL }).optional(),
75
- waitForResponse: zod_1.z.boolean().optional(),
68
+ operation: zod_1.z.object({
69
+ method: zod_1.z
70
+ .nativeEnum(sendHttpRequest_1.AllowedHttpMethod, {
71
+ message: "Invalid method"
72
+ })
73
+ .default(sendHttpRequest_1.AllowedHttpMethod.GET),
74
+ url: zod_1.z.string().url({ message: Messages.VALID_URL }),
75
+ waitForResponse: zod_1.z.boolean().default(true),
76
76
  headers: zod_1.z.record(zod_1.z.string()).optional()
77
77
  })
78
- .superRefine(({ url, type }, ctx) => {
79
- if (type !== AllowedOperations_1.AllowedOperations.BUILT_IN && !url) {
80
- ctx.addIssue({
81
- code: zod_1.z.ZodIssueCode.custom,
82
- message: "Url is required for non built-in operations."
83
- });
84
- }
85
- })
86
78
  });
87
79
  exports.toolSchema = toolSchema;
@@ -12,3 +12,4 @@ export * from "./withValidation";
12
12
  export * from "./types";
13
13
  export * from "./createFetchSingleCallByCallId";
14
14
  export * from "./findIntegrationsCredentials";
15
+ export * from "./sendHttpRequest";
@@ -46,3 +46,4 @@ __exportStar(require("./withValidation"), exports);
46
46
  __exportStar(require("./types"), exports);
47
47
  __exportStar(require("./createFetchSingleCallByCallId"), exports);
48
48
  __exportStar(require("./findIntegrationsCredentials"), exports);
49
+ __exportStar(require("./sendHttpRequest"), exports);
@@ -0,0 +1,14 @@
1
+ declare enum AllowedHttpMethod {
2
+ GET = "get",
3
+ POST = "post"
4
+ }
5
+ declare function sendHttpRequest(params: {
6
+ method: AllowedHttpMethod;
7
+ url: string;
8
+ waitForResponse: boolean;
9
+ headers?: Record<string, string>;
10
+ body?: Record<string, unknown>;
11
+ }): Promise<{
12
+ result: string;
13
+ }>;
14
+ export { sendHttpRequest, AllowedHttpMethod };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AllowedHttpMethod = void 0;
13
+ exports.sendHttpRequest = sendHttpRequest;
14
+ /*
15
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
16
+ * http://github.com/fonoster/fonoster
17
+ *
18
+ * This file is part of Fonoster
19
+ *
20
+ * Licensed under the MIT License (the "License");
21
+ * you may not use this file except in compliance with
22
+ * the License. You may obtain a copy of the License at
23
+ *
24
+ * https://opensource.org/licenses/MIT
25
+ *
26
+ * Unless required by applicable law or agreed to in writing, software
27
+ * distributed under the License is distributed on an "AS IS" BASIS,
28
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ * See the License for the specific language governing permissions and
30
+ * limitations under the License.
31
+ */
32
+ const logger_1 = require("@fonoster/logger");
33
+ const zod_1 = require("zod");
34
+ const responseSchema = zod_1.z.object({
35
+ result: zod_1.z.string()
36
+ });
37
+ const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
38
+ var AllowedHttpMethod;
39
+ (function (AllowedHttpMethod) {
40
+ AllowedHttpMethod["GET"] = "get";
41
+ AllowedHttpMethod["POST"] = "post";
42
+ })(AllowedHttpMethod || (exports.AllowedHttpMethod = AllowedHttpMethod = {}));
43
+ function sendHttpRequest(params) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const { url, method, body, headers, waitForResponse } = params;
46
+ const effectiveMethod = method.toLowerCase();
47
+ const options = {
48
+ method,
49
+ headers: Object.assign({ "Content-Type": "application/json" }, headers),
50
+ body: effectiveMethod === "post" ? JSON.stringify(body) : undefined
51
+ };
52
+ logger.silly(`sending request to ${url}`, {
53
+ body,
54
+ method: effectiveMethod
55
+ });
56
+ if (waitForResponse && effectiveMethod === "post") {
57
+ setTimeout(() => fetch(url, options), 0);
58
+ return { result: "request sent" };
59
+ }
60
+ else {
61
+ const response = yield fetch(url, options);
62
+ const data = yield response.json();
63
+ try {
64
+ return responseSchema.parse(data);
65
+ }
66
+ catch (error) {
67
+ throw new Error(`Invalid response: expected ${JSON.stringify(responseSchema, null, 2)}, got ${JSON.stringify(data, null, 2)}`);
68
+ }
69
+ }
70
+ });
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/common",
3
- "version": "0.8.59",
3
+ "version": "0.9.0",
4
4
  "description": "Common library for Fonoster projects",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -18,7 +18,7 @@
18
18
  "clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo"
19
19
  },
20
20
  "dependencies": {
21
- "@fonoster/logger": "^0.8.59",
21
+ "@fonoster/logger": "^0.9.0",
22
22
  "@grpc/grpc-js": "~1.10.6",
23
23
  "@grpc/proto-loader": "^0.7.12",
24
24
  "@influxdata/influxdb-client": "^1.35.0",
@@ -48,5 +48,5 @@
48
48
  "devDependencies": {
49
49
  "@types/nodemailer": "^6.4.14"
50
50
  },
51
- "gitHead": "6a5255febb9e4bcd9184d93abe72281f945c8c4d"
51
+ "gitHead": "0ec8e6ef5b6ee8adfb5b1856a177a0e0bf1070b9"
52
52
  }
@@ -1,6 +0,0 @@
1
- declare enum AllowedOperations {
2
- GET = "get",
3
- POST = "post",
4
- BUILT_IN = "built-in"
5
- }
6
- export { AllowedOperations };
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AllowedOperations = void 0;
4
- /*
5
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- var AllowedOperations;
23
- (function (AllowedOperations) {
24
- AllowedOperations["GET"] = "get";
25
- AllowedOperations["POST"] = "post";
26
- AllowedOperations["BUILT_IN"] = "built-in";
27
- })(AllowedOperations || (exports.AllowedOperations = AllowedOperations = {}));