mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
fc01deeefd
* chore(deps-dev): bump oxlint-tsgolint from 0.14.2 to 0.22.1 Bumps [oxlint-tsgolint](https://github.com/oxc-project/tsgolint) from 0.14.2 to 0.22.1. - [Release notes](https://github.com/oxc-project/tsgolint/releases) - [Commits](https://github.com/oxc-project/tsgolint/compare/v0.14.2...v0.22.1) --- updated-dependencies: - dependency-name: oxlint-tsgolint dependency-version: 0.22.1 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore: Switch tsconfig to bundler resolution for tsgolint 0.22.1 oxlint-tsgolint 0.22.1 removed support for moduleResolution=node10 (the alias for "node"). Switch to "bundler" with resolvePackageJsonExports disabled so packages whose exports field omits a types condition still resolve. Update markdown-it type imports to sub-paths since the package's .d.mts entry only re-exports a subset of named types. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix: Resolve type-aware lint errors caught by tsgolint 0.22.1 oxlint-tsgolint 0.22.1 catches several await-thenable, no-floating-promises, and no-meaningless-void-operator cases the prior 0.14.2 missed: - Drop redundant inner `await` from Promise.all([await x, await y]) call sites so the array entries are real Promises rather than already-resolved values. - Replace Promise.all wrappers around synchronous presenters (presentEvent, presentTemplate, presentPublicTeam) with plain map / direct calls. - Wrap non-promise branches of ternaries inside Promise.all with Promise.resolve so the array remains thenable across both arms. - Add `void` to the unawaited provider.connect() in the auth-failed retry chain, and remove `void` from the disconnect() call which returns void. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
177 lines
4.6 KiB
TypeScript
177 lines
4.6 KiB
TypeScript
import Router from "koa-router";
|
|
import type { WhereOptions } from "sequelize";
|
|
import { Op } from "sequelize";
|
|
import { IntegrationType, UserRole } from "@shared/types";
|
|
import auth from "@server/middlewares/authentication";
|
|
import { rateLimiter } from "@server/middlewares/rateLimiter";
|
|
import { transaction } from "@server/middlewares/transaction";
|
|
import validate from "@server/middlewares/validate";
|
|
import Integration from "@server/models/Integration";
|
|
import { authorize } from "@server/policies";
|
|
import { presentIntegration, presentPolicies } from "@server/presenters";
|
|
import type { APIContext } from "@server/types";
|
|
import { RateLimiterStrategy } from "@server/utils/RateLimiter";
|
|
import pagination from "../middlewares/pagination";
|
|
import * as T from "./schema";
|
|
|
|
const router = new Router();
|
|
|
|
router.post(
|
|
"integrations.list",
|
|
auth(),
|
|
pagination(),
|
|
validate(T.IntegrationsListSchema),
|
|
async (ctx: APIContext<T.IntegrationsListReq>) => {
|
|
const { direction, service, type, sort } = ctx.input.body;
|
|
const { user } = ctx.state.auth;
|
|
|
|
let where: WhereOptions<Integration> = {
|
|
teamId: user.teamId,
|
|
};
|
|
if (type) {
|
|
where = { ...where, type };
|
|
}
|
|
if (service) {
|
|
where = { ...where, service };
|
|
}
|
|
|
|
// Linked account is special as these are user-specific, other integrations are workspace-wide.
|
|
where = {
|
|
...where,
|
|
[Op.or]: [
|
|
{ userId: user.id, type: IntegrationType.LinkedAccount },
|
|
{
|
|
type: {
|
|
[Op.not]: IntegrationType.LinkedAccount,
|
|
},
|
|
},
|
|
],
|
|
};
|
|
|
|
const [integrations, total] = await Promise.all([
|
|
Integration.findAll({
|
|
where,
|
|
order: [[sort, direction]],
|
|
offset: ctx.state.pagination.offset,
|
|
limit: ctx.state.pagination.limit,
|
|
}),
|
|
Integration.count({
|
|
where,
|
|
}),
|
|
]);
|
|
|
|
ctx.body = {
|
|
pagination: { ...ctx.state.pagination, total },
|
|
data: integrations.map(presentIntegration),
|
|
policies: presentPolicies(user, integrations),
|
|
};
|
|
}
|
|
);
|
|
|
|
router.post(
|
|
"integrations.create",
|
|
rateLimiter(RateLimiterStrategy.TwentyFivePerMinute),
|
|
auth({ role: UserRole.Admin }),
|
|
validate(T.IntegrationsCreateSchema),
|
|
transaction(),
|
|
async (ctx: APIContext<T.IntegrationsCreateReq>) => {
|
|
const { type, service, settings } = ctx.input.body;
|
|
const { user } = ctx.state.auth;
|
|
|
|
authorize(user, "createIntegration", user.team);
|
|
|
|
const integration = await Integration.createWithCtx(ctx, {
|
|
userId: user.id,
|
|
teamId: user.teamId,
|
|
service,
|
|
settings,
|
|
type,
|
|
});
|
|
|
|
ctx.body = {
|
|
data: presentIntegration(integration),
|
|
policies: presentPolicies(user, [integration]),
|
|
};
|
|
}
|
|
);
|
|
|
|
router.post(
|
|
"integrations.info",
|
|
auth(),
|
|
validate(T.IntegrationsInfoSchema),
|
|
async (ctx: APIContext<T.IntegrationsInfoReq>) => {
|
|
const { id } = ctx.input.body;
|
|
const { user } = ctx.state.auth;
|
|
|
|
const integration = await Integration.findByPk(id, {
|
|
rejectOnEmpty: true,
|
|
});
|
|
authorize(user, "read", integration);
|
|
|
|
ctx.body = {
|
|
data: presentIntegration(integration),
|
|
policies: presentPolicies(user, [integration]),
|
|
};
|
|
}
|
|
);
|
|
|
|
router.post(
|
|
"integrations.update",
|
|
auth({ role: UserRole.Admin }),
|
|
validate(T.IntegrationsUpdateSchema),
|
|
transaction(),
|
|
async (ctx: APIContext<T.IntegrationsUpdateReq>) => {
|
|
const { id, events, settings } = ctx.input.body;
|
|
const { user } = ctx.state.auth;
|
|
const { transaction } = ctx.state;
|
|
|
|
const integration = await Integration.findByPk(id, {
|
|
transaction,
|
|
lock: transaction.LOCK.UPDATE,
|
|
});
|
|
authorize(user, "update", integration);
|
|
|
|
if (integration.type === IntegrationType.Post) {
|
|
integration.events = events.filter((event: string) =>
|
|
["documents.update", "documents.publish"].includes(event)
|
|
);
|
|
}
|
|
|
|
integration.settings = settings;
|
|
|
|
await integration.saveWithCtx(ctx);
|
|
|
|
ctx.body = {
|
|
data: presentIntegration(integration),
|
|
policies: presentPolicies(user, [integration]),
|
|
};
|
|
}
|
|
);
|
|
|
|
router.post(
|
|
"integrations.delete",
|
|
auth(),
|
|
validate(T.IntegrationsDeleteSchema),
|
|
transaction(),
|
|
async (ctx: APIContext<T.IntegrationsDeleteReq>) => {
|
|
const { id } = ctx.input.body;
|
|
const { user } = ctx.state.auth;
|
|
const { transaction } = ctx.state;
|
|
|
|
const integration = await Integration.findByPk(id, {
|
|
rejectOnEmpty: true,
|
|
transaction,
|
|
lock: transaction.LOCK.UPDATE,
|
|
});
|
|
authorize(user, "delete", integration);
|
|
|
|
await integration.destroyWithCtx(ctx);
|
|
|
|
ctx.body = {
|
|
success: true,
|
|
};
|
|
}
|
|
);
|
|
|
|
export default router;
|