@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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/JsonWebErrorEnum.d.ts +5 -0
- package/dist/JsonWebErrorEnum.js +26 -0
- package/dist/apikeys/ApiRoleEnum.d.ts +4 -0
- package/dist/apikeys/ApiRoleEnum.js +25 -0
- package/dist/apikeys/createApiKey.d.ts +24 -0
- package/dist/apikeys/createApiKey.js +73 -0
- package/dist/apikeys/deleteApiKey.d.ts +18 -0
- package/dist/apikeys/deleteApiKey.js +58 -0
- package/dist/apikeys/index.d.ts +5 -0
- package/dist/apikeys/index.js +39 -0
- package/dist/apikeys/listApiKeys.d.ts +23 -0
- package/dist/apikeys/listApiKeys.js +50 -0
- package/dist/apikeys/regenerateApiKey.d.ts +20 -0
- package/dist/apikeys/regenerateApiKey.js +64 -0
- package/dist/createAuthInterceptor.d.ts +15 -0
- package/dist/createAuthInterceptor.js +75 -0
- package/dist/db.d.ts +14 -0
- package/dist/db.js +31 -0
- package/dist/envs.d.ts +1 -0
- package/dist/envs.js +24 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +35 -0
- package/dist/exchanges/TokenUseEnum.d.ts +6 -0
- package/dist/exchanges/TokenUseEnum.js +27 -0
- package/dist/exchanges/exchangeApiKey.d.ts +24 -0
- package/dist/exchanges/exchangeApiKey.js +86 -0
- package/dist/exchanges/exchangeCredentials.d.ts +24 -0
- package/dist/exchanges/exchangeCredentials.js +86 -0
- package/dist/exchanges/exchangeRefreshToken.d.ts +21 -0
- package/dist/exchanges/exchangeRefreshToken.js +62 -0
- package/dist/exchanges/exchangeTokens.d.ts +8 -0
- package/dist/exchanges/exchangeTokens.js +92 -0
- package/dist/exchanges/index.d.ts +5 -0
- package/dist/exchanges/index.js +39 -0
- package/dist/exchanges/payloads/apikeys/getAccessTokenPayload.d.ts +4 -0
- package/dist/exchanges/payloads/apikeys/getAccessTokenPayload.js +45 -0
- package/dist/exchanges/payloads/apikeys/getRefreshTokenPayload.d.ts +4 -0
- package/dist/exchanges/payloads/apikeys/getRefreshTokenPayload.js +32 -0
- package/dist/exchanges/payloads/apikeys/index.d.ts +2 -0
- package/dist/exchanges/payloads/apikeys/index.js +36 -0
- package/dist/exchanges/payloads/buildRefreshTokenPayload.d.ts +7 -0
- package/dist/exchanges/payloads/buildRefreshTokenPayload.js +34 -0
- package/dist/exchanges/payloads/users/getAccessTokenPayload.d.ts +4 -0
- package/dist/exchanges/payloads/users/getAccessTokenPayload.js +55 -0
- package/dist/exchanges/payloads/users/getIdTokenPayload.d.ts +4 -0
- package/dist/exchanges/payloads/users/getIdTokenPayload.js +39 -0
- package/dist/exchanges/payloads/users/getRefreshTokenPayload.d.ts +4 -0
- package/dist/exchanges/payloads/users/getRefreshTokenPayload.js +35 -0
- package/dist/exchanges/payloads/users/index.d.ts +3 -0
- package/dist/exchanges/payloads/users/index.js +37 -0
- package/dist/exchanges/types.d.ts +56 -0
- package/dist/exchanges/types.js +2 -0
- package/dist/getPublicKey.d.ts +6 -0
- package/dist/getPublicKey.js +21 -0
- package/dist/getPublicKeyClient.d.ts +5 -0
- package/dist/getPublicKeyClient.js +62 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +44 -0
- package/dist/invites/EmailTemplatesEnum.d.ts +5 -0
- package/dist/invites/EmailTemplatesEnum.js +26 -0
- package/dist/invites/createInviteBody.d.ts +8 -0
- package/dist/invites/createInviteBody.js +44 -0
- package/dist/invites/index.d.ts +3 -0
- package/dist/invites/index.js +37 -0
- package/dist/invites/sendInvite.d.ts +11 -0
- package/dist/invites/sendInvite.js +29 -0
- package/dist/invites/templates/inviteExistingUser.hbs +54 -0
- package/dist/invites/templates/inviteNewUser.hbs +55 -0
- package/dist/roles.d.ts +5 -0
- package/dist/roles.js +129 -0
- package/dist/service.d.ts +200 -0
- package/dist/service.js +63 -0
- package/dist/users/createUser.d.ts +27 -0
- package/dist/users/createUser.js +66 -0
- package/dist/users/deleteUser.d.ts +12 -0
- package/dist/users/deleteUser.js +59 -0
- package/dist/users/getUser.d.ts +17 -0
- package/dist/users/getUser.js +67 -0
- package/dist/users/index.d.ts +5 -0
- package/dist/users/index.js +39 -0
- package/dist/users/updateUser.d.ts +27 -0
- package/dist/users/updateUser.js +73 -0
- package/dist/users/upsertDefaultUser.d.ts +17 -0
- package/dist/users/upsertDefaultUser.js +87 -0
- package/dist/utils/createCallAccessToken.d.ts +6 -0
- package/dist/utils/createCallAccessToken.js +65 -0
- package/dist/utils/decodeToken.d.ts +4 -0
- package/dist/utils/decodeToken.js +26 -0
- package/dist/utils/generateAccessKeyId.d.ts +8 -0
- package/dist/utils/generateAccessKeyId.js +39 -0
- package/dist/utils/generateAccessKeySecret.d.ts +2 -0
- package/dist/utils/generateAccessKeySecret.js +26 -0
- package/dist/utils/getAccessKeyIdFromCall.d.ts +3 -0
- package/dist/utils/getAccessKeyIdFromCall.js +9 -0
- package/dist/utils/getAccessKeyIdFromEmail.d.ts +3 -0
- package/dist/utils/getAccessKeyIdFromEmail.js +37 -0
- package/dist/utils/getAccessKeyIdFromToken.d.ts +2 -0
- package/dist/utils/getAccessKeyIdFromToken.js +31 -0
- package/dist/utils/getApiKeyByAccessKeyId.d.ts +12 -0
- package/dist/utils/getApiKeyByAccessKeyId.js +26 -0
- package/dist/utils/getTokenFromCall.d.ts +3 -0
- package/dist/utils/getTokenFromCall.js +9 -0
- package/dist/utils/getUserByEmail.d.ts +15 -0
- package/dist/utils/getUserByEmail.js +26 -0
- package/dist/utils/getUserRefFromToken.d.ts +2 -0
- package/dist/utils/getUserRefFromToken.js +31 -0
- package/dist/utils/hasAccess.d.ts +3 -0
- package/dist/utils/hasAccess.js +10 -0
- package/dist/utils/hasAccessToResource.d.ts +5 -0
- package/dist/utils/hasAccessToResource.js +53 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +45 -0
- package/dist/utils/isValidToken.d.ts +2 -0
- package/dist/utils/isValidToken.js +52 -0
- package/dist/utils/tokenHasAccessKeyId.d.ts +2 -0
- package/dist/utils/tokenHasAccessKeyId.js +29 -0
- package/dist/utils/withAccess.d.ts +6 -0
- package/dist/utils/withAccess.js +77 -0
- package/dist/workspaces/WorkspaceRoleEnum.d.ts +6 -0
- package/dist/workspaces/WorkspaceRoleEnum.js +27 -0
- package/dist/workspaces/createSendEmail.d.ts +3 -0
- package/dist/workspaces/createSendEmail.js +38 -0
- package/dist/workspaces/createWorkspace.d.ts +18 -0
- package/dist/workspaces/createWorkspace.js +65 -0
- package/dist/workspaces/deleteWorkspace.d.ts +12 -0
- package/dist/workspaces/deleteWorkspace.js +59 -0
- package/dist/workspaces/getWorkspace.d.ts +16 -0
- package/dist/workspaces/getWorkspace.js +65 -0
- package/dist/workspaces/index.d.ts +9 -0
- package/dist/workspaces/index.js +43 -0
- package/dist/workspaces/inviteUserToWorkspace.d.ts +31 -0
- package/dist/workspaces/inviteUserToWorkspace.js +152 -0
- package/dist/workspaces/isAdminMember.d.ts +3 -0
- package/dist/workspaces/isAdminMember.js +53 -0
- package/dist/workspaces/isWorkspaceMember.d.ts +3 -0
- package/dist/workspaces/isWorkspaceMember.js +32 -0
- package/dist/workspaces/listWorkspaces.d.ts +16 -0
- package/dist/workspaces/listWorkspaces.js +55 -0
- package/dist/workspaces/removeUserFromWorkspace.d.ts +12 -0
- package/dist/workspaces/removeUserFromWorkspace.js +84 -0
- package/dist/workspaces/resendWorkspaceMembershipInvitation.d.ts +14 -0
- package/dist/workspaces/resendWorkspaceMembershipInvitation.js +98 -0
- package/dist/workspaces/updateWorkspace.d.ts +21 -0
- package/dist/workspaces/updateWorkspace.js +76 -0
- package/package.json +50 -0
|
@@ -0,0 +1,98 @@
|
|
|
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.resendWorkspaceMembershipInvitation = void 0;
|
|
13
|
+
/*
|
|
14
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
|
+
* http://github.com/fonoster/fonoster
|
|
16
|
+
*
|
|
17
|
+
* This file is part of Fonoster
|
|
18
|
+
*
|
|
19
|
+
* Licensed under the MIT License (the "License");
|
|
20
|
+
* you may not use this file except in compliance with
|
|
21
|
+
* the License. You may obtain a copy of the License at
|
|
22
|
+
*
|
|
23
|
+
* https://opensource.org/licenses/MIT
|
|
24
|
+
*
|
|
25
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
26
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
27
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
|
+
* See the License for the specific language governing permissions and
|
|
29
|
+
* limitations under the License.
|
|
30
|
+
*/
|
|
31
|
+
const common_1 = require("@fonoster/common");
|
|
32
|
+
const logger_1 = require("@fonoster/logger");
|
|
33
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
34
|
+
const createSendEmail_1 = require("./createSendEmail");
|
|
35
|
+
const isAdminMember_1 = require("./isAdminMember");
|
|
36
|
+
const utils_1 = require("../utils");
|
|
37
|
+
const getTokenFromCall_1 = require("../utils/getTokenFromCall");
|
|
38
|
+
const getUserRefFromToken_1 = require("../utils/getUserRefFromToken");
|
|
39
|
+
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
40
|
+
function resendWorkspaceMembershipInvitation(prisma, identityConfig, sendInvite) {
|
|
41
|
+
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
try {
|
|
43
|
+
const { userRef: inviteeRef } = call.request;
|
|
44
|
+
const token = (0, getTokenFromCall_1.getTokenFromCall)(call);
|
|
45
|
+
const adminRef = (0, getUserRefFromToken_1.getUserRefFromToken)(token);
|
|
46
|
+
const accessKeyId = (0, utils_1.getAccessKeyIdFromCall)(call);
|
|
47
|
+
const workspace = yield prisma.workspace.findUnique({
|
|
48
|
+
where: {
|
|
49
|
+
accessKeyId
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const workspaceRef = workspace.ref;
|
|
53
|
+
logger.verbose("resending workspace membership invitation", {
|
|
54
|
+
workspaceRef,
|
|
55
|
+
inviteeRef,
|
|
56
|
+
adminRef
|
|
57
|
+
});
|
|
58
|
+
const isAdmin = yield (0, isAdminMember_1.isAdminMember)(prisma)(workspace.ref, adminRef);
|
|
59
|
+
if (!isAdmin) {
|
|
60
|
+
return callback({
|
|
61
|
+
code: grpc_js_1.status.PERMISSION_DENIED,
|
|
62
|
+
message: "Only admins and owners can resend workspace invitations"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const member = yield prisma.workspaceMember.findFirst({
|
|
66
|
+
where: {
|
|
67
|
+
workspaceRef,
|
|
68
|
+
userRef: inviteeRef
|
|
69
|
+
},
|
|
70
|
+
include: {
|
|
71
|
+
user: true,
|
|
72
|
+
workspace: true
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
if (!member) {
|
|
76
|
+
return callback({
|
|
77
|
+
code: grpc_js_1.status.NOT_FOUND,
|
|
78
|
+
message: `Original invitation not found for userRef: ${inviteeRef}`
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
yield sendInvite((0, createSendEmail_1.createSendEmail)(identityConfig), {
|
|
82
|
+
recipient: member.user.email,
|
|
83
|
+
oneTimePassword: member.user.password,
|
|
84
|
+
workspaceName: member.workspace.name,
|
|
85
|
+
isExistingUser: true,
|
|
86
|
+
// TODO: Create inviteUrl with invite token
|
|
87
|
+
inviteUrl: "https://placehold.it?token=jwt"
|
|
88
|
+
});
|
|
89
|
+
callback(null, {
|
|
90
|
+
userRef: inviteeRef
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
(0, common_1.handleError)(error, callback);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.resendWorkspaceMembershipInvitation = resendWorkspaceMembershipInvitation;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { Prisma } from "../db";
|
|
4
|
+
declare const UpdateWorkspaceRequestSchema: z.ZodObject<{
|
|
5
|
+
ref: z.ZodString;
|
|
6
|
+
name: z.ZodUnion<[z.ZodString, z.ZodNullable<z.ZodOptional<z.ZodString>>]>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
name?: string;
|
|
9
|
+
ref?: string;
|
|
10
|
+
}, {
|
|
11
|
+
name?: string;
|
|
12
|
+
ref?: string;
|
|
13
|
+
}>;
|
|
14
|
+
type UpdateWorkspaceRequest = z.infer<typeof UpdateWorkspaceRequestSchema>;
|
|
15
|
+
type UpdateWorkspaceResponse = {
|
|
16
|
+
ref: string;
|
|
17
|
+
};
|
|
18
|
+
declare function updateWorkspace(prisma: Prisma): (call: {
|
|
19
|
+
request: UpdateWorkspaceRequest;
|
|
20
|
+
}, callback: (error: GrpcErrorMessage, response?: UpdateWorkspaceResponse) => void) => Promise<void>;
|
|
21
|
+
export { updateWorkspace };
|
|
@@ -0,0 +1,76 @@
|
|
|
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.updateWorkspace = void 0;
|
|
13
|
+
/*
|
|
14
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
|
+
* http://github.com/fonoster/fonoster
|
|
16
|
+
*
|
|
17
|
+
* This file is part of Fonoster
|
|
18
|
+
*
|
|
19
|
+
* Licensed under the MIT License (the "License");
|
|
20
|
+
* you may not use this file except in compliance with
|
|
21
|
+
* the License. You may obtain a copy of the License at
|
|
22
|
+
*
|
|
23
|
+
* https://opensource.org/licenses/MIT
|
|
24
|
+
*
|
|
25
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
26
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
27
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
|
+
* See the License for the specific language governing permissions and
|
|
29
|
+
* limitations under the License.
|
|
30
|
+
*/
|
|
31
|
+
const common_1 = require("@fonoster/common");
|
|
32
|
+
const logger_1 = require("@fonoster/logger");
|
|
33
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
34
|
+
const zod_1 = require("zod");
|
|
35
|
+
const isWorkspaceMember_1 = require("./isWorkspaceMember");
|
|
36
|
+
const getTokenFromCall_1 = require("../utils/getTokenFromCall");
|
|
37
|
+
const getUserRefFromToken_1 = require("../utils/getUserRefFromToken");
|
|
38
|
+
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
|
+
function updateWorkspace(prisma) {
|
|
44
|
+
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
try {
|
|
46
|
+
const validatedRequest = UpdateWorkspaceRequestSchema.parse(call.request);
|
|
47
|
+
const token = (0, getTokenFromCall_1.getTokenFromCall)(call);
|
|
48
|
+
const userRef = (0, getUserRefFromToken_1.getUserRefFromToken)(token);
|
|
49
|
+
const { ref, name } = validatedRequest;
|
|
50
|
+
logger.verbose("call to updateWorkspace", { ref, userRef });
|
|
51
|
+
const isMember = yield (0, isWorkspaceMember_1.isWorkspaceMember)(prisma)(ref, userRef);
|
|
52
|
+
if (!isMember) {
|
|
53
|
+
callback({
|
|
54
|
+
code: grpc_js_1.status.PERMISSION_DENIED,
|
|
55
|
+
message: "User is not a member of the workspace"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
yield prisma.workspace.update({
|
|
59
|
+
where: {
|
|
60
|
+
ref
|
|
61
|
+
},
|
|
62
|
+
data: {
|
|
63
|
+
name
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const response = {
|
|
67
|
+
ref
|
|
68
|
+
};
|
|
69
|
+
callback(null, response);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
(0, common_1.handleError)(error, callback);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.updateWorkspace = updateWorkspace;
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fonoster/identity",
|
|
3
|
+
"version": "0.6.1-alpha.0",
|
|
4
|
+
"description": "Identity service for Fonoster",
|
|
5
|
+
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
|
+
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "dist/index",
|
|
9
|
+
"types": "dist/index",
|
|
10
|
+
"directories": {
|
|
11
|
+
"src": "src",
|
|
12
|
+
"test": "test"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
16
|
+
"build": "tsc -b tsconfig.json",
|
|
17
|
+
"clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"fonoster": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@fonoster/common": "^0.6.1-alpha.0",
|
|
24
|
+
"@fonoster/logger": "^0.6.1-alpha.0",
|
|
25
|
+
"@grpc/grpc-js": "^1.10.6",
|
|
26
|
+
"@prisma/client": "^5.14.0",
|
|
27
|
+
"jsonwebtoken": "^9.0.2",
|
|
28
|
+
"jwt-decode": "^4.0.0",
|
|
29
|
+
"nanoid": "^3.3.6",
|
|
30
|
+
"prisma-field-encryption": "^1.5.2",
|
|
31
|
+
"zod": "^3.23.8"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/fonoster/fonoster.git"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/fonoster/fonoster/issues"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/jsonwebtoken": "^9.0.6"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "2cdd1508146747550fe048c35d9a010d04f6d3aa"
|
|
50
|
+
}
|