@fonoster/identity 0.7.5 → 0.7.9

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 (42) hide show
  1. package/dist/apikeys/createApiKey.d.ts +1 -1
  2. package/dist/apikeys/createApiKey.js +6 -14
  3. package/dist/apikeys/deleteApiKey.d.ts +1 -1
  4. package/dist/apikeys/deleteApiKey.js +5 -11
  5. package/dist/apikeys/listApiKeys.d.ts +1 -1
  6. package/dist/apikeys/listApiKeys.js +1 -1
  7. package/dist/apikeys/regenerateApiKey.d.ts +1 -1
  8. package/dist/apikeys/regenerateApiKey.js +1 -5
  9. package/dist/exchanges/exchangeApiKey.d.ts +1 -1
  10. package/dist/exchanges/exchangeApiKey.js +5 -11
  11. package/dist/exchanges/exchangeCredentials.d.ts +1 -1
  12. package/dist/exchanges/exchangeCredentials.js +5 -11
  13. package/dist/exchanges/exchangeRefreshToken.d.ts +1 -1
  14. package/dist/exchanges/exchangeRefreshToken.js +1 -5
  15. package/dist/exchanges/types.d.ts +11 -1
  16. package/dist/users/createUser.d.ts +1 -1
  17. package/dist/users/createUser.js +3 -11
  18. package/dist/users/deleteUser.d.ts +1 -1
  19. package/dist/users/deleteUser.js +1 -1
  20. package/dist/users/getUser.d.ts +1 -1
  21. package/dist/users/getUser.js +1 -1
  22. package/dist/users/updateUser.d.ts +1 -1
  23. package/dist/users/updateUser.js +1 -8
  24. package/dist/utils/getApiKeyByAccessKeyId.d.ts +3 -3
  25. package/dist/utils/getUserByEmail.d.ts +2 -2
  26. package/dist/workspaces/createWorkspace.d.ts +1 -1
  27. package/dist/workspaces/createWorkspace.js +5 -9
  28. package/dist/workspaces/deleteWorkspace.d.ts +1 -1
  29. package/dist/workspaces/deleteWorkspace.js +1 -1
  30. package/dist/workspaces/getWorkspace.d.ts +1 -1
  31. package/dist/workspaces/getWorkspace.js +1 -1
  32. package/dist/workspaces/inviteUserToWorkspace.d.ts +1 -1
  33. package/dist/workspaces/inviteUserToWorkspace.js +1 -11
  34. package/dist/workspaces/listWorkspaces.d.ts +1 -1
  35. package/dist/workspaces/listWorkspaces.js +1 -1
  36. package/dist/workspaces/removeUserFromWorkspace.d.ts +1 -1
  37. package/dist/workspaces/removeUserFromWorkspace.js +1 -1
  38. package/dist/workspaces/resendWorkspaceMembershipInvitation.d.ts +1 -1
  39. package/dist/workspaces/resendWorkspaceMembershipInvitation.js +1 -1
  40. package/dist/workspaces/updateWorkspace.d.ts +1 -1
  41. package/dist/workspaces/updateWorkspace.js +1 -6
  42. package/package.json +5 -5
@@ -3,5 +3,5 @@ import { CreateApiKeyRequest, CreateApiKeyResponse } from "@fonoster/types";
3
3
  import { Prisma } from "../db";
