mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 10:26:16 +00:00
feat: remove plain and move to pylon
This commit is contained in:
Generated
-29
@@ -49,7 +49,6 @@
|
|||||||
"@sindresorhus/slugify": "1.1.0",
|
"@sindresorhus/slugify": "1.1.0",
|
||||||
"@slack/oauth": "^3.0.1",
|
"@slack/oauth": "^3.0.1",
|
||||||
"@slack/web-api": "^7.3.4",
|
"@slack/web-api": "^7.3.4",
|
||||||
"@team-plain/typescript-sdk": "^4.6.1",
|
|
||||||
"@ucast/mongo2js": "^1.3.4",
|
"@ucast/mongo2js": "^1.3.4",
|
||||||
"ajv": "^8.12.0",
|
"ajv": "^8.12.0",
|
||||||
"argon2": "^0.31.2",
|
"argon2": "^0.31.2",
|
||||||
@@ -5678,14 +5677,6 @@
|
|||||||
"uuid": "dist/bin/uuid"
|
"uuid": "dist/bin/uuid"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@graphql-typed-document-node/core": {
|
|
||||||
"version": "3.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz",
|
|
||||||
"integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==",
|
|
||||||
"peerDependencies": {
|
|
||||||
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@grpc/grpc-js": {
|
"node_modules/@grpc/grpc-js": {
|
||||||
"version": "1.12.2",
|
"version": "1.12.2",
|
||||||
"resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.12.2.tgz",
|
"resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.12.2.tgz",
|
||||||
@@ -9970,18 +9961,6 @@
|
|||||||
"optional": true,
|
"optional": true,
|
||||||
"peer": true
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/@team-plain/typescript-sdk": {
|
|
||||||
"version": "4.6.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@team-plain/typescript-sdk/-/typescript-sdk-4.6.1.tgz",
|
|
||||||
"integrity": "sha512-Uy9QJXu9U7bJb6WXL9sArGk7FXPpzdqBd6q8tAF1vexTm8fbTJRqcikTKxGtZmNADt+C2SapH3cApM4oHpO4lQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"@graphql-typed-document-node/core": "^3.2.0",
|
|
||||||
"ajv": "^8.12.0",
|
|
||||||
"ajv-formats": "^2.1.1",
|
|
||||||
"graphql": "^16.6.0",
|
|
||||||
"zod": "3.22.4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@techteamer/ocsp": {
|
"node_modules/@techteamer/ocsp": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@techteamer/ocsp/-/ocsp-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/@techteamer/ocsp/-/ocsp-1.0.1.tgz",
|
||||||
@@ -15180,14 +15159,6 @@
|
|||||||
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/graphql": {
|
|
||||||
"version": "16.9.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz",
|
|
||||||
"integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==",
|
|
||||||
"engines": {
|
|
||||||
"node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/gtoken": {
|
"node_modules/gtoken": {
|
||||||
"version": "7.1.0",
|
"version": "7.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-7.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-7.1.0.tgz",
|
||||||
|
|||||||
@@ -157,7 +157,6 @@
|
|||||||
"@sindresorhus/slugify": "1.1.0",
|
"@sindresorhus/slugify": "1.1.0",
|
||||||
"@slack/oauth": "^3.0.1",
|
"@slack/oauth": "^3.0.1",
|
||||||
"@slack/web-api": "^7.3.4",
|
"@slack/web-api": "^7.3.4",
|
||||||
"@team-plain/typescript-sdk": "^4.6.1",
|
|
||||||
"@ucast/mongo2js": "^1.3.4",
|
"@ucast/mongo2js": "^1.3.4",
|
||||||
"ajv": "^8.12.0",
|
"ajv": "^8.12.0",
|
||||||
"argon2": "^0.31.2",
|
"argon2": "^0.31.2",
|
||||||
|
|||||||
@@ -166,8 +166,7 @@ const envSchema = z
|
|||||||
OTEL_COLLECTOR_BASIC_AUTH_PASSWORD: zpStr(z.string().optional()),
|
OTEL_COLLECTOR_BASIC_AUTH_PASSWORD: zpStr(z.string().optional()),
|
||||||
OTEL_EXPORT_TYPE: z.enum(["prometheus", "otlp"]).optional(),
|
OTEL_EXPORT_TYPE: z.enum(["prometheus", "otlp"]).optional(),
|
||||||
|
|
||||||
PLAIN_API_KEY: zpStr(z.string().optional()),
|
PYLON_API_KEY: zpStr(z.string().optional()),
|
||||||
PLAIN_WISH_LABEL_IDS: zpStr(z.string().optional()),
|
|
||||||
DISABLE_AUDIT_LOG_GENERATION: zodStrBool.default("false"),
|
DISABLE_AUDIT_LOG_GENERATION: zodStrBool.default("false"),
|
||||||
SSL_CLIENT_CERTIFICATE_HEADER_KEY: zpStr(z.string().optional()).default("x-ssl-client-cert"),
|
SSL_CLIENT_CERTIFICATE_HEADER_KEY: zpStr(z.string().optional()).default("x-ssl-client-cert"),
|
||||||
WORKFLOW_SLACK_CLIENT_ID: zpStr(z.string().optional()),
|
WORKFLOW_SLACK_CLIENT_ID: zpStr(z.string().optional()),
|
||||||
|
|||||||
@@ -1242,7 +1242,8 @@ export const registerRoutes = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userEngagementService = userEngagementServiceFactory({
|
const userEngagementService = userEngagementServiceFactory({
|
||||||
userDAL
|
userDAL,
|
||||||
|
orgDAL
|
||||||
});
|
});
|
||||||
|
|
||||||
const slackService = slackServiceFactory({
|
const slackService = slackServiceFactory({
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const registerUserEngagementRouter = async (server: FastifyZodProvider) =
|
|||||||
},
|
},
|
||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
return server.services.userEngagement.createUserWish(req.permission.id, req.body.text);
|
return server.services.userEngagement.createUserWish(req.permission.id, req.permission.orgId, req.body.text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,87 +1,44 @@
|
|||||||
import { PlainClient } from "@team-plain/typescript-sdk";
|
import axios from "axios";
|
||||||
|
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { InternalServerError } from "@app/lib/errors";
|
import { InternalServerError } from "@app/lib/errors";
|
||||||
|
|
||||||
|
import { TOrgDALFactory } from "../org/org-dal";
|
||||||
import { TUserDALFactory } from "../user/user-dal";
|
import { TUserDALFactory } from "../user/user-dal";
|
||||||
|
|
||||||
type TUserEngagementServiceFactoryDep = {
|
type TUserEngagementServiceFactoryDep = {
|
||||||
userDAL: Pick<TUserDALFactory, "findById">;
|
userDAL: Pick<TUserDALFactory, "findById">;
|
||||||
|
orgDAL: Pick<TOrgDALFactory, "findById">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TUserEngagementServiceFactory = ReturnType<typeof userEngagementServiceFactory>;
|
export type TUserEngagementServiceFactory = ReturnType<typeof userEngagementServiceFactory>;
|
||||||
|
|
||||||
export const userEngagementServiceFactory = ({ userDAL }: TUserEngagementServiceFactoryDep) => {
|
export const userEngagementServiceFactory = ({ userDAL, orgDAL }: TUserEngagementServiceFactoryDep) => {
|
||||||
const createUserWish = async (userId: string, text: string) => {
|
const createUserWish = async (userId: string, orgId: string, text: string) => {
|
||||||
const user = await userDAL.findById(userId);
|
const user = await userDAL.findById(userId);
|
||||||
|
const org = await orgDAL.findById(orgId);
|
||||||
const appCfg = getConfig();
|
const appCfg = getConfig();
|
||||||
|
|
||||||
if (!appCfg.PLAIN_API_KEY) {
|
if (!appCfg.PYLON_API_KEY) {
|
||||||
throw new InternalServerError({
|
throw new InternalServerError({
|
||||||
message: "Plain is not configured."
|
message: "Pylon is not configured."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new PlainClient({
|
const request = axios.create({
|
||||||
apiKey: appCfg.PLAIN_API_KEY
|
baseURL: "https://api.usepylon.com",
|
||||||
});
|
headers: {
|
||||||
|
Authorization: `Bearer ${appCfg.PYLON_API_KEY}`
|
||||||
const customerUpsertRes = await client.upsertCustomer({
|
|
||||||
identifier: {
|
|
||||||
emailAddress: user.email
|
|
||||||
},
|
|
||||||
onCreate: {
|
|
||||||
fullName: `${user.firstName} ${user.lastName}`,
|
|
||||||
shortName: user.firstName,
|
|
||||||
email: {
|
|
||||||
email: user.email as string,
|
|
||||||
isVerified: user.isEmailVerified as boolean
|
|
||||||
},
|
|
||||||
|
|
||||||
externalId: user.id
|
|
||||||
},
|
|
||||||
|
|
||||||
onUpdate: {
|
|
||||||
fullName: {
|
|
||||||
value: `${user.firstName} ${user.lastName}`
|
|
||||||
},
|
|
||||||
shortName: {
|
|
||||||
value: user.firstName
|
|
||||||
},
|
|
||||||
email: {
|
|
||||||
email: user.email as string,
|
|
||||||
isVerified: user.isEmailVerified as boolean
|
|
||||||
},
|
|
||||||
externalId: {
|
|
||||||
value: user.id
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (customerUpsertRes.error) {
|
await request.post("/issues", {
|
||||||
throw new InternalServerError({ message: customerUpsertRes.error.message });
|
title: `New Wish From: ${user.firstName} ${user.lastName} (${org.name})`,
|
||||||
}
|
body_html: text,
|
||||||
|
requester_email: user.email,
|
||||||
const createThreadRes = await client.createThread({
|
requester_name: `${user.firstName} ${user.lastName} (${org.name})`,
|
||||||
title: "Wish",
|
tags: ["wish"]
|
||||||
customerIdentifier: {
|
|
||||||
externalId: customerUpsertRes.data.customer.externalId
|
|
||||||
},
|
|
||||||
components: [
|
|
||||||
{
|
|
||||||
componentText: {
|
|
||||||
text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
labelTypeIds: appCfg.PLAIN_WISH_LABEL_IDS?.split(",")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (createThreadRes.error) {
|
|
||||||
throw new InternalServerError({
|
|
||||||
message: createThreadRes.error.message
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
createUserWish
|
createUserWish
|
||||||
|
|||||||
Reference in New Issue
Block a user