@fonoster/common 0.12.15 → 0.13.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.
@@ -189,7 +189,7 @@ declare const assistantSchema: z.ZodObject<{
189
189
  method: z.ZodDefault<z.ZodNativeEnum<typeof import("..").AllowedHttpMethod>>;
190
190
  url: z.ZodString;
191
191
  waitForResponse: z.ZodDefault<z.ZodBoolean>;
192
- headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
192
+ headers: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>>;
193
193
  }, "strip", z.ZodTypeAny, {
194
194
  url?: string;
195
195
  method?: import("..").AllowedHttpMethod;
@@ -87,7 +87,7 @@ declare const languageModelConfigSchema: z.ZodObject<{
87
87
  method: z.ZodDefault<z.ZodNativeEnum<typeof import("..").AllowedHttpMethod>>;
88
88
  url: z.ZodString;
89
89
  waitForResponse: z.ZodDefault<z.ZodBoolean>;
90
- headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
90
+ headers: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>>;
91
91
  }, "strip", z.ZodTypeAny, {
92
92
  url?: string;
93
93
  method?: import("..").AllowedHttpMethod;
@@ -67,7 +67,7 @@ declare const toolSchema: z.ZodObject<{
67
67
  method: z.ZodDefault<z.ZodNativeEnum<typeof AllowedHttpMethod>>;
68
68
  url: z.ZodString;
69
69
  waitForResponse: z.ZodDefault<z.ZodBoolean>;
70
- headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
70
+ headers: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>>;
71
71
  }, "strip", z.ZodTypeAny, {
72
72
  url?: string;
73
73
  method?: AllowedHttpMethod;
@@ -73,7 +73,13 @@ const toolSchema = zod_1.z.object({
73
73
  .default(sendHttpRequest_1.AllowedHttpMethod.GET),
74
74
  url: zod_1.z.string().url({ message: Messages.VALID_URL }),
75
75
  waitForResponse: zod_1.z.boolean().default(true),
76
- headers: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional()
76
+ headers: zod_1.z
77
+ .record(zod_1.z.string(), zod_1.z.string())
78
+ .refine((headers) => !Object.keys(headers || {}).some((key) => key.toLowerCase() === "accept" ||
79
+ key.toLowerCase() === "content-type"), {
80
+ message: "Headers cannot include 'accept' or 'content-type' as they are set internally"
81
+ })
82
+ .optional()
77
83
  })
78
84
  });
79
85
  exports.toolSchema = toolSchema;
@@ -226,6 +226,7 @@ message VerifyCodeRequest {
226
226
 
227
227
  message SendResetPasswordCodeRequest {
228
228
  string username = 1;
229
+ string reset_password_url = 2;
229
230
  }
230
231
 
231
232
  message ResetPasswordRequest {
@@ -2,12 +2,12 @@ declare enum AllowedHttpMethod {
2
2
  GET = "get",
3
3
  POST = "post"
4
4
  }
5
- declare function sendHttpRequest(params: {
5
+ declare function sendHttpRequest(request: {
6
6
  method: AllowedHttpMethod;
7
7
  url: string;
8
8
  waitForResponse: boolean;
9
9
  headers?: Record<string, string>;
10
- body?: Record<string, unknown>;
10
+ params?: Record<string, unknown>;
11
11
  }): Promise<{
12
12
  result: string;
13
13
  }>;
@@ -29,6 +29,7 @@ exports.sendHttpRequest = sendHttpRequest;
29
29
  * See the License for the specific language governing permissions and
30
30
  * limitations under the License.
31
31
  */
32
+ const url_1 = require("url");
32
33
  const logger_1 = require("@fonoster/logger");
33
34
  const zod_1 = require("zod");
34
35
  const responseSchema = zod_1.z.object({
@@ -40,25 +41,35 @@ var AllowedHttpMethod;
40
41
  AllowedHttpMethod["GET"] = "get";
41
42
  AllowedHttpMethod["POST"] = "post";
42
43
  })(AllowedHttpMethod || (exports.AllowedHttpMethod = AllowedHttpMethod = {}));
43
- function sendHttpRequest(params) {
44
+ function sendHttpRequest(request) {
44
45
  return __awaiter(this, void 0, void 0, function* () {
45
- const { url, method, body, headers, waitForResponse } = params;
46
+ const { url, method, params, headers, waitForResponse } = request;
46
47
  const effectiveMethod = method.toLowerCase();
48
+ let effectiveUrl = url;
49
+ if (effectiveMethod === AllowedHttpMethod.GET && params) {
50
+ const queryParams = new url_1.URLSearchParams();
51
+ Object.entries(params).forEach(([key, value]) => {
52
+ queryParams.append(key, String(value));
53
+ });
54
+ effectiveUrl = `${url}${url.includes("?") ? "&" : "?"}${queryParams.toString()}`;
55
+ }
47
56
  const options = {
48
- method,
49
- headers: Object.assign({ "Content-Type": "application/json" }, headers),
50
- body: effectiveMethod === "post" ? JSON.stringify(body) : undefined
57
+ method: effectiveMethod,
58
+ headers: Object.assign(Object.assign({}, headers), { accept: "application/json", "content-type": "application/json" }),
59
+ body: effectiveMethod === AllowedHttpMethod.POST
60
+ ? JSON.stringify(params)
61
+ : undefined
51
62
  };
52
- logger.silly(`sending request to ${url}`, {
53
- body,
63
+ logger.silly(`sending request to ${effectiveUrl}`, {
64
+ params,
54
65
  method: effectiveMethod
55
66
  });
56
- if (waitForResponse && effectiveMethod === "post") {
57
- setTimeout(() => fetch(url, options), 0);
58
- return { result: "request sent" };
67
+ if (!waitForResponse && effectiveMethod === AllowedHttpMethod.POST) {
68
+ setTimeout(() => fetch(effectiveUrl, options), 0);
69
+ return { result: "success" };
59
70
  }
60
71
  else {
61
- const response = yield fetch(url, options);
72
+ const response = yield fetch(effectiveUrl, options);
62
73
  const data = yield response.json();
63
74
  try {
64
75
  return responseSchema.parse(data);
@@ -182,10 +182,13 @@ declare const verifyCodeRequestSchema: z.ZodObject<{
182
182
  }>;
183
183
  declare const sendResetPasswordCodeRequestSchema: z.ZodObject<{
184
184
  username: z.ZodString;
185
+ resetPasswordUrl: z.ZodString;
185
186
  }, "strip", z.ZodTypeAny, {
186
187
  username?: string;
188
+ resetPasswordUrl?: string;
187
189
  }, {
188
190
  username?: string;
191
+ resetPasswordUrl?: string;
189
192
  }>;
190
193
  declare const resetPasswordRequestSchema: z.ZodObject<{
191
194
  username: z.ZodString;
@@ -133,7 +133,8 @@ exports.verifyCodeRequestSchema = verifyCodeRequestSchema;
133
133
  const sendResetPasswordCodeRequestSchema = zod_1.z.object({
134
134
  username: zod_1.z
135
135
  .string()
136
- .email({ message: "Invalid username. Must be an email address" })
136
+ .email({ message: "Invalid username. Must be an email address" }),
137
+ resetPasswordUrl: zod_1.z.string()
137
138
  });
138
139
  exports.sendResetPasswordCodeRequestSchema = sendResetPasswordCodeRequestSchema;
139
140
  const resetPasswordRequestSchema = zod_1.z.object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/common",
3
- "version": "0.12.15",
3
+ "version": "0.13.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.12.6",
21
+ "@fonoster/logger": "^0.13.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",
@@ -49,5 +49,5 @@
49
49
  "devDependencies": {
50
50
  "@types/nodemailer": "^6.4.14"
51
51
  },
52
- "gitHead": "30cdb9b4a04b427eef2d35701ec1c4b62f6fad4d"
52
+ "gitHead": "1bbd25f403d05c2340676f8e29b9e00cd4db4bdb"
53
53
  }