4
4
  declare function createApiKey(prisma: Prisma): (call: {
5
5
  request: unknown;
6
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
7
  export { CreateApiKeyRequest, CreateApiKeyResponse, createApiKey };
@@ -30,32 +30,24 @@ exports.createApiKey = createApiKey;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
- const types_1 = require("@fonoster/types");
34
- const zod_1 = require("zod");
35
33
  const utils_1 = require("../utils");
36
34
  const generateAccessKeyId_1 = require("../utils/generateAccessKeyId");
37
35
  const generateAccessKeySecret_1 = require("../utils/generateAccessKeySecret");
38
36
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
39
- const createApiKeyRequestSchema = zod_1.z.object({
40
- role: zod_1.z.enum([types_1.ApiRoleEnum.WORKSPACE_ADMIN]),
41
- expiresAt: zod_1.z
42
- .number()
43
- .transform((value) => (value === 0 ? null : value))
44
- .optional()
45
- });
46
37
  function createApiKey(prisma) {
47
38
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
48
- const validatedRequest = createApiKeyRequestSchema.parse(call.request);
49
39
  const accessKeyId = (0, utils_1.getAccessKeyIdFromCall)(call);
50
- const { role, expiresAt } = validatedRequest;
40
+ const { request } = call;
41
+ const { role, expiresAt } = request;
51
42
  logger.info("creating new ApiKey", { accessKeyId, role, expiresAt });
52
43
  const workspace = yield prisma.workspace.findUnique({
53
44
  where: { accessKeyId }
54
45
  });
46
+ const { ref } = workspace;
55
47
  const response = yield prisma.apiKey.create({
56
48
  data: {
57
- workspaceRef: workspace.ref,
58
- role: validatedRequest.role,
49
+ workspaceRef: ref,
50
+ role,
59
51
  accessKeyId: (0, generateAccessKeyId_1.generateAccessKeyId)(generateAccessKeyId_1.AccessKeyIdType.API_KEY),
60
52
  accessKeySecret: (0, generateAccessKeySecret_1.generateAccessKeySecret)(),
61
53
  expiresAt: expiresAt ? new Date(expiresAt) : null
@@ -67,5 +59,5 @@ function createApiKey(prisma) {
67
59
  accessKeySecret: response.accessKeySecret
68
60
  });
69
61
  });
70
- return (0, common_1.withErrorHandling)(fn);
62
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.createApiKeyRequestSchema);
71
63
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function deleteApiKey(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { deleteApiKey };
@@ -30,24 +30,18 @@ exports.deleteApiKey = deleteApiKey;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
- const zod_1 = require("zod");
34
33
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
35
- const deleteApiKeyRequestSchema = zod_1.z.object({
36
- ref: zod_1.z.string()
37
- });
38
34
  function deleteApiKey(prisma) {
39
35
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
40
- const validatedRequest = deleteApiKeyRequestSchema.parse(call.request);
41
- const { ref } = validatedRequest;
36
+ const { request } = call;
37
+ const { ref } = request;
42
38
  logger.info("deleting ApiKey", { ref });
43
- const response = yield prisma.apiKey.delete({
39
+ yield prisma.apiKey.delete({
44
40
  where: {
45
41
  ref
46
42
  }
47
43
  });
48
- callback(null, {
49
- ref: response.ref
50
- });
44
+ callback(null, { ref });
51
45
  });
52
- return (0, common_1.withErrorHandling)(fn);
46
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
53
47
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function listApiKeys(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { listApiKeys };
@@ -58,5 +58,5 @@ function listApiKeys(prisma) {
58
58
  };
59
59
  callback(null, response);
60
60
  });
61
- return (0, common_1.withErrorHandling)(fn);
61
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.listRequestSchema);
62
62
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function regenerateApiKey(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { regenerateApiKey };
@@ -30,12 +30,8 @@ exports.regenerateApiKey = regenerateApiKey;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
- const zod_1 = require("zod");
34
33
  const generateAccessKeySecret_1 = require("../utils/generateAccessKeySecret");
35
34
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
36
- const regenerateApiKeyRequestSchema = zod_1.z.object({
37
- ref: zod_1.z.string()
38
- });
39
35
  function regenerateApiKey(prisma) {
40
36
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
41
37
  const { request } = call;
@@ -55,5 +51,5 @@ function regenerateApiKey(prisma) {
55
51
  accessKeySecret: response.accessKeySecret
56
52
  });
57
53
  });
58
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, regenerateApiKeyRequestSchema));
54
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
59
55
  }
