Skip to content

Commit

Permalink
Feat/newjitsu/profile builder UI (jitsucom#1137)
Browse files Browse the repository at this point in the history
ProfileBuilder UI
  • Loading branch information
absorbb authored Oct 28, 2024
1 parent 7e4261a commit bc311a7
Show file tree
Hide file tree
Showing 59 changed files with 4,908 additions and 649 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
jobs:
build:
name: Build Project
container: jitsucom/node18builder:latest
container: jitsucom/node22builder:latest
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
Expand Down
15 changes: 3 additions & 12 deletions builder.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@

# Run `docker login`
# Build & push it with
# docker buildx build --platform linux/amd64 . -f builder.Dockerfile --push -t jitsucom/node18builder:latest
# docker buildx build --platform linux/amd64 . -f builder.Dockerfile --push -t jitsucom/node22builder:latest

FROM debian:bullseye-slim
FROM node:22-bookworm
RUN apt-get update
# Telnet is useful for debugging, and we need curl for Node 16
# Telnet is useful for debugging, and we need curl for Node
RUN apt-get install git curl telnet python3 ca-certificates gnupg g++ make -y

#Install node 18, see https://github.com/nodesource/distributions#debian-and-ubuntu-based-distributions
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update

#We need bash for pnpm setup
RUN apt-get install nodejs bash -y

RUN npm -g install pnpm

#Should be the same as playwrite version in ./libs/jitsu-js/package.json
Expand Down
18 changes: 15 additions & 3 deletions cli/jitsu-cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,20 @@ async function deployFunction(
process.exit(1);
} else {
const existing = (await res.json()) as any;
existingFunctionId = existing.objects.find(f => f.slug === meta.slug)?.id;
existingFunctionId = existing.objects.find(f => f.slug === meta.slug || f.id === meta.id)?.id;
}
}

