Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

pieces-cache-db-*.sqlite

# compiled output
dist
tmp
Expand Down
2 changes: 0 additions & 2 deletions packages/pieces/community/framework/src/lib/piece-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const PieceBase = Type.Object({
displayName: Type.String(),
logoUrl: Type.String(),
description: Type.String(),
projectId: Type.Optional(Type.String()),
authors: Type.Array(Type.String()),
platformId: Type.Optional(Type.String()),
directoryPath: Type.Optional(Type.String()),
Expand All @@ -32,7 +31,6 @@ export type PieceBase = {
displayName: string;
logoUrl: string;
description: string;
projectId?: ProjectId;
platformId?: string;
authors: string[],
directoryPath?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ const columns: ColumnDef<RowDataWithActions<PieceMetadataModelSummary>>[] = [
header: ({ column }) => <DataTableColumnHeader column={column} title="" />,
cell: ({ row }) => {
if (
row.original.pieceType !== PieceType.CUSTOM ||
isNil(row.original.projectId)
row.original.pieceType !== PieceType.CUSTOM
) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import {
ApplicationEventName,
ResetPasswordRequestBody,
VerifyEmailRequestBody } from '@activepieces/ee-shared'
import { securityAccess } from '@activepieces/server-shared'
import { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox'
import { applicationEvents } from '../../../helper/application-events'
import { enterpriseLocalAuthnService } from './enterprise-local-authn-service'

export const enterpriseLocalAuthnController: FastifyPluginAsyncTypebox = async (
app,
) => {
app.post('/verify-email', VerifyEmailRequest, async (req) => {
applicationEvents(req.log).sendUserEvent(req, {
action: ApplicationEventName.USER_EMAIL_VERIFIED,
data: {},
})
await enterpriseLocalAuthnService(req.log).verifyEmail(req.body)
})

app.post('/reset-password', ResetPasswordRequest, async (req) => {
applicationEvents(req.log).sendUserEvent(req, {
action: ApplicationEventName.USER_PASSWORD_RESET,
data: {},
})
await enterpriseLocalAuthnService(req.log).resetPassword(req.body)
})
})
}

const VerifyEmailRequest = {
Expand All @@ -43,4 +33,4 @@ const ResetPasswordRequest = {
schema: {
body: ResetPasswordRequestBody,
},
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import {
ApplicationEvent,
ApplicationEventName,
OtpType,
ResetPasswordRequestBody,
VerifyEmailRequestBody,
} from '@activepieces/ee-shared'
import { ActivepiecesError, ErrorCode, UserId, UserIdentity } from '@activepieces/shared'
import { ActivepiecesError, ErrorCode, isNil, UserId, UserIdentity } from '@activepieces/shared'
import { FastifyBaseLogger } from 'fastify'
import { userIdentityService } from '../../../authentication/user-identity/user-identity-service'
import { applicationEvents } from '../../../helper/application-events'
import { userService } from '../../../user/user-service'
import { otpService } from '../otp/otp-service'

export const enterpriseLocalAuthnService = (log: FastifyBaseLogger) => ({
async verifyEmail({ identityId, otp }: VerifyEmailRequestBody): Promise<UserIdentity> {
await confirmOtp({
const isOtpValid = await otpService(log).confirm({
identityId,
otp,
otpType: OtpType.EMAIL_VERIFICATION,
log,
type: OtpType.EMAIL_VERIFICATION,
value: otp,
})

if (!isOtpValid) {
throw new ActivepiecesError({
code: ErrorCode.INVALID_OTP,
params: {},
})
}

await sendAuditLogForIdentity(identityId, {
action: ApplicationEventName.USER_EMAIL_VERIFIED,
data: {},
}, log)

return userIdentityService(log).verify(identityId)
},

Expand All @@ -25,43 +40,47 @@ export const enterpriseLocalAuthnService = (log: FastifyBaseLogger) => ({
otp,
newPassword,
}: ResetPasswordRequestBody): Promise<void> {
await confirmOtp({
const isOtpValid = await otpService(log).confirm({
identityId,
otp,
otpType: OtpType.PASSWORD_RESET,
log,
type: OtpType.PASSWORD_RESET,
value: otp,
})

if (!isOtpValid) {
throw new ActivepiecesError({
code: ErrorCode.INVALID_OTP,
params: {},
})
}

await sendAuditLogForIdentity(identityId, {
action: ApplicationEventName.USER_PASSWORD_RESET,
data: {},
}, log)

await userIdentityService(log).updatePassword({
id: identityId,
newPassword,
})
},
})

const confirmOtp = async ({
identityId,
otp,
otpType,
log,
}: ConfirmOtpParams): Promise<void> => {
const isOtpValid = await otpService(log).confirm({
identityId,
type: otpType,
value: otp,
})

if (!isOtpValid) {
throw new ActivepiecesError({
code: ErrorCode.INVALID_OTP,
params: {},
})
const sendAuditLogForIdentity = async (
identityId: UserId,
event: Pick<ApplicationEvent, 'action' | 'data'>,
log: FastifyBaseLogger,
): Promise<void> => {
const users = await userService.getUsersByIdentityId({ identityId })
for (const { id, platformId } of users) {
if (isNil(platformId)) {
continue
}
applicationEvents(log).sendUserEvent(
{
platformId,
userId: id,
},
event as ApplicationEvent,
)
}
}

type ConfirmOtpParams = {
identityId: UserId
otp: string
otpType: OtpType
log: FastifyBaseLogger
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ export const flowMigrations = {
},
}

export const migrateFlowVersionTemplate = async ({ trigger, schemaVersion, notes, valid }: Pick<FlowVersionTemplate, 'trigger' | 'schemaVersion' | 'notes' | 'valid'>): Promise<FlowVersionTemplate> => {
export const migrateFlowVersionTemplate = async ({ trigger, schemaVersion, notes, valid, displayName }: Pick<FlowVersionTemplate, 'trigger' | 'schemaVersion' | 'notes' | 'valid' | 'displayName'>): Promise<FlowVersionTemplate> => {
return flowMigrations.apply({
agentIds: [],
connectionIds: [],
created: new Date().toISOString(),
displayName: '',
displayName,
flowId: '',
id: '',
updated: new Date().toISOString(),
Expand Down
2 changes: 2 additions & 0 deletions packages/server/api/src/app/flows/flow/flow.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ export const flowController: FastifyPluginAsyncTypebox = async (app) => {
preValidation: async (request) => {
if (request.body?.type === FlowOperationType.IMPORT_FLOW) {
const migratedFlowTemplate = await migrateFlowVersionTemplate({
displayName: request.body.request.displayName,
trigger: request.body.request.trigger,
schemaVersion: request.body.request.schemaVersion,
notes: request.body.request.notes ?? [],
valid: false,
})
request.body.request = {
...request.body.request,
displayName: migratedFlowTemplate.displayName,
trigger: migratedFlowTemplate.trigger,
schemaVersion: migratedFlowTemplate.schemaVersion,
notes: migratedFlowTemplate.notes,
Expand Down
Loading
Loading