@@ -3,5 +3,5 @@ import { IdentityConfig } from "./types";
3
3
  import { Prisma } from "../db";
4
4
  declare function exchangeApiKey(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
5
  request: unknown;
6
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
7
  export { exchangeApiKey };
@@ -54,18 +54,9 @@ exports.exchangeApiKey = exchangeApiKey;
54
54
  const common_1 = require("@fonoster/common");
55
55
  const logger_1 = require("@fonoster/logger");
56
56
  const grpc = __importStar(require("@grpc/grpc-js"));
57
- const zod_1 = require("zod");
58
57
  const exchangeTokens_1 = require("./exchangeTokens");
59
58
  const getApiKeyByAccessKeyId_1 = require("../utils/getApiKeyByAccessKeyId");
60
59
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
61
- const exchangeApiKeysRequestSchema = zod_1.z.object({
62
- accessKeyId: zod_1.z.string(),
63
- accessKeySecret: zod_1.z.string()
64
- });
65
- const invalidApiKeyError = {
66
- code: grpc.status.PERMISSION_DENIED,
67
- message: "Invalid credentials"
68
- };
69
60
  function exchangeApiKey(prisma, identityConfig) {
70
61
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
71
62
  const { request } = call;
@@ -73,9 +64,12 @@ function exchangeApiKey(prisma, identityConfig) {
73
64
  logger.verbose("call to exchangeApiKey", { accessKeyId });
74
65
  const key = yield (0, getApiKeyByAccessKeyId_1.getApiKeyByAccessKeyId)(prisma)(accessKeyId);
75
66
  if ((key === null || key === void 0 ? void 0 : key.accessKeySecret) !== (accessKeySecret === null || accessKeySecret === void 0 ? void 0 : accessKeySecret.trim())) {
76
- return callback(invalidApiKeyError);
67
+ return callback({
68
+ code: grpc.status.PERMISSION_DENIED,
69
+ message: "Invalid credentials"
70
+ });
77
71
  }
78
72
  callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(accessKeyId));
79
73
  });
80
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, exchangeApiKeysRequestSchema));
74
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.exchangeApiKeysRequestSchema);
81
75
  }
@@ -3,5 +3,5 @@ import { IdentityConfig } from "./types";
3
3
  import { Prisma } from "../db";
4
4
  declare function exchangeCredentials(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
5
  request: unknown;
6
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
7
  export { exchangeCredentials };
@@ -54,18 +54,9 @@ exports.exchangeCredentials = exchangeCredentials;
54
54
  const common_1 = require("@fonoster/common");
55
55
  const logger_1 = require("@fonoster/logger");
56
56
  const grpc = __importStar(require("@grpc/grpc-js"));
57
- const zod_1 = require("zod");
58
57
  const exchangeTokens_1 = require("./exchangeTokens");
59
58
  const getUserByEmail_1 = require("../utils/getUserByEmail");
60
59
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
61
- const exchangeCredentialsRequestSchema = zod_1.z.object({
62
- username: zod_1.z.string(),
63
- password: zod_1.z.string()
64
- });
65
- const invalidCredentialsError = {
66
- code: grpc.status.PERMISSION_DENIED,
67
- message: "Invalid credentials"
68
- };
69
60
  function exchangeCredentials(prisma, identityConfig) {
70
61
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
71
62
  const { request } = call;
@@ -73,9 +64,12 @@ function exchangeCredentials(prisma, identityConfig) {
73
64
  logger.verbose("call to exchangeCredentials", { username });
74
65
  const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(username);
75
66
  if (!user || user.password !== (password === null || password === void 0 ? void 0 : password.trim())) {
76
- return callback(invalidCredentialsError);
67
+ return callback({
68
+ code: grpc.status.PERMISSION_DENIED,
69
+ message: "Invalid credentials"
70
+ });
77
71
  }
78
72
  callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
79
73
  });
80
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, exchangeCredentialsRequestSchema));
74
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeCredentialsRequestSchema);
81
75
  }
