@fonoster/identity 0.6.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/JsonWebErrorEnum.d.ts +5 -0
  4. package/dist/JsonWebErrorEnum.js +26 -0
  5. package/dist/apikeys/ApiRoleEnum.d.ts +4 -0
  6. package/dist/apikeys/ApiRoleEnum.js +25 -0
  7. package/dist/apikeys/createApiKey.d.ts +24 -0
  8. package/dist/apikeys/createApiKey.js +73 -0
  9. package/dist/apikeys/deleteApiKey.d.ts +18 -0
  10. package/dist/apikeys/deleteApiKey.js +58 -0
  11. package/dist/apikeys/index.d.ts +5 -0
  12. package/dist/apikeys/index.js +39 -0
  13. package/dist/apikeys/listApiKeys.d.ts +23 -0
  14. package/dist/apikeys/listApiKeys.js +50 -0
  15. package/dist/apikeys/regenerateApiKey.d.ts +20 -0
  16. package/dist/apikeys/regenerateApiKey.js +64 -0
  17. package/dist/createAuthInterceptor.d.ts +15 -0
  18. package/dist/createAuthInterceptor.js +75 -0
  19. package/dist/db.d.ts +14 -0
  20. package/dist/db.js +31 -0
  21. package/dist/envs.d.ts +1 -0
  22. package/dist/envs.js +24 -0
  23. package/dist/errors.d.ts +4 -0
  24. package/dist/errors.js +35 -0
  25. package/dist/exchanges/TokenUseEnum.d.ts +6 -0
  26. package/dist/exchanges/TokenUseEnum.js +27 -0
  27. package/dist/exchanges/exchangeApiKey.d.ts +24 -0
  28. package/dist/exchanges/exchangeApiKey.js +86 -0
  29. package/dist/exchanges/exchangeCredentials.d.ts +24 -0
  30. package/dist/exchanges/exchangeCredentials.js +86 -0
  31. package/dist/exchanges/exchangeRefreshToken.d.ts +21 -0
  32. package/dist/exchanges/exchangeRefreshToken.js +62 -0
  33. package/dist/exchanges/exchangeTokens.d.ts +8 -0
  34. package/dist/exchanges/exchangeTokens.js +92 -0
  35. package/dist/exchanges/index.d.ts +5 -0
  36. package/dist/exchanges/index.js +39 -0
  37. package/dist/exchanges/payloads/apikeys/getAccessTokenPayload.d.ts +4 -0
  38. package/dist/exchanges/payloads/apikeys/getAccessTokenPayload.js +45 -0
  39. package/dist/exchanges/payloads/apikeys/getRefreshTokenPayload.d.ts +4 -0
  40. package/dist/exchanges/payloads/apikeys/getRefreshTokenPayload.js +32 -0
  41. package/dist/exchanges/payloads/apikeys/index.d.ts +2 -0
  42. package/dist/exchanges/payloads/apikeys/index.js +36 -0
  43. package/dist/exchanges/payloads/buildRefreshTokenPayload.d.ts +7 -0
  44. package/dist/exchanges/payloads/buildRefreshTokenPayload.js +34 -0
  45. package/dist/exchanges/payloads/users/getAccessTokenPayload.d.ts +4 -0
  46. package/dist/exchanges/payloads/users/getAccessTokenPayload.js +55 -0
  47. package/dist/exchanges/payloads/users/getIdTokenPayload.d.ts +4 -0
  48. package/dist/exchanges/payloads/users/getIdTokenPayload.js +39 -0
  49. package/dist/exchanges/payloads/users/getRefreshTokenPayload.d.ts +4 -0
  50. package/dist/exchanges/payloads/users/getRefreshTokenPayload.js +35 -0
  51. package/dist/exchanges/payloads/users/index.d.ts +3 -0
  52. package/dist/exchanges/payloads/users/index.js +37 -0
  53. package/dist/exchanges/types.d.ts +56 -0
  54. package/dist/exchanges/types.js +2 -0
  55. package/dist/getPublicKey.d.ts +6 -0
  56. package/dist/getPublicKey.js +21 -0
  57. package/dist/getPublicKeyClient.d.ts +5 -0
  58. package/dist/getPublicKeyClient.js +62 -0
  59. package/dist/index.d.ts +10 -0
  60. package/dist/index.js +44 -0
  61. package/dist/invites/EmailTemplatesEnum.d.ts +5 -0
  62. package/dist/invites/EmailTemplatesEnum.js +26 -0
  63. package/dist/invites/createInviteBody.d.ts +8 -0
  64. package/dist/invites/createInviteBody.js +44 -0
  65. package/dist/invites/index.d.ts +3 -0
  66. package/dist/invites/index.js +37 -0
  67. package/dist/invites/sendInvite.d.ts +11 -0
  68. package/dist/invites/sendInvite.js +29 -0
  69. package/dist/invites/templates/inviteExistingUser.hbs +54 -0
  70. package/dist/invites/templates/inviteNewUser.hbs +55 -0
  71. package/dist/roles.d.ts +5 -0
  72. package/dist/roles.js +129 -0
  73. package/dist/service.d.ts +200 -0
  74. package/dist/service.js +63 -0
  75. package/dist/users/createUser.d.ts +27 -0
  76. package/dist/users/createUser.js +66 -0
  77. package/dist/users/deleteUser.d.ts +12 -0
  78. package/dist/users/deleteUser.js +59 -0
  79. package/dist/users/getUser.d.ts +17 -0
  80. package/dist/users/getUser.js +67 -0
  81. package/dist/users/index.d.ts +5 -0
  82. package/dist/users/index.js +39 -0
  83. package/dist/users/updateUser.d.ts +27 -0
  84. package/dist/users/updateUser.js +73 -0
  85. package/dist/users/upsertDefaultUser.d.ts +17 -0
  86. package/dist/users/upsertDefaultUser.js +87 -0
  87. package/dist/utils/createCallAccessToken.d.ts +6 -0
  88. package/dist/utils/createCallAccessToken.js +65 -0
  89. package/dist/utils/decodeToken.d.ts +4 -0
  90. package/dist/utils/decodeToken.js +26 -0
  91. package/dist/utils/generateAccessKeyId.d.ts +8 -0
  92. package/dist/utils/generateAccessKeyId.js +39 -0
  93. package/dist/utils/generateAccessKeySecret.d.ts +2 -0
  94. package/dist/utils/generateAccessKeySecret.js +26 -0
  95. package/dist/utils/getAccessKeyIdFromCall.d.ts +3 -0
  96. package/dist/utils/getAccessKeyIdFromCall.js +9 -0
  97. package/dist/utils/getAccessKeyIdFromEmail.d.ts +3 -0
  98. package/dist/utils/getAccessKeyIdFromEmail.js +37 -0
  99. package/dist/utils/getAccessKeyIdFromToken.d.ts +2 -0
  100. package/dist/utils/getAccessKeyIdFromToken.js +31 -0
  101. package/dist/utils/getApiKeyByAccessKeyId.d.ts +12 -0
  102. package/dist/utils/getApiKeyByAccessKeyId.js +26 -0
  103. package/dist/utils/getTokenFromCall.d.ts +3 -0
  104. package/dist/utils/getTokenFromCall.js +9 -0
  105. package/dist/utils/getUserByEmail.d.ts +15 -0
  106. package/dist/utils/getUserByEmail.js +26 -0
  107. package/dist/utils/getUserRefFromToken.d.ts +2 -0
  108. package/dist/utils/getUserRefFromToken.js +31 -0
  109. package/dist/utils/hasAccess.d.ts +3 -0
  110. package/dist/utils/hasAccess.js +10 -0
  111. package/dist/utils/hasAccessToResource.d.ts +5 -0
  112. package/dist/utils/hasAccessToResource.js +53 -0
  113. package/dist/utils/index.d.ts +11 -0
  114. package/dist/utils/index.js +45 -0
  115. package/dist/utils/isValidToken.d.ts +2 -0
  116. package/dist/utils/isValidToken.js +52 -0
  117. package/dist/utils/tokenHasAccessKeyId.d.ts +2 -0
  118. package/dist/utils/tokenHasAccessKeyId.js +29 -0
  119. package/dist/utils/withAccess.d.ts +6 -0
  120. package/dist/utils/withAccess.js +77 -0
  121. package/dist/workspaces/WorkspaceRoleEnum.d.ts +6 -0
  122. package/dist/workspaces/WorkspaceRoleEnum.js +27 -0
  123. package/dist/workspaces/createSendEmail.d.ts +3 -0
  124. package/dist/workspaces/createSendEmail.js +38 -0
  125. package/dist/workspaces/createWorkspace.d.ts +18 -0
  126. package/dist/workspaces/createWorkspace.js +65 -0
  127. package/dist/workspaces/deleteWorkspace.d.ts +12 -0
  128. package/dist/workspaces/deleteWorkspace.js +59 -0
  129. package/dist/workspaces/getWorkspace.d.ts +16 -0
  130. package/dist/workspaces/getWorkspace.js +65 -0
  131. package/dist/workspaces/index.d.ts +9 -0
  132. package/dist/workspaces/index.js +43 -0
  133. package/dist/workspaces/inviteUserToWorkspace.d.ts +31 -0
  134. package/dist/workspaces/inviteUserToWorkspace.js +152 -0
  135. package/dist/workspaces/isAdminMember.d.ts +3 -0
  136. package/dist/workspaces/isAdminMember.js +53 -0
  137. package/dist/workspaces/isWorkspaceMember.d.ts +3 -0
  138. package/dist/workspaces/isWorkspaceMember.js +32 -0
  139. package/dist/workspaces/listWorkspaces.d.ts +16 -0
  140. package/dist/workspaces/listWorkspaces.js +55 -0
  141. package/dist/workspaces/removeUserFromWorkspace.d.ts +12 -0
  142. package/dist/workspaces/removeUserFromWorkspace.js +84 -0
  143. package/dist/workspaces/resendWorkspaceMembershipInvitation.d.ts +14 -0
  144. package/dist/workspaces/resendWorkspaceMembershipInvitation.js +98 -0
  145. package/dist/workspaces/updateWorkspace.d.ts +21 -0
  146. package/dist/workspaces/updateWorkspace.js +76 -0
  147. package/package.json +50 -0
