@fonoster/common 0.7.18 → 0.7.25

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.
Files changed (40) hide show
  1. package/dist/envs.d.ts +1 -0
  2. package/dist/envs.js +31 -0
  3. package/dist/errors/handleError.js +6 -1
  4. package/dist/errors/handleZodError.js +4 -2
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +2 -1
  7. package/dist/messages.d.ts +8 -0
  8. package/dist/messages.js +29 -0
  9. package/dist/notifications/createSendEmail.d.ts +3 -0
  10. package/dist/notifications/{createEmailSender.js → createSendEmail.js} +2 -2
  11. package/dist/notifications/createSendSmsTwilioImpl.d.ts +3 -0
  12. package/dist/notifications/createSendSmsTwilioImpl.js +54 -0
  13. package/dist/notifications/index.d.ts +3 -1
  14. package/dist/notifications/index.js +3 -1
  15. package/dist/notifications/types.d.ts +27 -0
  16. package/dist/notifications/types.js +2 -0
  17. package/dist/protos/identity.proto +35 -12
  18. package/dist/utils/createService.js +1 -0
  19. package/dist/validators/calls.d.ts +4 -4
  20. package/dist/validators/calls.js +18 -12
  21. package/dist/validators/common.d.ts +4 -1
  22. package/dist/validators/common.js +22 -3
  23. package/dist/validators/hostOrHostPortSchema.js +1 -1
  24. package/dist/validators/identity.d.ts +48 -6
  25. package/dist/validators/identity.js +55 -21
  26. package/dist/validators/secrets.js +3 -3
  27. package/dist/validators/sipnet/acls.d.ts +26 -2
  28. package/dist/validators/sipnet/acls.js +45 -2
  29. package/dist/validators/sipnet/agents.d.ts +41 -2
  30. package/dist/validators/sipnet/agents.js +23 -2
  31. package/dist/validators/sipnet/credentials.d.ts +20 -2
  32. package/dist/validators/sipnet/credentials.js +9 -2
  33. package/dist/validators/sipnet/domains.d.ts +43 -2
  34. package/dist/validators/sipnet/domains.js +32 -2
  35. package/dist/validators/sipnet/numbers.d.ts +29 -4
  36. package/dist/validators/sipnet/numbers.js +6 -0
  37. package/dist/validators/sipnet/trunks.d.ts +57 -1
  38. package/dist/validators/sipnet/trunks.js +45 -1
  39. package/package.json +4 -3
  40. package/dist/notifications/createEmailSender.d.ts +0 -17