@@ -3,5 +3,5 @@ import { IdentityConfig } from "./types";
3
3
  import { Prisma } from "../db";
4
4
  declare function exchangeRefreshToken(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
5
  request: unknown;
6
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
7
  export { exchangeRefreshToken };
@@ -34,12 +34,8 @@ exports.exchangeRefreshToken = exchangeRefreshToken;
34
34
  const common_1 = require("@fonoster/common");
35
35
  const logger_1 = require("@fonoster/logger");
36
36
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
37
- const zod_1 = require("zod");
38
37
  const exchangeTokens_1 = require("./exchangeTokens");
39
38
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
40
- const exchangeRefreshTokenRequestSchema = zod_1.z.object({
41
- refreshToken: zod_1.z.string()
42
- });
43
39
  const SIGN_ALGORITHM = "RS256";
44
40
  function exchangeRefreshToken(prisma, identityConfig) {
45
41
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
@@ -53,5 +49,5 @@ function exchangeRefreshToken(prisma, identityConfig) {
53
49
  logger.verbose("call to exchangeRefreshToken", { accessKeyId });
54
50
  callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(accessKeyId));
55
51
  });
56
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, exchangeRefreshTokenRequestSchema));
52
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeRefreshTokenRequestSchema);
57
53
  }
@@ -1,4 +1,6 @@
1
+ import { Validators as V } from "@fonoster/common";
1
2
  import { WorkspaceRoleEnum } from "@fonoster/types";
3
+ import { z } from "zod";
2
4
  import { TokenUseEnum } from "./TokenUseEnum";
3
5
  type Role = {
4
6
  name: string;
@@ -53,4 +55,12 @@ type IdentityConfig = {
53
55
  };
54
56
  };
55
57
  type DecodedToken<T extends TokenUseEnum> = T extends TokenUseEnum.ID ? IdToken : T extends TokenUseEnum.ACCESS ? AccessToken : T extends TokenUseEnum.REFRESH ? TokenUseEnum : never;
56
- export { Access, AccessToken, DecodedToken, IdToken, IdentityConfig, RefreshToken, Role };
58
+ type ExchangeApiKeysRequest = z.infer<typeof V.exchangeApiKeysRequestSchema>;
59
+ type ExchangeCredentialsRequest = z.infer<typeof V.exchangeCredentialsRequestSchema>;
60
+ type ExchangeResponse = {
61
+ idToken: string;
62
+ accessToken: string;
63
+ refreshToken: string;
64
+ };
65
+ type ExchangeRefreshTokenRequest = z.infer<typeof V.exchangeRefreshTokenRequestSchema>;
66
+ export { Access, AccessToken, DecodedToken, ExchangeApiKeysRequest, ExchangeCredentialsRequest, ExchangeRefreshTokenRequest, ExchangeResponse, IdToken, IdentityConfig, RefreshToken, Role };
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function createUser(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { createUser };
@@ -30,15 +30,8 @@ exports.createUser = createUser;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
- const zod_1 = require("zod");
34
33
  const generateAccessKeyId_1 = require("../utils/generateAccessKeyId");
35
34
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
36
- const createUserRequestSchema = zod_1.z.object({
37
- name: zod_1.z.string().min(3, "Name must contain at least 3 characters").max(50),
38
- email: zod_1.z.string().email(),
39
- password: zod_1.z.string().min(8).max(100),
40
- avatar: zod_1.z.string().url()
41
- });
42
35
  function createUser(prisma) {
43
36
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
44
37
  const { request } = call;
@@ -53,9 +46,8 @@ function createUser(prisma) {
53
46
  avatar
54
47
  }
55
48
  });
56
- callback(null, {
57
- ref: user.ref
58
- });
49
+ const { ref } = user;
50
+ callback(null, { ref });
59
51
  });
