@fonoster/identity 0.8.24 → 0.8.26

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 (141) hide show
  1. package/dist/apikeys/{createApiKey.d.ts → createCreateApiKey.d.ts} +2 -2
  2. package/dist/apikeys/{createApiKey.js → createCreateApiKey.js} +5 -6
  3. package/dist/apikeys/createDeleteApiKey.d.ts +6 -0
  4. package/dist/apikeys/{deleteApiKey.js → createDeleteApiKey.js} +4 -4
  5. package/dist/apikeys/createListApiKeys.d.ts +6 -0
  6. package/dist/apikeys/{listApiKeys.js → createListApiKeys.js} +5 -6
  7. package/dist/apikeys/createRegenerateApiKey.d.ts +6 -0
  8. package/dist/apikeys/{regenerateApiKey.js → createRegenerateApiKey.js} +4 -4
  9. package/dist/apikeys/index.d.ts +4 -4
  10. package/dist/apikeys/index.js +4 -4
  11. package/dist/exchanges/{exchangeRefreshToken.d.ts → createExchangeApiKey.d.ts} +2 -2
  12. package/dist/exchanges/{exchangeApiKey.js → createExchangeApiKey.js} +6 -6
  13. package/dist/exchanges/{exchangeOauth2Code.d.ts → createExchangeCredentials.d.ts} +2 -2
  14. package/dist/exchanges/{exchangeCredentials.js → createExchangeCredentials.js} +6 -6
  15. package/dist/exchanges/{exchangeCredentials.d.ts → createExchangeOauth2Code.d.ts} +2 -2
  16. package/dist/exchanges/{exchangeOauth2Code.js → createExchangeOauth2Code.js} +6 -6
  17. package/dist/exchanges/{exchangeApiKey.d.ts → createExchangeRefreshToken.d.ts} +2 -2
  18. package/dist/exchanges/{exchangeRefreshToken.js → createExchangeRefreshToken.js} +4 -4
  19. package/dist/exchanges/exchangeTokens.js +5 -5
  20. package/dist/exchanges/index.d.ts +4 -5
  21. package/dist/exchanges/index.js +4 -5
  22. package/dist/exchanges/payloads/apikeys/createGetAccessTokenPayload.d.ts +5 -0
  23. package/dist/exchanges/payloads/apikeys/createGetAccessTokenPayload.js +46 -0
  24. package/dist/exchanges/payloads/apikeys/createGetRefreshTokenPayload.d.ts +5 -0
  25. package/dist/exchanges/payloads/apikeys/{getRefreshTokenPayload.js → createGetRefreshTokenPayload.js} +18 -16
  26. package/dist/exchanges/payloads/apikeys/index.d.ts +2 -2
  27. package/dist/exchanges/payloads/apikeys/index.js +2 -2
  28. package/dist/exchanges/payloads/buildRefreshTokenPayload.d.ts +2 -1
  29. package/dist/exchanges/payloads/buildRefreshTokenPayload.js +2 -2
  30. package/dist/exchanges/payloads/users/createGetAccessTokenPayload.d.ts +5 -0
  31. package/dist/exchanges/payloads/users/createGetAccessTokenPayload.js +75 -0
  32. package/dist/exchanges/payloads/users/createGetIdTokenPayload.d.ts +5 -0
  33. package/dist/exchanges/payloads/users/createGetIdTokenPayload.js +40 -0
  34. package/dist/exchanges/payloads/users/createGetRefreshTokenPayload.d.ts +5 -0
  35. package/dist/exchanges/payloads/users/{getRefreshTokenPayload.js → createGetRefreshTokenPayload.js} +22 -20
  36. package/dist/exchanges/payloads/users/index.d.ts +3 -3
  37. package/dist/exchanges/payloads/users/index.js +3 -3
  38. package/dist/exchanges/types.d.ts +1 -36
  39. package/dist/getPublicKey.d.ts +2 -2
  40. package/dist/getPublicKey.js +8 -6
  41. package/dist/index.d.ts +0 -2
  42. package/dist/index.js +0 -2
  43. package/dist/service.js +22 -22
  44. package/dist/{apikeys/listApiKeys.d.ts → users/createCreateUser.d.ts} +2 -2
  45. package/dist/users/{createUser.js → createCreateUser.js} +4 -4
  46. package/dist/users/{createUser.d.ts → createDeleteUser.d.ts} +2 -2
  47. package/dist/users/{deleteUser.js → createDeleteUser.js} +5 -6
  48. package/dist/{apikeys/deleteApiKey.d.ts → users/createGetUser.d.ts} +2 -2
  49. package/dist/users/{getUser.js → createGetUser.js} +5 -6
  50. package/dist/{apikeys/regenerateApiKey.d.ts → users/createUpdateUser.d.ts} +2 -2
  51. package/dist/users/{updateUser.js → createUpdateUser.js} +5 -6
  52. package/dist/users/index.d.ts +4 -4
  53. package/dist/users/index.js +4 -4
  54. package/dist/utils/createGenerateCallAccessToken.d.ts +6 -0
  55. package/dist/utils/{createCallAccessToken.js → createGenerateCallAccessToken.js} +29 -28
  56. package/dist/utils/{createWorkspaceInviteToken.d.ts → createGenerateWorkspaceInviteToken.d.ts} +2 -2
  57. package/dist/utils/{createWorkspaceInviteToken.js → createGenerateWorkspaceInviteToken.js} +21 -19
  58. package/dist/utils/createGetAccessKeyIdFromEmail.d.ts +3 -0
  59. package/dist/utils/{getAccessKeyIdFromEmail.js → createGetAccessKeyIdFromEmail.js} +8 -6
  60. package/dist/utils/{getApiKeyByAccessKeyId.d.ts → createGetApiKeyByAccessKeyId.d.ts} +5 -5
  61. package/dist/utils/{getApiKeyByAccessKeyId.js → createGetApiKeyByAccessKeyId.js} +13 -11
  62. package/dist/utils/{getUserByEmail.d.ts → createGetUserByEmail.d.ts} +2 -2
  63. package/dist/utils/{getUserByEmail.js → createGetUserByEmail.js} +10 -8
  64. package/dist/utils/createUpdateMembershipStatus.d.ts +3 -0
  65. package/dist/utils/{updateMembershipStatus.js → createUpdateMembershipStatus.js} +18 -16
  66. package/dist/utils/getAccessKeyIdFromToken.js +3 -4
  67. package/dist/utils/getUserRefFromToken.js +3 -4
  68. package/dist/utils/hasAccessToResource.js +3 -4
  69. package/dist/utils/index.d.ts +2 -8
  70. package/dist/utils/index.js +2 -8
  71. package/dist/verification/createVerifyCode.js +2 -2
  72. package/dist/workspaces/createCreateWorkspace.d.ts +6 -0
  73. package/dist/workspaces/{createWorkspace.js → createCreateWorkspace.js} +5 -6
  74. package/dist/workspaces/createDeleteWorkspace.d.ts +6 -0
  75. package/dist/workspaces/{deleteWorkspace.js → createDeleteWorkspace.js} +5 -6
  76. package/dist/workspaces/createGetWorkspace.d.ts +6 -0
  77. package/dist/workspaces/{getWorkspace.js → createGetWorkspace.js} +5 -6
  78. package/dist/workspaces/{inviteUserToWorkspace.d.ts → createInviteUserToWorkspace.d.ts} +2 -2
  79. package/dist/workspaces/{inviteUserToWorkspace.js → createInviteUserToWorkspace.js} +26 -25
  80. package/dist/workspaces/createIsAdminMember.d.ts +3 -0
  81. package/dist/workspaces/{isAdminMember.js → createIsAdminMember.js} +21 -19
  82. package/dist/workspaces/createIsWorkspaceMember.d.ts +3 -0
  83. package/dist/workspaces/createIsWorkspaceMember.js +33 -0
  84. package/dist/workspaces/createListWorkspaces.d.ts +6 -0
  85. package/dist/workspaces/{listWorkspaces.js → createListWorkspaces.js} +6 -8
  86. package/dist/workspaces/createRemoveUserFromWorkspace.d.ts +6 -0
  87. package/dist/workspaces/{removeUserFromWorkspace.js → createRemoveUserFromWorkspace.js} +8 -10
  88. package/dist/workspaces/{resendWorkspaceMembershipInvitation.d.ts → createResendWorkspaceMembershipInvitation.d.ts} +2 -2
  89. package/dist/workspaces/{resendWorkspaceMembershipInvitation.js → createResendWorkspaceMembershipInvitation.js} +10 -11
  90. package/dist/workspaces/createUpdateWorkspace.d.ts +6 -0
  91. package/dist/workspaces/{updateWorkspace.js → createUpdateWorkspace.js} +7 -8
  92. package/dist/workspaces/index.d.ts +8 -8
  93. package/dist/workspaces/index.js +8 -8
  94. package/package.json +5 -5
  95. package/dist/JsonWebErrorEnum.d.ts +0 -5
  96. package/dist/JsonWebErrorEnum.js +0 -26
  97. package/dist/createAuthInterceptor.d.ts +0 -15
  98. package/dist/createAuthInterceptor.js +0 -74
  99. package/dist/errors.d.ts +0 -4
  100. package/dist/errors.js +0 -35
  101. package/dist/exchanges/TokenUseEnum.d.ts +0 -6
  102. package/dist/exchanges/TokenUseEnum.js +0 -27
  103. package/dist/exchanges/payloads/apikeys/getAccessTokenPayload.d.ts +0 -4
  104. package/dist/exchanges/payloads/apikeys/getAccessTokenPayload.js +0 -44
  105. package/dist/exchanges/payloads/apikeys/getRefreshTokenPayload.d.ts +0 -4
  106. package/dist/exchanges/payloads/users/getAccessTokenPayload.d.ts +0 -4
  107. package/dist/exchanges/payloads/users/getAccessTokenPayload.js +0 -73
  108. package/dist/exchanges/payloads/users/getIdTokenPayload.d.ts +0 -4
  109. package/dist/exchanges/payloads/users/getIdTokenPayload.js +0 -38
  110. package/dist/exchanges/payloads/users/getRefreshTokenPayload.d.ts +0 -4
  111. package/dist/getPublicKeyClient.d.ts +0 -5
  112. package/dist/getPublicKeyClient.js +0 -71
  113. package/dist/roles.d.ts +0 -5
  114. package/dist/roles.js +0 -129
  115. package/dist/users/deleteUser.d.ts +0 -6
  116. package/dist/users/getUser.d.ts +0 -6
  117. package/dist/users/updateUser.d.ts +0 -6
  118. package/dist/utils/createCallAccessToken.d.ts +0 -6
  119. package/dist/utils/decodeToken.d.ts +0 -4
  120. package/dist/utils/decodeToken.js +0 -25
  121. package/dist/utils/getAccessKeyIdFromCall.d.ts +0 -3
  122. package/dist/utils/getAccessKeyIdFromCall.js +0 -8
  123. package/dist/utils/getAccessKeyIdFromEmail.d.ts +0 -3
  124. package/dist/utils/getTokenFromCall.d.ts +0 -3
  125. package/dist/utils/getTokenFromCall.js +0 -8
  126. package/dist/utils/hasAccess.d.ts +0 -3
  127. package/dist/utils/hasAccess.js +0 -9
  128. package/dist/utils/isValidToken.d.ts +0 -2
  129. package/dist/utils/isValidToken.js +0 -51
  130. package/dist/utils/tokenHasAccessKeyId.d.ts +0 -2
  131. package/dist/utils/tokenHasAccessKeyId.js +0 -28
  132. package/dist/utils/updateMembershipStatus.d.ts +0 -3
  133. package/dist/workspaces/createWorkspace.d.ts +0 -6
  134. package/dist/workspaces/deleteWorkspace.d.ts +0 -6
  135. package/dist/workspaces/getWorkspace.d.ts +0 -6
  136. package/dist/workspaces/isAdminMember.d.ts +0 -3
  137. package/dist/workspaces/isWorkspaceMember.d.ts +0 -3
  138. package/dist/workspaces/isWorkspaceMember.js +0 -31
  139. package/dist/workspaces/listWorkspaces.d.ts +0 -6
  140. package/dist/workspaces/removeUserFromWorkspace.d.ts +0 -6
  141. package/dist/workspaces/updateWorkspace.d.ts +0 -6