package/dist/envs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const ROOT_DOMAIN: string;
package/dist/envs.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ROOT_DOMAIN = void 0;
7
+ /*
8
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/fonoster
10
+ *
11
+ * This file is part of Fonoster
12
+ *
13
+ * Licensed under the MIT License (the "License");
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const path_1 = require("path");
26
+ const dotenv_1 = __importDefault(require("dotenv"));
27
+ if (process.env.NODE_ENV === "dev") {
28
+ dotenv_1.default.config({ path: (0, path_1.join)(__dirname, "..", "..", "..", ".env") });
29
+ }
30
+ const e = process.env;
31
+ exports.ROOT_DOMAIN = e.ROOT_DOMAIN || "fonoster.local";
@@ -57,7 +57,12 @@ function handleError(error, callback) {
57
57
  const { code, message } = error;
58
58
  const logAndCallback = (errorCode, errorMessage, logMessage) => {
59
59
  logger.error(logMessage, { message: errorMessage });
60
- callback({ code: errorCode, message: errorMessage });
60
+ const messageParts = errorMessage.split(":");
61
+ let effectiveErrorMessage = errorMessage;
62
+ if (errorCode === grpc_js_1.status.NOT_FOUND && messageParts.length > 1) {
63
+ effectiveErrorMessage = `Resource not found: ${messageParts[messageParts.length - 1].trim()}`;
64
+ }
65
+ callback({ code: errorCode, message: effectiveErrorMessage });
61
66
  };
62
67
  switch (code) {
63
68
  case PrismaErrorEnum_1.PrismaErrorEnum.RECORD_ALREADY_EXISTS:
@@ -30,8 +30,10 @@ function handleZodError(error, callback) {
30
30
  callback({ code: grpc_js_1.status.INVALID_ARGUMENT, message });
31
31
  }
32
32
  else {
33
- const validationError = (0, zod_validation_error_1.fromError)(error);
34
- logger.error("validation error", { message: validationError.toString() });
33
+ const validationError = (0, zod_validation_error_1.fromError)(error, {
34
+ prefix: null
35
+ });
36
+ logger.error("Error:", { message: validationError.toString() });
35
37
  callback({
36
38
  code: grpc_js_1.status.INVALID_ARGUMENT,
37
39
  message: validationError.toString()
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./GrpcError";
2
2
  export * from "./constants";
3
3
  export * from "./errors";
4
4
  export * from "./grpcStatusMap";
5
+ export * as Messages from "./messages";
5
6
  export * from "./notifications";
6
7
  export * from "./tts";
7
8
  export * from "./types";
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Validators = void 0;
29
+ exports.Validators = exports.Messages = void 0;
30
30
  /*
31
31
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
32
32
  * http://github.com/fonoster/fonoster
@@ -49,6 +49,7 @@ __exportStar(require("./GrpcError"), exports);
49
49
  __exportStar(require("./constants"), exports);
50
50
  __exportStar(require("./errors"), exports);
51
51
  __exportStar(require("./grpcStatusMap"), exports);
52
+ exports.Messages = __importStar(require("./messages"));
52
53
  __exportStar(require("./notifications"), exports);
53
54
  __exportStar(require("./tts"), exports);
54
55
  __exportStar(require("./types"), exports);
@@ -0,0 +1,8 @@
1
+ export declare const MUST_BE_A_SINGLE_CHARACTER = "Must be a single character";
2
+ export declare const MUST_BE_A_STRING = "Must be a string";
3
+ export declare const POSITIVE_INTEGER_MESSAGE = "Must be a positive number";
4
+ export declare const VALID_DATE = "The date must be a valid ISO 8601";
5
+ export declare const VALID_DTMF = "Must be a valid DTMF";
6
+ export declare const VALID_LANGUAGE_CODE = "Must be a valid language code";
7
+ export declare const VALID_URL = "Must be a valid URL";
8
+ export declare const VALID_UUID = "Must be a valid UUID";
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VALID_UUID = exports.VALID_URL = exports.VALID_LANGUAGE_CODE = exports.VALID_DTMF = exports.VALID_DATE = exports.POSITIVE_INTEGER_MESSAGE = exports.MUST_BE_A_STRING = exports.MUST_BE_A_SINGLE_CHARACTER = void 0;
4
+ /*
5
+ * Copyright (C) 2024 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
+ exports.MUST_BE_A_SINGLE_CHARACTER = "Must be a single character";
23
+ exports.MUST_BE_A_STRING = "Must be a string";
24
+ exports.POSITIVE_INTEGER_MESSAGE = "Must be a positive number";
25
+ exports.VALID_DATE = "The date must be a valid ISO 8601";
26
+ exports.VALID_DTMF = "Must be a valid DTMF";
27
+ exports.VALID_LANGUAGE_CODE = "Must be a valid language code";
28
+ exports.VALID_URL = "Must be a valid URL";
29
+ exports.VALID_UUID = "Must be a valid UUID";
@@ -0,0 +1,3 @@
1
+ import { EmailParams, EmailSenderConfig } from "./types";
2
+ declare function createSendEmail(config: EmailSenderConfig): (params: EmailParams) => Promise<void>;
3
+ export { createSendEmail };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createEmailSender = createEmailSender;
12
+ exports.createSendEmail = createSendEmail;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -31,7 +31,7 @@ exports.createEmailSender = createEmailSender;
31
31
  const logger_1 = require("@fonoster/logger");
32
32
  const nodemailer_1 = require("nodemailer");
33
33
  const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
34
- function createEmailSender(config) {
34
+ function createSendEmail(config) {
35
35
  const { sender, host, port, secure, auth } = config;
36
36
  const transporter = (0, nodemailer_1.createTransport)({
37
37
  host,
@@ -0,0 +1,3 @@
1
+ import { SmsParams, TwilioSmsSenderConfig } from "./types";
2
+ declare function createSendSmsTwilioImpl(config: TwilioSmsSenderConfig): (params: SmsParams) => Promise<void>;
3
+ export { createSendSmsTwilioImpl };
@@ -0,0 +1,54 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createSendSmsTwilioImpl = createSendSmsTwilioImpl;
16
+ /*
17
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
18
+ * http://github.com/fonoster/fonoster
19
+ *
20
+ * This file is part of Fonoster
21
+ *
22
+ * Licensed under the MIT License (the "License");
23
+ * you may not use this file except in compliance with
24
+ * the License. You may obtain a copy of the License at
25
+ *
26
+ * https://opensource.org/licenses/MIT
27
+ *
28
+ * Unless required by applicable law or agreed to in writing, software
29
+ * distributed under the License is distributed on an "AS IS" BASIS,
30
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
+ * See the License for the specific language governing permissions and
32
+ * limitations under the License.
33
+ */
34
+ const logger_1 = require("@fonoster/logger");
35
+ const twilio_1 = __importDefault(require("twilio"));
36
+ const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
37
+ function createSendSmsTwilioImpl(config) {
38
+ const { sender: from, accountSid, authToken } = config;
39
+ const client = (0, twilio_1.default)(accountSid, authToken);
40
+ return function sendSms(params) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const { to, body } = params;
43
+ const result = yield client.messages.create({
44
+ body,
45
+ from,
46
+ to
47
+ });
48
+ logger.verbose("message sent", {
49
+ status: result.status,
50
+ messageId: result.sid
51
+ });
52
+ });
53
+ };
54
+ }
@@ -1,2 +1,4 @@
1
1
  export * from "./compileTemplate";