60
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, createUserRequestSchema));
52
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.createUserRequestSchema);
61
53
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function deleteUser(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { deleteUser };
@@ -48,5 +48,5 @@ function deleteUser(prisma) {
48
48
  });
49
49
  callback(null, { ref });
50
50
  });
51
- return (0, common_1.withErrorHandling)(fn);
51
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
52
52
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function getUser(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { getUser };
@@ -59,5 +59,5 @@ function getUser(prisma) {
59
59
  }
60
60
  callback(null, (0, common_1.datesMapper)(user));
61
61
  });
62
- return (0, common_1.withErrorHandling)(fn);
62
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
63
63
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function updateUser(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { updateUser };
@@ -30,16 +30,9 @@ exports.updateUser = updateUser;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
- const zod_1 = require("zod");
34
33
  const utils_1 = require("../utils");
35
34
  const getTokenFromCall_1 = require("../utils/getTokenFromCall");
36
35
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
37
- const updateUserRequestSchema = zod_1.z.object({
38
- ref: zod_1.z.string(),
39
- name: zod_1.z.string().min(3).max(50).or(zod_1.z.string().optional().nullable()),
40
- password: zod_1.z.string().min(8).max(50).or(zod_1.z.string().optional().nullable()),
41
- avatar: zod_1.z.string().url().or(zod_1.z.string().optional().nullable())
42
- });
43
36
  function updateUser(prisma) {
44
37
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
45
38
  const { request } = call;
@@ -64,5 +57,5 @@ function updateUser(prisma) {
64
57
  };
65
58
  callback(null, response);
66
59
  });
67
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, updateUserRequestSchema));
60
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.updateUserRequestSchema);
68
61
  }
@@ -3,10 +3,10 @@ declare function getApiKeyByAccessKeyId(prisma: Prisma): (accessKeyId: string) =
3
3
  ref: string;
4
4
  createdAt: Date;
5
5
  updatedAt: Date;
6
- accessKeyId: string;
7
6
  role: "WORKSPACE_ADMIN";
8
- workspaceRef: string;
9
- accessKeySecret: string;
10
7
  expiresAt: Date;
8
+ accessKeyId: string;
9
+ accessKeySecret: string;
10
+ workspaceRef: string;
11
11
  }>;
12
12
  export { getApiKeyByAccessKeyId };
@@ -6,10 +6,10 @@ declare function getUserByEmail(prisma: Prisma): (email: string) => Promise<{
6
6
  createdAt: Date;
7
7
  updatedAt: Date;
8
8
  accessKeyId: string;
9
- emailVerified: boolean;
10
9
  password: string;
10
+ avatar: string;
11
+ emailVerified: boolean;
11
12
  phoneNumber: string;
12
13
  phoneNumberVerified: boolean;
13
- avatar: string;
14
14
  }>;
15
15
  export { getUserByEmail };
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function createWorkspace(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { createWorkspace };
@@ -30,31 +30,27 @@ exports.createWorkspace = createWorkspace;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
- const zod_1 = require("zod");
34
33
  const generateAccessKeyId_1 = require("../utils/generateAccessKeyId");
35
34
  const getTokenFromCall_1 = require("../utils/getTokenFromCall");
36
35
  const getUserRefFromToken_1 = require("../utils/getUserRefFromToken");
37
36
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
38
- const createWorkspaceRequestSchema = zod_1.z.object({
39
- name: zod_1.z.string().min(3, "Name must contain at least 3 characters").max(50)
40
- });
41
37
  function createWorkspace(prisma) {
42
38
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
43
39
  const { request } = call;
44
40
  const { name } = request;
45
41
  const token = (0, getTokenFromCall_1.getTokenFromCall)(call);
46
42
  const ownerRef = (0, getUserRefFromToken_1.getUserRefFromToken)(token);
43
+ const accessKeyId = (0, generateAccessKeyId_1.generateAccessKeyId)(generateAccessKeyId_1.AccessKeyIdType.WORKSPACE);
47
44
  logger.verbose("call to createWorkspace", { name, ownerRef });
48
45
  const workspace = yield prisma.workspace.create({
49
46
  data: {
50
47
  name,
51
- accessKeyId: (0, generateAccessKeyId_1.generateAccessKeyId)(generateAccessKeyId_1.AccessKeyIdType.WORKSPACE),
48
+ accessKeyId,
52
49
  ownerRef
53
50
  }
54
51
  });
55
- callback(null, {
56
- ref: workspace.ref
57
- });
52
+ const { ref } = workspace;
53
+ callback(null, { ref });
58
54
  });
