Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+76
@@ -0,0 +1,76 @@
|
||||
import {
|
||||
buildExportJob,
|
||||
enqueueJob,
|
||||
queueNames,
|
||||
resolveRedisConnectionOptions,
|
||||
resolveRedisConnectionOptionsFromProcessEnv,
|
||||
type RedisConnectionEnv,
|
||||
type TypedQueue,
|
||||
} from "@hivegrid/queue";
|
||||
|
||||
export type GdprExportScope = "user_self" | "tenant_full";
|
||||
|
||||
export type EnqueueGdprExportInput = {
|
||||
exportJobId: string;
|
||||
tenantId: string;
|
||||
requestedByUserId: string;
|
||||
scope: GdprExportScope;
|
||||
targetUserId?: string | null;
|
||||
requestId?: string;
|
||||
};
|
||||
|
||||
export type EnqueueGdprExportResult = { enqueued: true; jobId?: string } | { enqueued: false; reason: "queue-unavailable" };
|
||||
|
||||
type Dependencies = {
|
||||
env?: RedisConnectionEnv;
|
||||
queue?: TypedQueue<typeof queueNames.exports>;
|
||||
};
|
||||
|
||||
export const GDPR_USER_SELF_EXPORT_TYPE = "gdpr_user_self";
|
||||
export const GDPR_TENANT_FULL_EXPORT_TYPE = "gdpr_tenant_full";
|
||||
|
||||
export async function enqueueGdprExport(input: EnqueueGdprExportInput, dependencies: Dependencies = {}): Promise<EnqueueGdprExportResult> {
|
||||
let queue = dependencies.queue;
|
||||
let shouldCloseQueue = false;
|
||||
const connection = queue
|
||||
? undefined
|
||||
: dependencies.env
|
||||
? resolveRedisConnectionOptions({ env: dependencies.env })
|
||||
: resolveRedisConnectionOptionsFromProcessEnv();
|
||||
|
||||
if (!queue && !connection) {
|
||||
return { enqueued: false, reason: "queue-unavailable" };
|
||||
}
|
||||
|
||||
if (!queue && connection) {
|
||||
const queueRuntimeModule = "@hivegrid/queue/runtime";
|
||||
const { createQueue } = (await import(/* @vite-ignore */ queueRuntimeModule)) as typeof import("@hivegrid/queue/runtime");
|
||||
queue = createQueue(queueNames.exports, { connection });
|
||||
shouldCloseQueue = true;
|
||||
}
|
||||
|
||||
if (!queue) {
|
||||
return { enqueued: false, reason: "queue-unavailable" };
|
||||
}
|
||||
|
||||
try {
|
||||
const descriptor = buildExportJob({
|
||||
exportJobId: input.exportJobId,
|
||||
tenantId: input.tenantId,
|
||||
requestedByUserId: input.requestedByUserId,
|
||||
exportType: input.scope === "tenant_full" ? GDPR_TENANT_FULL_EXPORT_TYPE : GDPR_USER_SELF_EXPORT_TYPE,
|
||||
format: "json",
|
||||
requestId: input.requestId,
|
||||
metadata: {
|
||||
scope: input.scope,
|
||||
...(input.targetUserId ? { targetUserId: input.targetUserId } : {}),
|
||||
},
|
||||
});
|
||||
const job = await enqueueJob(queue, descriptor, { tenantId: input.tenantId });
|
||||
return { enqueued: true, jobId: typeof job.id === "string" ? job.id : undefined };
|
||||
} finally {
|
||||
if (shouldCloseQueue && queue) {
|
||||
await queue.close().catch(() => {});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user