@fonoster/identity 0.7.4 → 0.7.7
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/README.md +163 -2
- package/dist/apikeys/createApiKey.d.ts +3 -3
- package/dist/apikeys/createApiKey.js +24 -36
- package/dist/apikeys/deleteApiKey.d.ts +2 -3
- package/dist/apikeys/deleteApiKey.js +11 -21
- package/dist/apikeys/listApiKeys.d.ts +2 -3
- package/dist/apikeys/listApiKeys.js +21 -1
- package/dist/apikeys/regenerateApiKey.d.ts +2 -3
- package/dist/apikeys/regenerateApiKey.js +18 -26
- package/dist/db.d.ts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/exchanges/exchangeApiKey.d.ts +2 -19
- package/dist/exchanges/exchangeApiKey.js +12 -22
- package/dist/exchanges/exchangeCredentials.d.ts +2 -19
- package/dist/exchanges/exchangeCredentials.js +12 -22
- package/dist/exchanges/exchangeRefreshToken.d.ts +2 -16
- package/dist/exchanges/exchangeRefreshToken.js +11 -19
- package/dist/exchanges/index.d.ts +1 -1
- package/dist/exchanges/index.js +1 -1
- package/dist/exchanges/payloads/users/index.d.ts +1 -1
- package/dist/exchanges/payloads/users/index.js +1 -1
- package/dist/exchanges/types.d.ts +11 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/invites/index.d.ts +1 -1
- package/dist/invites/index.js +1 -1
- package/dist/invites/sendInvite.d.ts +1 -1
- package/dist/roles.d.ts +1 -1
- package/dist/roles.js +1 -1
- package/dist/service.d.ts +37 -57
- package/dist/users/createUser.d.ts +2 -3
- package/dist/users/createUser.js +16 -28
- package/dist/users/deleteUser.d.ts +3 -3
- package/dist/users/deleteUser.js +14 -20
- package/dist/users/getUser.d.ts +2 -3
- package/dist/users/getUser.js +20 -23
- package/dist/users/index.d.ts +1 -1
- package/dist/users/index.js +1 -1
- package/dist/users/updateUser.d.ts +2 -3
- package/dist/users/updateUser.js +23 -34
- package/dist/users/upsertDefaultUser.d.ts +2 -2
- package/dist/users/upsertDefaultUser.js +2 -2
- package/dist/utils/generateAccessKeyId.d.ts +1 -1
- package/dist/utils/getApiKeyByAccessKeyId.d.ts +3 -3
- package/dist/utils/getUserByEmail.d.ts +2 -2
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.js +5 -5
- package/dist/utils/withAccess.js +10 -34
- package/dist/workspaces/createWorkspace.d.ts +2 -3
- package/dist/workspaces/createWorkspace.js +17 -25
- package/dist/workspaces/deleteWorkspace.d.ts +2 -3
- package/dist/workspaces/deleteWorkspace.js +14 -17
- package/dist/workspaces/getWorkspace.d.ts +2 -3
- package/dist/workspaces/getWorkspace.js +20 -23
- package/dist/workspaces/index.d.ts +2 -2
- package/dist/workspaces/index.js +2 -2
- package/dist/workspaces/inviteUserToWorkspace.d.ts +2 -3
- package/dist/workspaces/inviteUserToWorkspace.js +57 -70
- package/dist/workspaces/listWorkspaces.d.ts +1 -2
- package/dist/workspaces/listWorkspaces.js +21 -1
- package/dist/workspaces/removeUserFromWorkspace.d.ts +2 -3
- package/dist/workspaces/removeUserFromWorkspace.js +34 -37
- package/dist/workspaces/resendWorkspaceMembershipInvitation.d.ts +2 -3
- package/dist/workspaces/resendWorkspaceMembershipInvitation.js +47 -50
- package/dist/workspaces/updateWorkspace.d.ts +2 -3
- package/dist/workspaces/updateWorkspace.js +21 -30
- package/package.json +5 -5
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
-
import { ResendWorkspaceMembershipInvitationRequest, ResendWorkspaceMembershipInvitationResponse } from "@fonoster/types";
|
|
3
2
|
import { Prisma } from "../db";
|
|
4
3
|
import { IdentityConfig } from "../exchanges/types";
|
|
5
4
|
import { SendInvite } from "../invites/sendInvite";
|
|
6
5
|
declare function resendWorkspaceMembershipInvitation(prisma: Prisma, identityConfig: IdentityConfig, sendInvite: SendInvite): (call: {
|
|
7
|
-
request:
|
|
8
|
-
}, callback: (error
|
|
6
|
+
request: unknown;
|
|
7
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
9
8
|
export { resendWorkspaceMembershipInvitation };
|
|
@@ -38,60 +38,57 @@ const getTokenFromCall_1 = require("../utils/getTokenFromCall");
|
|
|
38
38
|
const getUserRefFromToken_1 = require("../utils/getUserRefFromToken");
|
|
39
39
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
40
40
|
function resendWorkspaceMembershipInvitation(prisma, identityConfig, sendInvite) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
});
|
|
41
|
+
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const token = (0, getTokenFromCall_1.getTokenFromCall)(call);
|
|
43
|
+
const adminRef = (0, getUserRefFromToken_1.getUserRefFromToken)(token);
|
|
44
|
+
const accessKeyId = (0, utils_1.getAccessKeyIdFromCall)(call);
|
|
45
|
+
const workspace = yield prisma.workspace.findUnique({
|
|
46
|
+
where: {
|
|
47
|
+
accessKeyId
|
|
80
48
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
49
|
+
});
|
|
50
|
+
const { ref: workspaceRef } = workspace;
|
|
51
|
+
const { request } = call;
|
|
52
|
+
const { userRef: inviteeRef } = request;
|
|
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"
|
|
88
63
|
});
|
|
89
|
-
|
|
64
|
+
}
|
|
65
|
+
const member = yield prisma.workspaceMember.findFirst({
|
|
66
|
+
where: {
|
|
67
|
+
workspaceRef,
|
|
90
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}`
|
|
91
79
|
});
|
|
92
80
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
+
});
|
|
96
92
|
});
|
|
93
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.resendWorkspaceMembershipInvitationRequestSchema);
|
|
97
94
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
-
import { BaseApiObject, UpdateWorkspaceRequest } from "@fonoster/types";
|
|
3
2
|
import { Prisma } from "../db";
|
|
4
3
|
declare function updateWorkspace(prisma: Prisma): (call: {
|
|
5
|
-
request:
|
|
6
|
-
}, callback: (error
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
6
|
export { updateWorkspace };
|
|
@@ -31,42 +31,33 @@ 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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
}
|
|
39
|
+
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const token = (0, getTokenFromCall_1.getTokenFromCall)(call);
|
|
41
|
+
const userRef = (0, getUserRefFromToken_1.getUserRefFromToken)(token);
|
|
42
|
+
const { request } = call;
|
|
43
|
+
const { ref, name } = request;
|
|
44
|
+
logger.verbose("call to updateWorkspace", { ref, userRef });
|
|
45
|
+
const isMember = yield (0, isWorkspaceMember_1.isWorkspaceMember)(prisma)(ref, userRef);
|
|
46
|
+
if (!isMember) {
|
|
47
|
+
callback({
|
|
48
|
+
code: grpc_js_1.status.PERMISSION_DENIED,
|
|
49
|
+
message: "User is not a member of the workspace"
|
|
65
50
|
});
|
|
66
|
-
callback(null, { ref });
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
(0, common_1.handleError)(error, callback);
|
|
70
51
|
}
|
|
52
|
+
yield prisma.workspace.update({
|
|
53
|
+
where: {
|
|
54
|
+
ref
|
|
55
|
+
},
|
|
56
|
+
data: {
|
|
57
|
+
name
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
callback(null, { ref });
|
|
71
61
|
});
|
|
62
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.updateWorkspaceRequestSchema);
|
|
72
63
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/identity",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
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.
|
|
24
|
-
"@fonoster/logger": "^0.7.
|
|
25
|
-
"@fonoster/types": "^0.7.
|
|
23
|
+
"@fonoster/common": "^0.7.7",
|
|
24
|
+
"@fonoster/logger": "^0.7.5",
|
|
25
|
+
"@fonoster/types": "^0.7.5",
|
|
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": "
|
|
50
|
+
"gitHead": "f1cfa987ec4221dad9900bc377cccee49221164a"
|
|
51
51
|
}
|