2
- export * from "./createEmailSender";
2
+ export * from "./createSendEmail";
3
+ export * from "./createSendSmsTwilioImpl";
4
+ export * from "./types";
@@ -33,4 +33,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  * limitations under the License.
34
34
  */
35
35
  __exportStar(require("./compileTemplate"), exports);
36
- __exportStar(require("./createEmailSender"), exports);
36
+ __exportStar(require("./createSendEmail"), exports);
37
+ __exportStar(require("./createSendSmsTwilioImpl"), exports);
38
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,27 @@
1
+ type EmailSenderConfig = {
2
+ sender: string;
3
+ host: string;
4
+ port: number;
5
+ secure: boolean;
6
+ auth: {
7
+ user: string;
8
+ pass: string;
9
+ };
10
+ };
11
+ type EmailParams = {
12
+ to: string;
13
+ subject: string;
14
+ html: string;
15
+ };
16
+ type SmsSenderConfig = {
17
+ sender: string;
18
+ };
19
+ type TwilioSmsSenderConfig = SmsSenderConfig & {
20
+ accountSid: string;
21
+ authToken: string;
22
+ };
23
+ type SmsParams = {
24
+ to: string;
25
+ body: string;
26
+ };
27
+ export { EmailParams, EmailSenderConfig, SmsParams, SmsSenderConfig, TwilioSmsSenderConfig };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -38,7 +38,9 @@ service Identity {
38
38
  rpc GetUser (GetUserRequest) returns (User) {}
39
39
  rpc UpdateUser (UpdateUserRequest) returns (UpdateUserResponse) {}
40
40
  rpc DeleteUser (DeleteUserRequest) returns (DeleteUserResponse) {}
41
-
41
+ rpc SendVerificationCode (SendVerificationCodeRequest) returns (google.protobuf.Empty) {}
42
+ rpc VerifyCode (VerifyCodeRequest) returns (google.protobuf.Empty) {}
43
+
42
44
  // ApiKey actions
43
45
  rpc CreateApiKey (CreateApiKeyRequest) returns (CreateApiKeyResponse) {}
44
46
  rpc DeleteApiKey (DeleteApiKeyRequest) returns (DeleteApiKeyResponse) {}
@@ -48,7 +50,7 @@ service Identity {
48
50
  // Token exchange actions
49
51
  rpc ExchangeCredentials (ExchangeCredentialsRequest) returns (ExchangeCredentialsResponse) {}
50
52
  rpc ExchangeApiKey (ExchangeApiKeyRequest) returns (ExchangeApiKeyResponse) {}
51
- rpc ExchangeOAuth2Code (ExchangeOAuth2CodeRequest) returns (ExchangeOAuth2CodeResponse) {}
53
+ rpc ExchangeOauth2Code (ExchangeOauth2CodeRequest) returns (ExchangeOauth2CodeResponse) {}
52
54
  rpc ExchangeRefreshToken (ExchangeRefreshTokenRequest) returns (ExchangeRefreshTokenResponse) {}
53
55
  rpc RevokeToken (RevokeTokenRequest) returns (RevokeTokenResponse) {}
54
56
 
@@ -58,6 +60,14 @@ service Identity {
58
60
 
59
61
  // Workspace Resources
60
62
 
63
+ message Workspace {
64
+ string ref = 1;
65
+ string name = 2;
66
+ string owner_ref = 3;
67
+ int32 created_at = 4;
68
+ int32 updated_at = 5;
69
+ }
70
+
61
71
  message CreateWorkspaceRequest {
62
72
  string name = 1;
63
73
  }
@@ -124,6 +134,10 @@ message ResendWorkspaceMembershipInvitationResponse {
124
134
  }
125
135
 
126
136
  // User Resources
137
+ enum ContactType {
138
+ EMAIL = 0;
139
+ PHONE = 1;
140
+ }
127
141
 
128
142
  message CreateUserRequest {
129
143
  string email = 1;
@@ -168,12 +182,16 @@ message DeleteUserResponse {
168
182
  string ref = 1;
169
183
  }
170
184
 
171
- message Workspace {
172
- string ref = 1;
173
- string name = 2;
174
- string owner_ref = 3;
175
- int32 created_at = 4;
176
- int32 updated_at = 5;
185
+ message SendVerificationCodeRequest {
186
+ ContactType contact_type = 1;
187
+ string value = 2;
188
+ }
189
+
190
+ message VerifyCodeRequest {
191
+ string username = 1;
192
+ ContactType contact_type = 2;
193
+ string value = 3;
194
+ string verification_code = 4;
177
195
  }
178
196
 
179
197
  // ApiKey Resources
@@ -232,7 +250,7 @@ message ExchangeCredentialsRequest {
232
250
  string username = 1;
233
251
  string password = 2;
234
252
  // Optional code for multi-factor authentication
235
- string ephemeral_code = 3;
253
+ string verification_code = 3;
236
254
  }
237
255
 
238
256
  message ExchangeCredentialsResponse {
@@ -252,11 +270,16 @@ message ExchangeApiKeyResponse {
252
270
  string refresh_token = 3;
253
271
  }
254
272
 
255
- message ExchangeOAuth2CodeRequest {
256
- string code = 1;
273
+ message ExchangeOauth2CodeRequest {
274
+ enum Oauth2Provider {
275
+ GITHUB = 0;
276
+ }
277
+ Oauth2Provider provider = 1;
278
+ string username = 2;
279
+ string code = 3;
257
280
  }
258
281
 
259
- message ExchangeOAuth2CodeResponse {
282
+ message ExchangeOauth2CodeResponse {
260
283
  string id_token = 1;
261
284
  string access_token = 2;
262
285
  string refresh_token = 3;
@@ -49,6 +49,7 @@ const loadOptions = {
49
49
  longs: String,
50
50
  enums: String,
51
51
  defaults: false,
52
+ arrays: true,
52
53
  oneofs: true
53
54
  };
54
55
  function createServiceDefinition(params) {
@@ -6,15 +6,15 @@ declare const createCallRequestSchema: z.ZodObject<{
6
6
  appRef: z.ZodString;
7
7
  timeout: z.ZodOptional<z.ZodNumber>;
8
8
  }, "strip", z.ZodTypeAny, {
9
- timeout?: number;
10
- from?: string;
11
9
  to?: string;
10
+ from?: string;
12
11
  appRef?: string;
13
- }, {
14
12
  timeout?: number;
15
- from?: string;
13
+ }, {
16
14
  to?: string;
15
+ from?: string;
17
16
  appRef?: string;
17
+ timeout?: number;
18
18
  }>;
19
19
  declare const getCallRequestSchema: z.ZodObject<{
20
20
  ref: z.ZodString;
@@ -21,27 +21,33 @@ exports.listCallsRequestSchema = exports.getCallRequestSchema = exports.createCa
21
21
  */
22
22
  const types_1 = require("@fonoster/types");
23
23
  const zod_1 = require("zod");
24
+ const messages_1 = require("../messages");
24
25
  const createCallRequestSchema = zod_1.z.object({
25
26
  from: zod_1.z.string(),
26
27
  to: zod_1.z.string(),
27
- appRef: zod_1.z.string().uuid("Invalid call reference"),
28
- timeout: zod_1.z.number().max(120, "Timeout must be less than 120s").optional()
28
+ appRef: zod_1.z.string().uuid({ message: "Invalid call reference" }),
29
+ timeout: zod_1.z
30
+ .number()
31
+ .max(120, { message: "Timeout must be less than 120s" })
32
+ .optional()
29
33
  });
30
34
  exports.createCallRequestSchema = createCallRequestSchema;
31
35
  const getCallRequestSchema = zod_1.z.object({
32
- ref: zod_1.z.string().uuid("Invalid call reference")
36
+ ref: zod_1.z.string().uuid({ message: "Invalid call reference" })
33
37
  });
34
38
  exports.getCallRequestSchema = getCallRequestSchema;
35
39
  const listCallsRequestSchema = zod_1.z.object({
36
- after: zod_1.z
37
- .string()
38
- .datetime({ offset: true, message: "The date must be a valid ISO 8601" })
39
- .optional(),
40
- before: zod_1.z
41
- .string()
42
- .datetime({ offset: true, message: "The date must be a valid ISO 8601" })
40
+ after: zod_1.z.string().datetime({ offset: true, message: messages_1.VALID_DATE }).optional(),
41
+ before: zod_1.z.string().datetime({ offset: true, message: messages_1.VALID_DATE }).optional(),
42
+ pageSize: zod_1.z
43
+ .number()
44
+ .int({
45
+ message: messages_1.POSITIVE_INTEGER_MESSAGE
46
+ })
47
+ .positive({
48
+ message: messages_1.POSITIVE_INTEGER_MESSAGE
49
+ })
43
50
  .optional(),
44
- pageSize: zod_1.z.number({ message: "Invalid pageSize value" }).optional(),
45
51
  type: zod_1.z
46
52
  .nativeEnum(types_1.CallType, {
47
53
  message: "Invalid call type"
@@ -50,6 +56,6 @@ const listCallsRequestSchema = zod_1.z.object({
50
56
  status: zod_1.z
51
57
  .nativeEnum(types_1.CallStatus, { message: "Invalid call status" })
52
58
  .optional(),
53
- pageToken: zod_1.z.string({ message: "The pageToken must be a string" }).optional()
59
+ pageToken: zod_1.z.string().optional()
54
60
  });
55
61
  exports.listCallsRequestSchema = listCallsRequestSchema;
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ declare const usernameSchema: z.ZodString;
2
3
  declare const baseApiObjectSchema: z.ZodObject<{
3
4
  ref: z.ZodString;
4
5
  }, "strip", z.ZodTypeAny, {
@@ -6,6 +7,7 @@ declare const baseApiObjectSchema: z.ZodObject<{
6
7
  }, {
7
8
  ref?: string;
8
9
  }>;
10
+ declare const emptySchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
9
11
  declare const listRequestSchema: z.ZodOptional<z.ZodObject<{
10
12
  pageSize: z.ZodOptional<z.ZodNumber>;
11
13
  pageToken: z.ZodOptional<z.ZodString>;
@@ -16,4 +18,5 @@ declare const listRequestSchema: z.ZodOptional<z.ZodObject<{
16
18
  pageSize?: number;
17
19
  pageToken?: string;
18
20
  }>>;
19
- export { baseApiObjectSchema, listRequestSchema };
21
+ declare const nameSchema: z.ZodString;
22
+ export { baseApiObjectSchema, emptySchema, listRequestSchema, nameSchema, usernameSchema };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listRequestSchema = exports.baseApiObjectSchema = void 0;
3
+ exports.usernameSchema = exports.nameSchema = exports.listRequestSchema = exports.emptySchema = exports.baseApiObjectSchema = void 0;
4
4
  /*
5
5
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/fonoster
@@ -20,14 +20,33 @@ exports.listRequestSchema = exports.baseApiObjectSchema = void 0;
20
20
  * limitations under the License.
21
21
  */
22
22
  const zod_1 = require("zod");
23
+ const messages_1 = require("../messages");
24
+ const usernameSchema = zod_1.z.string().regex(/^[a-z0-9._-]+$/, {
25
+ message: "Must be a lowercase string and with no spaces."
26
+ });
27
+ exports.usernameSchema = usernameSchema;
23
28
  const baseApiObjectSchema = zod_1.z.object({
24
- ref: zod_1.z.string()
29
+ ref: zod_1.z.string().uuid({
30
+ message: messages_1.VALID_UUID
31
+ })
25
32
  });
26
33
  exports.baseApiObjectSchema = baseApiObjectSchema;
34
+ const emptySchema = zod_1.z.object({});
35
+ exports.emptySchema = emptySchema;
27
36
  const listRequestSchema = zod_1.z
28
37
  .object({
29
- pageSize: zod_1.z.number().optional(),
38
+ pageSize: zod_1.z
39
+ .number()
40
+ .int({
41
+ message: messages_1.POSITIVE_INTEGER_MESSAGE
42
+ })
43
+ .positive({
44
+ message: messages_1.POSITIVE_INTEGER_MESSAGE
45
+ })
46
+ .optional(),
30
47
  pageToken: zod_1.z.string().optional()
31
48
  })
32
49
  .optional();
33
50
  exports.listRequestSchema = listRequestSchema;
51
+ const nameSchema = zod_1.z.string().min(1, { message: "Value required" });
52
+ exports.nameSchema = nameSchema;
@@ -28,6 +28,6 @@ const hostOrHostPortSchema = zod_1.z
28
28
  const hostPortRegex = /^(?!:\/\/)([a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)*|(\d{1,3}\.){3}\d{1,3}):\d{1,5}$/;
29
29
  return hostRegex.test(value) || hostPortRegex.test(value);
30
30
  }, {
31
- message: "Invalid format. Expected 'host' or 'host:port'"
31
+ message: "Invalid format. Expects 'host' or 'host:port'"
32
32
  });
33
33
  exports.hostOrHostPortSchema = hostOrHostPortSchema;
@@ -9,7 +9,7 @@ declare const createWorkspaceRequestSchema: z.ZodObject<{
9
9
  }>;
10
10
  declare const createApiKeyRequestSchema: z.ZodObject<{
11
11
  role: z.ZodEnum<[ApiRoleEnum]>;
12
- expiresAt: z.ZodOptional<z.ZodEffects<z.ZodNumber, number, number>>;
12
+ expiresAt: z.ZodOptional<z.ZodNumber>;
13
13
  }, "strip", z.ZodTypeAny, {
14
14
  role?: ApiRoleEnum;
15
15
  expiresAt?: number;
@@ -30,12 +30,28 @@ declare const exchangeApiKeysRequestSchema: z.ZodObject<{
30
30
  declare const exchangeCredentialsRequestSchema: z.ZodObject<{
31
31
  username: z.ZodString;
32
32
  password: z.ZodString;
33
+ verificationCode: z.ZodOptional<z.ZodString>;
33
34
  }, "strip", z.ZodTypeAny, {
34
35
  username?: string;
35
36
  password?: string;
37
+ verificationCode?: string;
36
38
  }, {
37
39
  username?: string;
38
40
  password?: string;
41
+ verificationCode?: string;
42
+ }>;
43
+ declare const exchangeOauth2RequestSchema: z.ZodObject<{
44
+ provider: z.ZodDefault<z.ZodEnum<["GITHUB"]>>;
45
+ username: z.ZodString;
46
+ code: z.ZodString;
47
+ }, "strip", z.ZodTypeAny, {
48
+ code?: string;
49
+ username?: string;
50
+ provider?: "GITHUB";
51
+ }, {
52
+ code?: string;
53
+ username?: string;
54
+ provider?: "GITHUB";
39
55
  }>;
40
56
  declare const exchangeRefreshTokenRequestSchema: z.ZodObject<{
41
57
  refreshToken: z.ZodString;
@@ -51,13 +67,13 @@ declare const createUserRequestSchema: z.ZodObject<{
51
67
  avatar: z.ZodString;
52
68
  }, "strip", z.ZodTypeAny, {
53
69
  name?: string;
54
- email?: string;
55
70
  password?: string;
71
+ email?: string;
56
72
  avatar?: string;
57
73
  }, {
58
74
  name?: string;
59
- email?: string;
60
75
  password?: string;
76
+ email?: string;
61
77
  avatar?: string;
62
78
  }>;
63
79
  declare const updateUserRequestSchema: z.ZodObject<{
@@ -83,14 +99,14 @@ declare const inviteUserToWorkspaceRequestSchema: z.ZodObject<{
83
99
  password: z.ZodUnion<[z.ZodString, z.ZodUndefined]>;
84
100
  }, "strip", z.ZodTypeAny, {
85
101
  name?: string;
86
- email?: string;
87
102
  role?: WorkspaceRoleEnum.ADMIN | WorkspaceRoleEnum.USER;
88
103
  password?: string;
104
+ email?: string;
89
105
  }, {
90
106
  name?: string;
91
- email?: string;
92
107
  role?: WorkspaceRoleEnum.ADMIN | WorkspaceRoleEnum.USER;
93
108
  password?: string;
109
+ email?: string;
94
110
  }>;
95
111
  declare const resendWorkspaceMembershipInvitationRequestSchema: z.ZodObject<{
96
112
  userRef: z.ZodString;
@@ -116,4 +132,30 @@ declare const removeUserFromWorkspaceRequestSchema: z.ZodObject<{
116
132
  }, {
117
133
  userRef?: string;
118
134
  }>;
119
- export { createApiKeyRequestSchema, createUserRequestSchema, createWorkspaceRequestSchema, exchangeApiKeysRequestSchema, exchangeCredentialsRequestSchema, exchangeRefreshTokenRequestSchema, inviteUserToWorkspaceRequestSchema, removeUserFromWorkspaceRequestSchema, resendWorkspaceMembershipInvitationRequestSchema, updateUserRequestSchema, updateWorkspaceRequestSchema };
135
+ declare const sendVerificationCodeRequestSchema: z.ZodObject<{
136
+ contactType: z.ZodDefault<z.ZodEnum<["EMAIL", "PHONE"]>>;
137
+ value: z.ZodString;
138
+ }, "strip", z.ZodTypeAny, {
139
+ value?: string;
140
+ contactType?: "EMAIL" | "PHONE";
141
+ }, {
142
+ value?: string;
143
+ contactType?: "EMAIL" | "PHONE";
144
+ }>;
145
+ declare const verifyCodeRequestSchema: z.ZodObject<{
146
+ username: z.ZodString;
147
+ contactType: z.ZodDefault<z.ZodEnum<["EMAIL", "PHONE"]>>;
148
+ value: z.ZodString;
149
+ verificationCode: z.ZodString;
150
+ }, "strip", z.ZodTypeAny, {
151
+ value?: string;
152
+ username?: string;
153
+ verificationCode?: string;
154
+ contactType?: "EMAIL" | "PHONE";
155
+ }, {
156
+ value?: string;
157
+ username?: string;
158
+ verificationCode?: string;
159
+ contactType?: "EMAIL" | "PHONE";
160
+ }>;
161
+ export { createApiKeyRequestSchema, createUserRequestSchema, createWorkspaceRequestSchema, exchangeApiKeysRequestSchema, exchangeCredentialsRequestSchema, exchangeOauth2RequestSchema, exchangeRefreshTokenRequestSchema, inviteUserToWorkspaceRequestSchema, removeUserFromWorkspaceRequestSchema, resendWorkspaceMembershipInvitationRequestSchema, sendVerificationCodeRequestSchema, updateUserRequestSchema, updateWorkspaceRequestSchema, verifyCodeRequestSchema };