59
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, createWorkspaceRequestSchema));
55
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.createWorkspaceRequestSchema);
60
56
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function deleteWorkspace(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { deleteWorkspace };
@@ -48,5 +48,5 @@ function deleteWorkspace(prisma) {
48
48
  });
49
49
  callback(null, { ref });
50
50
  });
51
- return (0, common_1.withErrorHandling)(fn);
51
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
52
52
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function getWorkspace(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { getWorkspace };
@@ -57,5 +57,5 @@ function getWorkspace(prisma) {
57
57
  const response = (0, common_1.datesMapper)(workspace);
58
58
  callback(null, response);
59
59
  });
60
- return (0, common_1.withErrorHandling)(fn);
60
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
61
61
  }
@@ -4,5 +4,5 @@ import { IdentityConfig } from "../exchanges/types";
4
4
  import { SendInvite } from "../invites/sendInvite";
5
5
  declare function inviteUserToWorkspace(prisma: Prisma, identityConfig: IdentityConfig, sendInvite: SendInvite): (call: {
6
6
  request: unknown;
7
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
8
8
  export { inviteUserToWorkspace };
@@ -33,7 +33,6 @@ const logger_1 = require("@fonoster/logger");
33
33
  const types_1 = require("@fonoster/types");
34
34
  const grpc_js_1 = require("@grpc/grpc-js");
35
35
  const nanoid_1 = require("nanoid");
36
- const zod_1 = require("zod");
37
36
  const createSendEmail_1 = require("./createSendEmail");
38
37
  const isAdminMember_1 = require("./isAdminMember");
39
38
  const isWorkspaceMember_1 = require("./isWorkspaceMember");
@@ -41,15 +40,6 @@ const utils_1 = require("../utils");
41
40
  const getTokenFromCall_1 = require("../utils/getTokenFromCall");
42
41
  const getUserRefFromToken_1 = require("../utils/getUserRefFromToken");
43
42
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
44
- const inviteUserToWorkspaceRequestSchema = zod_1.z.object({
45
- email: zod_1.z.string().email(),
46
- name: zod_1.z.string().min(3, "Name must contain at least 3 characters").max(50),
47
- role: zod_1.z.enum([types_1.WorkspaceRoleEnum.ADMIN, types_1.WorkspaceRoleEnum.USER]),
48
- password: zod_1.z
49
- .string()
50
- .min(6, "Password must contain at least 8 characters")
51
- .or(zod_1.z.undefined())
52
- });
53
43
  const userIsMemberError = {
54
44
  code: grpc_js_1.status.ALREADY_EXISTS,
55
45
  message: "User is already a member of this workspace"
@@ -140,5 +130,5 @@ function inviteUserToWorkspace(prisma, identityConfig, sendInvite) {
140
130
  workspaceRef
141
131
  });
142
132
  });
143
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, inviteUserToWorkspaceRequestSchema));
133
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.inviteUserToWorkspaceRequestSchema);
144
134
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function listWorkspaces(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { listWorkspaces };
@@ -71,5 +71,5 @@ function listWorkspaces(prisma) {
71
71
  nextPageToken: (_b = items[items.length - 1]) === null || _b === void 0 ? void 0 : _b.ref
72
72
  });