@@ -0,0 +1,7 @@
1
+ import { IdentityConfig, RefreshToken } from "../types";
2
+ declare function buildRefreshTokenPayload(params: {
3
+ identityConfig: IdentityConfig;
4
+ accessKeyId: string;
5
+ identityRef: string;
6
+ }): RefreshToken;
7
+ export { buildRefreshTokenPayload };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRefreshTokenPayload = 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
+ const TokenUseEnum_1 = require("../TokenUseEnum");
23
+ function buildRefreshTokenPayload(params) {
24
+ const { identityConfig, accessKeyId, identityRef } = params;
25
+ const { issuer, audience } = identityConfig;
26
+ return {
27
+ iss: issuer,
28
+ sub: identityRef,
29
+ aud: audience,
30
+ tokenUse: TokenUseEnum_1.TokenUseEnum.REFRESH,
31
+ accessKeyId
32
+ };
33
+ }
34
+ exports.buildRefreshTokenPayload = buildRefreshTokenPayload;
@@ -0,0 +1,4 @@
1
+ import { Prisma } from "../../../db";
2
+ import { AccessToken, IdentityConfig } from "../../types";
3
+ declare function getAccessTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<AccessToken>;
4
+ export { getAccessTokenPayload };
@@ -0,0 +1,55 @@
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.getAccessTokenPayload = void 0;
13
+ const workspaces_1 = require("../../../workspaces");
14
+ const TokenUseEnum_1 = require("../../TokenUseEnum");
15
+ function getAccessTokenPayload(prisma, identityConfig) {
16
+ return (accessKeyId) => __awaiter(this, void 0, void 0, function* () {
17
+ const user = yield prisma.user.findFirst({
18
+ where: {
19
+ accessKeyId
20
+ },
21
+ include: {
22
+ ownedWorkspaces: true,
23
+ memberships: {
24
+ include: {
25
+ workspace: true
26
+ }
27
+ }
28
+ }
29
+ });
30
+ if (!user) {
31
+ return null;
32
+ }
33
+ const { issuer, audience } = identityConfig;
34
+ const { ref, ownedWorkspaces, memberships } = user;
35
+ const access = ownedWorkspaces.map((workspace) => ({
36
+ accessKeyId: workspace.accessKeyId,
37
+ role: workspaces_1.WorkspaceRoleEnum.OWNER
38
+ }));
39
+ memberships.forEach((membership) => {
40
+ access.push({
41
+ accessKeyId: membership.workspace.accessKeyId,
42
+ role: membership.role
43
+ });
44
+ });
45
+ return {
46
+ iss: issuer,
47
+ sub: ref,
48
+ aud: audience,
49
+ tokenUse: TokenUseEnum_1.TokenUseEnum.ACCESS,
50
+ accessKeyId,
51
+ access
52
+ };
53
+ });
54
+ }
55
+ exports.getAccessTokenPayload = getAccessTokenPayload;
@@ -0,0 +1,4 @@
1
+ import { Prisma } from "../../../db";
2
+ import { IdToken, IdentityConfig } from "../../types";
3
+ declare function getIdTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<IdToken>;
4
+ export { getIdTokenPayload };
@@ -0,0 +1,39 @@
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.getIdTokenPayload = void 0;
13
+ const TokenUseEnum_1 = require("../../TokenUseEnum");
14
+ function getIdTokenPayload(prisma, identityConfig) {
15
+ return (accessKeyId) => __awaiter(this, void 0, void 0, function* () {
16
+ const user = yield prisma.user.findFirst({
17
+ where: {
18
+ accessKeyId
19
+ }
20
+ });
21
+ if (!user) {
22
+ return null;
23
+ }
24
+ const { issuer, audience } = identityConfig;
25
+ const { ref, email, phoneNumber, emailVerified, phoneNumberVerified } = user;
26
+ return {
27
+ iss: issuer,
28
+ sub: ref,
29
+ aud: audience,
30
+ tokenUse: TokenUseEnum_1.TokenUseEnum.ID,
31
+ accessKeyId,
32
+ email,
33
+ emailVerified,
34
+ phoneNumber,
35
+ phoneNumberVerified
36
+ };
37
+ });
38
+ }
39
+ exports.getIdTokenPayload = getIdTokenPayload;
@@ -0,0 +1,4 @@
1
+ import { Prisma } from "../../../db";
2
+ import { IdentityConfig, RefreshToken } from "../../types";
3
+ declare function getRefreshTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<RefreshToken>;
4
+ export { getRefreshTokenPayload };
@@ -0,0 +1,35 @@
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.getRefreshTokenPayload = void 0;
13
+ const TokenUseEnum_1 = require("../../TokenUseEnum");
14
+ function getRefreshTokenPayload(prisma, identityConfig) {
15
+ return (accessKeyId) => __awaiter(this, void 0, void 0, function* () {
16
+ const user = yield prisma.user.findFirst({
17
+ where: {
18
+ accessKeyId
19
+ }
20
+ });
21
+ if (!user) {
22
+ return null;
23
+ }
24
+ const { issuer, audience } = identityConfig;
25
+ const { ref } = user;
26
+ return {
27
+ iss: issuer,
28
+ sub: ref,
29
+ aud: audience,
30
+ tokenUse: TokenUseEnum_1.TokenUseEnum.REFRESH,
31
+ accessKeyId
32
+ };
33
+ });
34
+ }
35
+ exports.getRefreshTokenPayload = getRefreshTokenPayload;
@@ -0,0 +1,3 @@
1
+ export * from "./getIdTokenPayload";
2
+ export * from "./getAccessTokenPayload";
3
+ export * from "./getRefreshTokenPayload";
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*
18
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster/fonoster
20
+ *
21
+ * This file is part of Fonoster
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ __exportStar(require("./getIdTokenPayload"), exports);
36
+ __exportStar(require("./getAccessTokenPayload"), exports);
37
+ __exportStar(require("./getRefreshTokenPayload"), exports);
@@ -0,0 +1,56 @@
1
+ import { TokenUseEnum } from "./TokenUseEnum";
2
+ import { WorkspaceRoleEnum } from "../workspaces/WorkspaceRoleEnum";
3
+ type Role = {
4
+ name: string;
5
+ description: string;
6
+ access: string[];
7
+ };
8
+ type Access = {
9
+ accessKeyId: string;
10
+ role: WorkspaceRoleEnum;
11
+ };
12
+ type BaseToken = {
13
+ iss: string;
14
+ sub: string;
15
+ aud: string;
16
+ exp: number;
17
+ iat: number;
18
+ tokenUse: TokenUseEnum;
19
+ accessKeyId: string;
20
+ };
21
+ type IdToken = BaseToken & {
22
+ emailVerified: boolean;
23
+ phoneNumberVerified: boolean;
24
+ phoneNumber: string;
25
+ email: string;
26
+ tokenUse: TokenUseEnum.ID;
27
+ };
28
+ type AccessToken = BaseToken & {
29
+ access: Access[];
30
+ tokenUse: TokenUseEnum.ACCESS;
31
+ };
32
+ type RefreshToken = BaseToken & {
33
+ tokenUse: TokenUseEnum.REFRESH;
34
+ };
35
+ type IdentityConfig = {
36
+ issuer: string;
37
+ audience: string;
38
+ privateKey: string;
39
+ publicKey: string;
40
+ encryptionKey: string;
41
+ accessTokenExpiresIn: number | string;
42
+ refreshTokenExpiresIn: number | string;
43
+ idTokenExpiresIn: number | string;
44
+ smtpConfig: {
45
+ sender: string;
46
+ host: string;
47
+ port: number;
48
+ secure: boolean;
49
+ auth: {
50
+ user: string;
51
+ pass: string;
52
+ };
53
+ };
54
+ };
55
+ type DecodedToken<T extends TokenUseEnum> = T extends TokenUseEnum.ID ? IdToken : T extends TokenUseEnum.ACCESS ? AccessToken : T extends TokenUseEnum.REFRESH ? TokenUseEnum : never;
56
+ export { Role, IdToken, Access, AccessToken, RefreshToken, DecodedToken, IdentityConfig };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ type GetPublicKeyResponse = {
3
+ publicKey: string;
4
+ };
5
+ declare function getPublicKey(publicKey: string): (_: unknown, callback: (error: GrpcErrorMessage, response?: GetPublicKeyResponse) => void) => Promise<void>;
6
+ export { getPublicKey };
@@ -0,0 +1,21 @@
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.getPublicKey = void 0;
13
+ const logger_1 = require("@fonoster/logger");
14
+ const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
15
+ function getPublicKey(publicKey) {
16
+ return (_, callback) => __awaiter(this, void 0, void 0, function* () {
17
+ logger.verbose("getting public key for JWT verification");
18
+ callback(null, { publicKey });
19
+ });
20
+ }
21
+ exports.getPublicKey = getPublicKey;
@@ -0,0 +1,5 @@
1
+ type GetPublicKeyResponse = {
2
+ publicKey: string;
3
+ };
4
+ declare function getPublicKeyClient(endpoint: string): Promise<GetPublicKeyResponse>;
5
+ export { getPublicKeyClient };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getPublicKeyClient = void 0;
27
+ /*
28
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
29
+ * http://github.com/fonoster/fonoster
30
+ *
31
+ * This file is part of Fonoster
32
+ *
33
+ * Licensed under the MIT License (the "License");
34
+ * you may not use this file except in compliance with
35
+ * the License. You may obtain a copy of the License at
36
+ *
37
+ * https://opensource.org/licenses/MIT
38
+ *
39
+ * Unless required by applicable law or agreed to in writing, software
40
+ * distributed under the License is distributed on an "AS IS" BASIS,
41
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42
+ * See the License for the specific language governing permissions and
43
+ * limitations under the License.
44
+ */
45
+ const common_1 = require("@fonoster/common");
46
+ const grpc = __importStar(require("@grpc/grpc-js"));
47
+ const service_1 = require("./service");
48
+ const IdentityServiceClient = grpc.makeGenericClientConstructor((0, common_1.createServiceDefinition)(service_1.serviceDefinitionParams), "", {});
49
+ function getPublicKeyClient(endpoint) {
50
+ return new Promise((resolve, reject) => {
51
+ const client = new IdentityServiceClient(endpoint, grpc.credentials.createInsecure());
52
+ client.getPublicKey({}, (error, response) => {
53
+ if (error) {
54
+ reject(error);
55
+ }
56
+ else {
57
+ resolve(response);
58
+ }
59
+ });
60
+ });
61
+ }
62
+ exports.getPublicKeyClient = getPublicKeyClient;
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ export * from "./apikeys";
3
+ export * from "./exchanges";
4
+ export * from "./invites";
5
+ export * from "./users";
6
+ export * from "./workspaces";
7
+ export * from "./utils";
8
+ export * from "./service";
9
+ export * from "./createAuthInterceptor";
10
+ export * from "./getPublicKeyClient";
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ /*
19
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
20
+ * http://github.com/fonoster/fonoster
21
+ *
22
+ * This file is part of Fonoster
23
+ *
24
+ * Licensed under the MIT License (the "License");
25
+ * you may not use this file except in compliance with
26
+ * the License. You may obtain a copy of the License at
27
+ *
28
+ * https://opensource.org/licenses/MIT
29
+ *
30
+ * Unless required by applicable law or agreed to in writing, software
31
+ * distributed under the License is distributed on an "AS IS" BASIS,
32
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
+ * See the License for the specific language governing permissions and
34
+ * limitations under the License.
35
+ */
36
+ __exportStar(require("./apikeys"), exports);
37
+ __exportStar(require("./exchanges"), exports);
38
+ __exportStar(require("./invites"), exports);
39
+ __exportStar(require("./users"), exports);
40
+ __exportStar(require("./workspaces"), exports);
41
+ __exportStar(require("./utils"), exports);
42
+ __exportStar(require("./service"), exports);
43
+ __exportStar(require("./createAuthInterceptor"), exports);
44
+ __exportStar(require("./getPublicKeyClient"), exports);
@@ -0,0 +1,5 @@
1
+ declare enum EmailTemplatesEnum {
2
+ INVITE_NEW_USER = "inviteNewUser",
3
+ INVITE_EXISTING_USER = "inviteExistingUser"
4
+ }
5
+ export { EmailTemplatesEnum };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmailTemplatesEnum = 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
+ var EmailTemplatesEnum;
23
+ (function (EmailTemplatesEnum) {
24
+ EmailTemplatesEnum["INVITE_NEW_USER"] = "inviteNewUser";
25
+ EmailTemplatesEnum["INVITE_EXISTING_USER"] = "inviteExistingUser";
26
+ })(EmailTemplatesEnum || (exports.EmailTemplatesEnum = EmailTemplatesEnum = {}));
@@ -0,0 +1,8 @@
1
+ declare function createInviteBody(params: {
2
+ emailTemplateDir?: string;
3
+ isExistingUser: boolean;
4
+ workspaceName: string;
5
+ oneTimePassword: string;
6
+ inviteUrl: string;
7
+ }): string;
8
+ export { createInviteBody };
@@ -0,0 +1,44 @@
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.createInviteBody = 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 = __importDefault(require("path"));
26
+ const common_1 = require("@fonoster/common");
27
+ const EmailTemplatesEnum_1 = require("./EmailTemplatesEnum");
28
+ function createInviteBody(params) {
29
+ const { emailTemplateDir, isExistingUser, workspaceName, oneTimePassword, inviteUrl } = params;
30
+ const template = isExistingUser
31
+ ? EmailTemplatesEnum_1.EmailTemplatesEnum.INVITE_EXISTING_USER
32
+ : EmailTemplatesEnum_1.EmailTemplatesEnum.INVITE_NEW_USER;
33
+ const templateDir = emailTemplateDir || path_1.default.join(__dirname, "templates");
34
+ const templatePath = `${templateDir}/${template}.hbs`;
35
+ return (0, common_1.compileTemplate)({
36
+ filePath: templatePath,
37
+ data: {
38
+ workspaceName,
39
+ oneTimePassword,
40
+ inviteUrl
41
+ }
42
+ });
43
+ }
44
+ exports.createInviteBody = createInviteBody;
@@ -0,0 +1,3 @@
1
+ export * from "./createInviteBody";
2
+ export * from "./EmailTemplatesEnum";
3
+ export * from "./sendInvite";
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*
18
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster/fonoster
20
+ *
21
+ * This file is part of Fonoster
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ __exportStar(require("./createInviteBody"), exports);
36
+ __exportStar(require("./EmailTemplatesEnum"), exports);
37
+ __exportStar(require("./sendInvite"), exports);
@@ -0,0 +1,11 @@
1
+ import { EmailParams } from "@fonoster/common";
2
+ type InviteParams = {
3
+ recipient: string;
4
+ inviteUrl: string;
5
+ oneTimePassword?: string;
6
+ workspaceName: string;
7
+ isExistingUser: boolean;
8
+ };
9
+ type SendInvite = (sendEmail: (params: EmailParams) => Promise<void>, request: InviteParams) => Promise<void>;
10
+ declare function sendInvite(sendEmail: (params: EmailParams) => Promise<void>, request: InviteParams): Promise<void>;
11
+ export { sendInvite, SendInvite, InviteParams };
@@ -0,0 +1,29 @@
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.sendInvite = void 0;
13
+ const createInviteBody_1 = require("./createInviteBody");
14
+ function sendInvite(sendEmail, request) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const { recipient, inviteUrl, oneTimePassword, isExistingUser, workspaceName } = request;
17
+ yield sendEmail({
18
+ to: recipient,
19
+ subject: "Invite to join a Fonoster workspace",
20
+ html: (0, createInviteBody_1.createInviteBody)({
21
+ isExistingUser,
22
+ workspaceName,
23
+ oneTimePassword: isExistingUser ? undefined : oneTimePassword,
24
+ inviteUrl
25
+ })
26
+ });
27
+ });
28
+ }
29
+ exports.sendInvite = sendInvite;