let functionPayload = {};
if (kind === "profile") {
functionPayload = {
draft: code,
kind: "profile",
};
} else {
functionPayload = {
code,
};
}
if (!existingFunctionId) {
const id = cuid();
const res = await fetch(`${host}/api/${workspace.id}/config/function`, {
Expand All @@ -211,7 +221,9 @@ async function deployFunction(
description: meta.description,
version: packageJson.version,
name: meta.name,
// we always add code to the initial function creation
code,
...functionPayload,
}),
});
if (!res.ok) {
Expand All @@ -236,7 +248,7 @@ async function deployFunction(
description: meta.description,
version: packageJson.version,
name: meta.name,
code,
...functionPayload,
}),
});
if (!res.ok) {
Expand Down
16 changes: 15 additions & 1 deletion cli/jitsu-cli/src/lib/compiled-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type CompiledFunction = {
func: JitsuFunction;
meta: {
slug: string;
id?: string;
name?: string;
description?: string;
};
Expand Down Expand Up @@ -47,16 +48,29 @@ export async function getFunctionFromFilePath(
assertTrue(typeof exports.default === "function", `Default export from ${filePath} is not a function`);

let name = exports.config?.name || exports.config?.slug || getSlug(filePath);
let id = exports.config?.id;
if (kind === "profile") {
const profileBuilderId = exports.config?.profileBuilderId;
const profileBuilder = profileBuilders.find(pb => pb.id === profileBuilderId);
name = `${profileBuilder.name} profile function`;
if (!profileBuilder) {
throw new Error(
`Cannot find profile builder with id ${profileBuilderId} for profile function ${filePath}. Please setup Profile Builder in UI first.`
);
}
name = name || `${profileBuilder.name} function`;
id = id || profileBuilder.functions[0]?.functionId;
if (!id) {
throw new Error(
`Cannot find function id for profile function ${filePath}. Please setup Profile Builder in UI first.`
);
}
}

return {
func: exports.default,
meta: {
slug: exports.config?.slug || getSlug(filePath),
id: id,
name: name,
description: exports.config?.description,
},
Expand Down
2 changes: 1 addition & 1 deletion libs/core-functions/__tests__/udf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default udf;
type: "page",
context: {},
},
config: {
variables: {
prop1: "test_prop1",
},
store: {
Expand Down
4 changes: 2 additions & 2 deletions libs/core-functions/src/functions/lib/mongodb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getLog, getSingleton, parseNumber, requireDefined } from "juava";
import { MongoClient, ObjectId } from "mongodb";
import { MongoClient, MongoClientOptions, ObjectId } from "mongodb";
import { AnalyticsServerEvent } from "@jitsu/protocols/analytics";
import { AnonymousEventsStore } from "@jitsu/protocols/functions";

Expand All @@ -22,7 +22,7 @@ async function createClient() {

// Create a new MongoClient
const client = new MongoClient(mongodbURL, {
compressors: ["zstd"],
compressors: process.env.MONGODB_NETWORK_COMPRESSION ? process.env.MONGODB_NETWORK_COMPRESSION : ["zstd"],
serverSelectionTimeoutMS: 60000,
maxPoolSize: 32,
connectTimeoutMS: 60000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ function isDropResult(result) {
async function runChain(
chain,
ctx,
events,
user
user,
ctx
) {
const execLog = [];
const f = chain[0];
let result = undefined;
try {
result = await f.f(ctx, events, user);
result = await f.f(events, user, ctx);
} catch (err) {
if (err.name === DropRetryErrorName) {
result = "drop";
Expand All @@ -64,10 +64,10 @@ async function runChain(
return {result, execLog};
}
const wrappedFunctionChain = async function (ctx, events, user) {
const wrappedFunctionChain = async function (events, user, ctx) {
let chain = [];
//** @UDF_FUNCTIONS_CHAIN **//
const chainRes = await runChain(chain, ctx, events, user);
const chainRes = await runChain(chain, events, user, ctx);
checkError(chainRes);
return chainRes.result;
};
Expand Down Expand Up @@ -155,7 +155,7 @@ const wrappedUserFunction = (id, f, funcCtx) => {
};
}
return async function (c, events, user) {
return async function (events, user, c) {
const fetchLogEnabled = _jitsu_fetch_log_level !== "debug" || (funcCtx.function.debugTill && funcCtx.function.debugTill > new Date());
let ftch = fetch
if (fetchLogEnabled) {
Expand All @@ -170,7 +170,7 @@ const wrappedUserFunction = (id, f, funcCtx) => {
store,
fetch: ftch,
};
return await f(ctx, events, user);
return await f(events, user, ctx);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function isDropResult(result) {

async function runChain(
chain,
ctx,
events,
user
user,
ctx
) {
const execLog = [];
const f = chain[0];
let result = undefined;
try {
result = await f.f(ctx, events, user);
result = await f.f(events, user, ctx);
} catch (err) {
if (err.name === DropRetryErrorName) {
result = "drop";
Expand All @@ -51,10 +51,10 @@ async function runChain(
return {result, execLog};
}

const wrappedFunctionChain = async function (ctx, events, user) {
const wrappedFunctionChain = async function (events, user, ctx) {
let chain = [];
//** @UDF_FUNCTIONS_CHAIN **//
const chainRes = await runChain(chain, ctx, events, user);
const chainRes = await runChain(chain, events, user, ctx);
checkError(chainRes);
return chainRes.result;
};
Expand Down Expand Up @@ -142,7 +142,7 @@ const wrappedUserFunction = (id, f, funcCtx) => {
};
}

return async function (c, events, user) {
return async function (events, user, c) {
const fetchLogEnabled = _jitsu_fetch_log_level !== "debug" || (funcCtx.function.debugTill && funcCtx.function.debugTill > new Date());
let ftch = fetch
if (fetchLogEnabled) {
Expand All @@ -157,7 +157,7 @@ const wrappedUserFunction = (id, f, funcCtx) => {
store,
fetch: ftch,
};
return await f(ctx, events, user);
return await f(events, user, ctx);
}
};

Expand Down
Loading

0 comments on commit bc311a7

Please sign in to comment.