73
73
  });
74
- return (0, common_1.withErrorHandling)(fn);
74
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.listRequestSchema);
75
75
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function removeUserFromWorkspace(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { removeUserFromWorkspace };
@@ -76,5 +76,5 @@ function removeUserFromWorkspace(prisma) {
76
76
  });
77
77
  callback(null, response);
78
78
  });
79
- return (0, common_1.withErrorHandling)(fn);
79
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.removeUserFromWorkspaceRequestSchema);
80
80
  }
@@ -4,5 +4,5 @@ import { IdentityConfig } from "../exchanges/types";
4
4
  import { SendInvite } from "../invites/sendInvite";
5
5
  declare function resendWorkspaceMembershipInvitation(prisma: Prisma, identityConfig: IdentityConfig, sendInvite: SendInvite): (call: {
6
6
  request: unknown;
7
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
8
8
  export { resendWorkspaceMembershipInvitation };
@@ -90,5 +90,5 @@ function resendWorkspaceMembershipInvitation(prisma, identityConfig, sendInvite)
90
90
  userRef: inviteeRef
91
91
  });
92
92
  });
93
- return (0, common_1.withErrorHandling)(fn);
93
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.resendWorkspaceMembershipInvitationRequestSchema);
94
94
  }
@@ -2,5 +2,5 @@ import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { Prisma } from "../db";
3
3
  declare function updateWorkspace(prisma: Prisma): (call: {
4
4
  request: unknown;
5
- }, callback: (error?: GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
6
  export { updateWorkspace };
@@ -31,15 +31,10 @@ exports.updateWorkspace = updateWorkspace;
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
33
  const grpc_js_1 = require("@grpc/grpc-js");
34
- const zod_1 = require("zod");
35
34
  const isWorkspaceMember_1 = require("./isWorkspaceMember");
36
35
  const getTokenFromCall_1 = require("../utils/getTokenFromCall");
37
36
  const getUserRefFromToken_1 = require("../utils/getUserRefFromToken");
38
37
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
39
- const updateWorkspaceRequestSchema = zod_1.z.object({
40
- ref: zod_1.z.string(),
41
- name: zod_1.z.string().min(3).max(50).or(zod_1.z.string().optional().nullable())
42
- });
43
38
  function updateWorkspace(prisma) {
44
39
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
45
40
  const token = (0, getTokenFromCall_1.getTokenFromCall)(call);
@@ -64,5 +59,5 @@ function updateWorkspace(prisma) {
64
59
  });
65
60
  callback(null, { ref });
66
61
  });
67
- return (0, common_1.withErrorHandling)((0, common_1.withValidation)(fn, updateWorkspaceRequestSchema));
62
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.updateWorkspaceRequestSchema);
68
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/identity",
3
- "version": "0.7.5",
3
+ "version": "0.7.9",
4
4
  "description": "Identity service for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -20,9 +20,9 @@
20
20
  "fonoster": "./dist/index.js"
21
21
  },
22
22
  "dependencies": {
23
- "@fonoster/common": "^0.7.5",
24
- "@fonoster/logger": "^0.7.5",
25
- "@fonoster/types": "^0.7.5",
23
+ "@fonoster/common": "^0.7.9",
24
+ "@fonoster/logger": "^0.7.9",
25
+ "@fonoster/types": "^0.7.9",
26
26
  "@grpc/grpc-js": "~1.10.6",
27
27
  "@prisma/client": "^5.14.0",
28
28
  "jsonwebtoken": "^9.0.2",
@@ -47,5 +47,5 @@
47
47
  "devDependencies": {
48
48
  "@types/jsonwebtoken": "^9.0.6"
49
49
  },
50
- "gitHead": "cf28444503e4e698ccc001e061c7c918a4204757"
50
+ "gitHead": "3b16a5ed87b84d03534bb20de4d59d5bbb51a742"
51
51
  }