@@ -1,7 +1,7 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { CreateApiKeyRequest, CreateApiKeyResponse } from "@fonoster/types";
3
3
  import { Prisma } from "../db";
4
- declare function createApiKey(prisma: Prisma): (call: {
4
+ declare function createCreateApiKey(prisma: Prisma): (call: {
5
5
  request: unknown;
6
6
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
- export { CreateApiKeyRequest, CreateApiKeyResponse, createApiKey };
7
+ export { CreateApiKeyRequest, CreateApiKeyResponse, createCreateApiKey };
@@ -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.createApiKey = createApiKey;
12
+ exports.createCreateApiKey = createCreateApiKey;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -30,13 +30,12 @@ exports.createApiKey = createApiKey;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
- const utils_1 = require("../utils");
34
33
  const generateAccessKeyId_1 = require("../utils/generateAccessKeyId");
35
34
  const generateAccessKeySecret_1 = require("../utils/generateAccessKeySecret");
36
35
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
37
- function createApiKey(prisma) {
38
- const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
39
- const accessKeyId = (0, utils_1.getAccessKeyIdFromCall)(call);
36
+ function createCreateApiKey(prisma) {
37
+ const createApiKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
38
+ const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
40
39
  const { request } = call;
41
40
  const { role, expiresAt } = request;
42
41
  logger.info("creating new ApiKey", { accessKeyId, role, expiresAt });
@@ -59,5 +58,5 @@ function createApiKey(prisma) {
59
58
  accessKeySecret: response.accessKeySecret
60
59
  });
61
60
  });
62
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.createApiKeyRequestSchema);
61
+ return (0, common_1.withErrorHandlingAndValidation)(createApiKey, common_1.Validators.createApiKeyRequestSchema);
63
62
  }
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { Prisma } from "../db";
3
+ declare function createDeleteApiKey(prisma: Prisma): (call: {
4
+ request: unknown;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
+ export { createDeleteApiKey };
@@ -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.deleteApiKey = deleteApiKey;
12
+ exports.createDeleteApiKey = createDeleteApiKey;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -31,8 +31,8 @@ exports.deleteApiKey = deleteApiKey;
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
33
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
34
- function deleteApiKey(prisma) {
35
- const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
34
+ function createDeleteApiKey(prisma) {
35
+ const deleteApiKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
36
36
  const { request } = call;
37
37
  const { ref } = request;
38
38
  logger.info("deleting ApiKey", { ref });
@@ -43,5 +43,5 @@ function deleteApiKey(prisma) {
43
43
  });
44
44
  callback(null, { ref });
45
45
  });
46
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
46
+ return (0, common_1.withErrorHandlingAndValidation)(deleteApiKey, common_1.Validators.emptySchema);
47
47
  }
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { Prisma } from "../db";
3
+ declare function createListApiKeys(prisma: Prisma): (call: {
4
+ request: unknown;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
+ export { createListApiKeys };
@@ -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.listApiKeys = listApiKeys;
12
+ exports.createListApiKeys = createListApiKeys;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -30,13 +30,12 @@ exports.listApiKeys = listApiKeys;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
- const utils_1 = require("../utils");
34
33
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
35
- function listApiKeys(prisma) {
36
- const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
34
+ function createListApiKeys(prisma) {
35
+ const listApiKeys = (call, callback) => __awaiter(this, void 0, void 0, function* () {
37
36
  var _a;
38
37
  const { pageSize, pageToken } = call.request;
39
- const accessKeyId = (0, utils_1.getAccessKeyIdFromCall)(call);
38
+ const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
40
39
  logger.verbose("list keys for workspace", { accessKeyId });
41
40
  const workspace = yield prisma.workspace.findUnique({
42
41
  where: {
@@ -58,5 +57,5 @@ function listApiKeys(prisma) {
58
57
  };
59
58
  callback(null, response);
60
59
  });
61
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.listRequestSchema);
60
+ return (0, common_1.withErrorHandlingAndValidation)(listApiKeys, common_1.Validators.listRequestSchema);
62
61
  }
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { Prisma } from "../db";
3
+ declare function createRegenerateApiKey(prisma: Prisma): (call: {
4
+ request: unknown;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
+ export { createRegenerateApiKey };
@@ -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.regenerateApiKey = regenerateApiKey;
12
+ exports.createRegenerateApiKey = createRegenerateApiKey;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -32,8 +32,8 @@ const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
33
  const generateAccessKeySecret_1 = require("../utils/generateAccessKeySecret");
34
34
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
35
- function regenerateApiKey(prisma) {
36
- const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
35
+ function createRegenerateApiKey(prisma) {
36
+ const regenerateApiKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
37
37
  const { request } = call;
38
38
  const { ref } = request;
39
39
  logger.info("regenerating ApiKey", { ref });
@@ -51,5 +51,5 @@ function regenerateApiKey(prisma) {
51
51
  accessKeySecret: response.accessKeySecret
52
52
  });
53
53
  });
54
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
54
+ return (0, common_1.withErrorHandlingAndValidation)(regenerateApiKey, common_1.Validators.emptySchema);
55
55
  }
@@ -1,4 +1,4 @@
1
- export * from "./createApiKey";
2
- export * from "./deleteApiKey";
3
- export * from "./listApiKeys";
4
- export * from "./regenerateApiKey";
1
+ export * from "./createCreateApiKey";
2
+ export * from "./createDeleteApiKey";
3
+ export * from "./createListApiKeys";
4
+ export * from "./createRegenerateApiKey";
@@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  * See the License for the specific language governing permissions and
33
33
  * limitations under the License.
34
34
  */
35
- __exportStar(require("./createApiKey"), exports);
36
- __exportStar(require("./deleteApiKey"), exports);
37
- __exportStar(require("./listApiKeys"), exports);
38
- __exportStar(require("./regenerateApiKey"), exports);
35
+ __exportStar(require("./createCreateApiKey"), exports);
36
+ __exportStar(require("./createDeleteApiKey"), exports);
37
+ __exportStar(require("./createListApiKeys"), exports);
38
+ __exportStar(require("./createRegenerateApiKey"), exports);
@@ -1,7 +1,7 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { IdentityConfig } from "./types";
3
3
  import { Prisma } from "../db";
4
- declare function exchangeRefreshToken(prisma: Prisma, identityConfig: IdentityConfig): (call: {
4
+ declare function createExchangeApiKey(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
5
  request: unknown;
6
6
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
- export { exchangeRefreshToken };
7
+ export { createExchangeApiKey };
@@ -42,7 +42,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
42
42
  });
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.exchangeApiKey = exchangeApiKey;
45
+ exports.createExchangeApiKey = createExchangeApiKey;
46
46
  /*
47
47
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
48
48
  * http://github.com/fonoster/fonoster
@@ -65,14 +65,14 @@ const common_1 = require("@fonoster/common");
65
65
  const logger_1 = require("@fonoster/logger");
66
66
  const grpc = __importStar(require("@grpc/grpc-js"));
67
67
  const exchangeTokens_1 = require("./exchangeTokens");
68
- const getApiKeyByAccessKeyId_1 = require("../utils/getApiKeyByAccessKeyId");
68
+ const createGetApiKeyByAccessKeyId_1 = require("../utils/createGetApiKeyByAccessKeyId");
69
69
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
70
- function exchangeApiKey(prisma, identityConfig) {
71
- const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
70
+ function createExchangeApiKey(prisma, identityConfig) {
71
+ const exchangeApiKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
72
72
  const { request } = call;
73
73
  const { accessKeyId, accessKeySecret } = request;
74
74
  logger.verbose("call to exchangeApiKey", { accessKeyId });
75
- const key = yield (0, getApiKeyByAccessKeyId_1.getApiKeyByAccessKeyId)(prisma)(accessKeyId);
75
+ const key = yield (0, createGetApiKeyByAccessKeyId_1.createGetApiKeyByAccessKeyId)(prisma)(accessKeyId);
76
76
  if ((key === null || key === void 0 ? void 0 : key.accessKeySecret) !== (accessKeySecret === null || accessKeySecret === void 0 ? void 0 : accessKeySecret.trim())) {
77
77
  return callback({
78
78
  code: grpc.status.PERMISSION_DENIED,
@@ -81,5 +81,5 @@ function exchangeApiKey(prisma, identityConfig) {
81
81
  }
82
82
  callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(accessKeyId));
83
83
  });
84
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.exchangeApiKeysRequestSchema);
84
+ return (0, common_1.withErrorHandlingAndValidation)(exchangeApiKey, common_1.Validators.exchangeApiKeysRequestSchema);
85
85
  }
@@ -1,7 +1,7 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { IdentityConfig } from "./types";
3
3
  import { Prisma } from "../db";
4
- declare function exchangeOauth2Code(prisma: Prisma, identityConfig: IdentityConfig): (call: {
4
+ declare function createExchangeCredentials(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
5
  request: unknown;
6
6
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
- export { exchangeOauth2Code };
7
+ export { createExchangeCredentials };
@@ -42,7 +42,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
42
42
  });
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.exchangeCredentials = exchangeCredentials;
45
+ exports.createExchangeCredentials = createExchangeCredentials;
46
46
  /*
47
47
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
48
48
  * http://github.com/fonoster/fonoster
@@ -67,18 +67,18 @@ const grpc = __importStar(require("@grpc/grpc-js"));
67
67
  const exchangeTokens_1 = require("./exchangeTokens");
68
68
  const envs_1 = require("../envs");
69
69
  const createIsValidVerificationCode_1 = require("../utils/createIsValidVerificationCode");
70
- const getUserByEmail_1 = require("../utils/getUserByEmail");
70
+ const createGetUserByEmail_1 = require("../utils/createGetUserByEmail");
71
71
  const verification_1 = require("../verification");
72
72
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
73
73
  const verificationRequiredButNotProvided = (user) => envs_1.IDENTITY_USER_VERIFICATION_REQUIRED &&
74
74
  (!user.emailVerified || !user.phoneNumberVerified);
75
- function exchangeCredentials(prisma, identityConfig) {
75
+ function createExchangeCredentials(prisma, identityConfig) {
76
76
  const isValidVerificationCode = (0, createIsValidVerificationCode_1.createIsValidVerificationCode)(prisma);
77
- const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
77
+ const exchangeCredentials = (call, callback) => __awaiter(this, void 0, void 0, function* () {
78
78
  const { request } = call;
79
79
  const { username: email, password, verificationCode } = request;
80
80
  logger.verbose("call to exchangeCredentials", { username: email });
81
- const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(email);
81
+ const user = yield (0, createGetUserByEmail_1.createGetUserByEmail)(prisma)(email);
82
82
  if (!user || user.password !== (password === null || password === void 0 ? void 0 : password.trim())) {
83
83
  return callback({
84
84
  code: grpc.status.PERMISSION_DENIED,
@@ -106,5 +106,5 @@ function exchangeCredentials(prisma, identityConfig) {
106
106
  }
107
107
  callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
108
108
  });
109
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeCredentialsRequestSchema);
109
+ return (0, common_1.withErrorHandlingAndValidation)(exchangeCredentials, common_1.exchangeCredentialsRequestSchema);
110
110
  }
@@ -1,7 +1,7 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { IdentityConfig } from "./types";
3
3
  import { Prisma } from "../db";
4
- declare function exchangeCredentials(prisma: Prisma, identityConfig: IdentityConfig): (call: {
4
+ declare function createExchangeOauth2Code(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
5
  request: unknown;
6
6
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
- export { exchangeCredentials };
7
+ export { createExchangeOauth2Code };
@@ -42,7 +42,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
42
42
  });
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.exchangeOauth2Code = exchangeOauth2Code;
45
+ exports.createExchangeOauth2Code = createExchangeOauth2Code;
46
46
  /*
47
47
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
48
48
  * http://github.com/fonoster/fonoster
@@ -65,10 +65,10 @@ const common_1 = require("@fonoster/common");
65
65
  const logger_1 = require("@fonoster/logger");
66
66
  const grpc = __importStar(require("@grpc/grpc-js"));
67
67
  const exchangeTokens_1 = require("./exchangeTokens");
68
- const getUserByEmail_1 = require("../utils/getUserByEmail");
68
+ const createGetUserByEmail_1 = require("../utils/createGetUserByEmail");
69
69
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
70
- function exchangeOauth2Code(prisma, identityConfig) {
71
- const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
70
+ function createExchangeOauth2Code(prisma, identityConfig) {
71
+ const exchangeOauth2Code = (call, callback) => __awaiter(this, void 0, void 0, function* () {
72
72
  const { request } = call;
73
73
  const { provider, username: email, code } = request;
74
74
  logger.verbose("call to exchangeOauth2Code", { provider });
@@ -92,7 +92,7 @@ function exchangeOauth2Code(prisma, identityConfig) {
92
92
  }
93
93
  });
94
94
  const userData = yield userResponse.json();
95
- const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(email);
95
+ const user = yield (0, createGetUserByEmail_1.createGetUserByEmail)(prisma)(email);
96
96
  if (userData.email !== email || !user) {
97
97
  return callback({
98
98
  code: grpc.status.PERMISSION_DENIED,
@@ -101,5 +101,5 @@ function exchangeOauth2Code(prisma, identityConfig) {
101
101
  }
102
102
  callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
103
103
  });
104
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeOauth2RequestSchema);
104
+ return (0, common_1.withErrorHandlingAndValidation)(exchangeOauth2Code, common_1.exchangeOauth2RequestSchema);
105
105
  }
@@ -1,7 +1,7 @@
1
1
  import { GrpcErrorMessage } from "@fonoster/common";
2
2
  import { IdentityConfig } from "./types";
3
3
  import { Prisma } from "../db";
4
- declare function exchangeApiKey(prisma: Prisma, identityConfig: IdentityConfig): (call: {
4
+ declare function createExchangeRefreshToken(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
5
  request: unknown;
6
6
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
- export { exchangeApiKey };
7
+ export { createExchangeRefreshToken };
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.exchangeRefreshToken = exchangeRefreshToken;
15
+ exports.createExchangeRefreshToken = createExchangeRefreshToken;
16
16
  /*
17
17
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
18
18
  * http://github.com/fonoster/fonoster
@@ -37,8 +37,8 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
37
37
  const exchangeTokens_1 = require("./exchangeTokens");
38
38
  const constants_1 = require("../constants");
39
39
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
40
- function exchangeRefreshToken(prisma, identityConfig) {
41
- const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
40
+ function createExchangeRefreshToken(prisma, identityConfig) {
41
+ const exchangeRefreshToken = (call, callback) => __awaiter(this, void 0, void 0, function* () {
42
42
  const { privateKey } = identityConfig;
43
43
  const { request } = call;
44
44
  const { refreshToken: oldRefreshToken } = request;
@@ -49,5 +49,5 @@ function exchangeRefreshToken(prisma, identityConfig) {
49
49
  logger.verbose("call to exchangeRefreshToken", { accessKeyId });
50
50
  callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(accessKeyId));
51
51
  });
52
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeRefreshTokenRequestSchema);
52
+ return (0, common_1.withErrorHandlingAndValidation)(exchangeRefreshToken, common_1.exchangeRefreshTokenRequestSchema);
53
53
  }
@@ -79,16 +79,16 @@ function exchangeTokens(prisma, identityConfig) {
79
79
  let accessToken = null;
80
80
  let refreshToken = null;
81
81
  if (accessKeyId.startsWith("US")) {
82
- const idTokenPayload = yield US.getIdTokenPayload(prisma, identityConfig)(accessKeyId);
83
- const accessTokenPayload = yield US.getAccessTokenPayload(prisma, identityConfig)(accessKeyId);
84
- const refreshTokenPayload = yield US.getRefreshTokenPayload(prisma, identityConfig)(accessKeyId);
82
+ const idTokenPayload = yield US.createGetIdTokenPayload(prisma, identityConfig)(accessKeyId);
83
+ const accessTokenPayload = yield US.createGetAccessTokenPayload(prisma, identityConfig)(accessKeyId);
84
+ const refreshTokenPayload = yield US.createGetRefreshTokenPayload(prisma, identityConfig)(accessKeyId);
85
85
  idToken = jsonwebtoken_1.default.sign(idTokenPayload, privateKey, idTokenSignOptions);
86
86
  accessToken = jsonwebtoken_1.default.sign(accessTokenPayload, privateKey, accessTokenSignOptions);
87
87
  refreshToken = jsonwebtoken_1.default.sign(refreshTokenPayload, privateKey, refreshTokenSignOptions);
88
88
  }
89
89
  else {
90
- const accessTokenPayload = yield AK.getAccessTokenPayload(prisma, identityConfig)(accessKeyId);
91
- const refreshTokenPayload = yield AK.getRefreshTokenPayload(prisma, identityConfig)(accessKeyId);
90
+ const accessTokenPayload = yield AK.createGetAccessTokenPayload(prisma, identityConfig)(accessKeyId);
91
+ const refreshTokenPayload = yield AK.createGetRefreshTokenPayload(prisma, identityConfig)(accessKeyId);
92
92
  accessToken = jsonwebtoken_1.default.sign(accessTokenPayload, privateKey, accessTokenSignOptions);
93
93
  refreshToken = jsonwebtoken_1.default.sign(refreshTokenPayload, privateKey, refreshTokenSignOptions);
94
94
  }
@@ -1,6 +1,5 @@
1
- export * from "./TokenUseEnum";
2
- export * from "./exchangeApiKey";
3
- export * from "./exchangeCredentials";
4
- export * from "./exchangeOauth2Code";
5
- export * from "./exchangeRefreshToken";
1
+ export * from "./createExchangeApiKey";
2
+ export * from "./createExchangeCredentials";
3
+ export * from "./createExchangeOauth2Code";
4
+ export * from "./createExchangeRefreshToken";
6
5
  export * from "./types";
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./TokenUseEnum"), exports);
18
17
  /*
19
18
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
20
19
  * http://github.com/fonoster/fonoster
@@ -33,8 +32,8 @@ __exportStar(require("./TokenUseEnum"), exports);
33
32
  * See the License for the specific language governing permissions and
34
33
  * limitations under the License.
35
34
  */
36
- __exportStar(require("./exchangeApiKey"), exports);
37
- __exportStar(require("./exchangeCredentials"), exports);
38
- __exportStar(require("./exchangeOauth2Code"), exports);
39
- __exportStar(require("./exchangeRefreshToken"), exports);
35
+ __exportStar(require("./createExchangeApiKey"), exports);
36
+ __exportStar(require("./createExchangeCredentials"), exports);
37
+ __exportStar(require("./createExchangeOauth2Code"), exports);
38
+ __exportStar(require("./createExchangeRefreshToken"), exports);
40
39
  __exportStar(require("./types"), exports);
@@ -0,0 +1,5 @@
1
+ import { Prisma } from "../../../db";
2
+ import { AccessToken } from "@fonoster/common/";
3
+ import { IdentityConfig } from "../../types";
4
+ declare function createGetAccessTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<AccessToken>;
5
+ export { createGetAccessTokenPayload };
@@ -0,0 +1,46 @@
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.createGetAccessTokenPayload = createGetAccessTokenPayload;
13
+ const common_1 = require("@fonoster/common/");
14
+ function createGetAccessTokenPayload(prisma, identityConfig) {
15
+ return function getAccessTokenPayload(accessKeyId) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const apiKey = yield prisma.apiKey.findFirst({
18
+ where: {
19
+ accessKeyId
20
+ },
21
+ include: {
22
+ workspace: true
23
+ }
24
+ });
25
+ if (!apiKey) {
26
+ return null;
27
+ }
28
+ const { issuer, audience } = identityConfig;
29
+ const { ref, workspace } = apiKey;
30
+ const access = [
31
+ {
32
+ accessKeyId: workspace.accessKeyId,
33
+ role: apiKey.role
34
+ }
35
+ ];
36
+ return {
37
+ iss: issuer,
38
+ sub: ref,
39
+ aud: audience,
40
+ tokenUse: common_1.TokenUseEnum.ACCESS,
41
+ accessKeyId,
42
+ access
43
+ };
44
+ });
45
+ };
46
+ }
@@ -0,0 +1,5 @@
1
+ import { Prisma } from "../../../db";
2
+ import { IdentityConfig } from "../../types";
3
+ import { RefreshToken } from "@fonoster/common";
4
+ declare function createGetRefreshTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<RefreshToken>;
5
+ export { createGetRefreshTokenPayload };
@@ -9,23 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getRefreshTokenPayload = getRefreshTokenPayload;
12
+ exports.createGetRefreshTokenPayload = createGetRefreshTokenPayload;
13
13
  const buildRefreshTokenPayload_1 = require("../buildRefreshTokenPayload");
14
- function getRefreshTokenPayload(prisma, identityConfig) {
15
- return (accessKeyId) => __awaiter(this, void 0, void 0, function* () {
16
- const apiKey = yield prisma.apiKey.findFirst({
17
- where: {
18
- accessKeyId
14
+ function createGetRefreshTokenPayload(prisma, identityConfig) {
15
+ return function createGetRefreshTokenPayload(accessKeyId) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const apiKey = yield prisma.apiKey.findFirst({
18
+ where: {
19
+ accessKeyId
20
+ }
21
+ });
22
+ if (!apiKey) {
23
+ return null;
19
24
  }
25
+ const { ref: identityRef } = apiKey;
26
+ return (0, buildRefreshTokenPayload_1.buildRefreshTokenPayload)({
27
+ identityConfig,
28
+ accessKeyId,
29
+ identityRef
30
+ });
20
31
  });
21
- if (!apiKey) {
22
- return null;
23
- }
24
- const { ref: identityRef } = apiKey;
25
- return (0, buildRefreshTokenPayload_1.buildRefreshTokenPayload)({
26
- identityConfig,
27
- accessKeyId,
28
- identityRef
29
- });
30
- });
32
+ };
31
33
  }
@@ -1,2 +1,2 @@
1
- export * from "./getAccessTokenPayload";
2
- export * from "./getRefreshTokenPayload";
1
+ export * from "./createGetAccessTokenPayload";
2
+ export * from "./createGetRefreshTokenPayload";
@@ -32,5 +32,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  * See the License for the specific language governing permissions and
33
33
  * limitations under the License.
34
34
  */
35
- __exportStar(require("./getAccessTokenPayload"), exports);
36
- __exportStar(require("./getRefreshTokenPayload"), exports);
35
+ __exportStar(require("./createGetAccessTokenPayload"), exports);
36
+ __exportStar(require("./createGetRefreshTokenPayload"), exports);
@@ -1,4 +1,5 @@
1
- import { IdentityConfig, RefreshToken } from "../types";
1
+ import { RefreshToken } from "@fonoster/common";
2
+ import { IdentityConfig } from "../types";
2
3
  declare function buildRefreshTokenPayload(params: {
3
4
  identityConfig: IdentityConfig;
4
5
  accessKeyId: string;
@@ -19,7 +19,7 @@ exports.buildRefreshTokenPayload = buildRefreshTokenPayload;
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
- const TokenUseEnum_1 = require("../TokenUseEnum");
22
+ const common_1 = require("@fonoster/common");
23
23
  function buildRefreshTokenPayload(params) {
24
24
  const { identityConfig, accessKeyId, identityRef } = params;
25
25
  const { issuer, audience } = identityConfig;
@@ -27,7 +27,7 @@ function buildRefreshTokenPayload(params) {
27
27
  iss: issuer,
28
28
  sub: identityRef,
29
29
  aud: audience,
30
- tokenUse: TokenUseEnum_1.TokenUseEnum.REFRESH,
30
+ tokenUse: common_1.TokenUseEnum.REFRESH,
31
31
  accessKeyId
32
32
  };
33
33
  }
@@ -0,0 +1,5 @@
1
+ import { Prisma } from "../../../db";
2
+ import { AccessToken } from "@fonoster/common";
3
+ import { IdentityConfig } from "../../types";
4
+ declare function createGetAccessTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<AccessToken>;
5
+ export { createGetAccessTokenPayload };