Skip to content
Open
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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ permissions:
jobs:
ci:
name: CI
uses: NEARBuilders/everything-dev/.github/workflows/consumer-ci.yml@v2.0.0-rc.27
uses: NEARBuilders/everything-dev/.github/workflows/consumer-ci.yml@v2.0.0-rc.31
with:
working_directory: .
secrets: inherit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ permissions:
jobs:
deploy:
name: Deploy
uses: NEARBuilders/everything-dev/.github/workflows/consumer-deploy.yml@v2.0.0-rc.27
uses: NEARBuilders/everything-dev/.github/workflows/consumer-deploy.yml@v2.0.0-rc.31
with:
working_directory: .
verbose: ${{ inputs.verbose == true }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ permissions:
jobs:
deploy-staging:
name: Deploy Staging
uses: NEARBuilders/everything-dev/.github/workflows/consumer-staging.yml@v2.0.0-rc.27
uses: NEARBuilders/everything-dev/.github/workflows/consumer-staging.yml@v2.0.0-rc.31
with:
working_directory: .
verbose: ${{ inputs.verbose == true }}
Expand Down
18 changes: 18 additions & 0 deletions api/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ export const MemberCountSchema = z.object({
observedAt: z.iso.datetime().nullable(),
});

export const OnboardCommunitySchema = z.object({
name: z.string().min(1),
href: z.string(),
channels: z.array(z.object({ label: z.string().min(1), url: z.string() })),
});

export const AttendanceRecordSchema = z.object({
events: z.array(
z.object({
Expand Down Expand Up @@ -1029,6 +1035,18 @@ export const contract = oc.router({
.input(z.object({ nodeId: z.string() }))
.output(MemberCountSchema),

getOnboardCommunity: oc
.route({
method: "GET",
path: "/communities/by-organization/{organizationId}",
summary: "Get the community page and channels for an organization",
description:
"Public — for the auth plugin's joined screen: the community's City Node name, its page and its published discovery channels. Not found when the organization isn't an active community or has no City Node.",
})
.input(z.object({ organizationId: z.string().min(1) }))
.output(OnboardCommunitySchema)
.errors({ NOT_FOUND }),

getMyAttendance: oc
.route({
method: "GET",
Expand Down
2 changes: 1 addition & 1 deletion api/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as schema from "./schema";

export type Database = PgDatabase<PgQueryResultHKT, typeof schema>;

export { DatabaseError, unwrapDatabaseError } from "everything-dev/db";
export { DatabaseError } from "everything-dev/db";

export interface DatabaseDriver {
readonly db: Database;
Expand Down
11 changes: 7 additions & 4 deletions api/src/db/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Effect } from "effect";
import {
type DatabaseError,
detectDrift,
type LoadedMigrations,
loadMigrations as loadSharedMigrations,
type Migration,
type MigrationDatabase,
type MigrationReport,
type MigrationStorage,
runMigrations,
} from "everything-dev/db";

export type { DriftReport, LoadedMigrations } from "everything-dev/db";
export { detectDrift } from "everything-dev/db";
type MigrationDatabase = Parameters<typeof runMigrations>[0];
type MigrationReport = Effect.Success<ReturnType<typeof runMigrations>>;
export type DriftReport = Effect.Success<ReturnType<typeof detectDrift>>;

export type { LoadedMigrations };
export { detectDrift };

export const loadMigrations: Effect.Effect<LoadedMigrations, DatabaseError> = loadSharedMigrations({
fromDir: import.meta.dirname,
Expand Down
22 changes: 22 additions & 0 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,28 @@ export default createPlugin.withPlugins<PluginsClient>()({
return (yield* services.memberDirectory.latestCount(tenant.orgId)) ?? unavailable;
}),

getOnboardCommunity: builder.getOnboardCommunity.effect(function* ({ input }) {
const services = yield* ApiServices;
const notFound = () =>
new ORPCError("NOT_FOUND", { message: "No City Node for this organization" });
const tenant = yield* services.tenants.resolveTenantByOrgId(input.organizationId);
if (!tenant || tenant.status !== "active") return yield* Effect.fail(notFound());
const [node] = (yield* services.nodes.list({ tenantId: tenant.id })).sort(
(a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id),
);
if (!node) return yield* Effect.fail(notFound());
const listing = yield* services.discovery
.get(node.id)
.pipe(Effect.orElseSucceed(() => null));
return {
name: node.name,
href: `/n/${encodeURIComponent(node.slug)}${
node.parentId ? `?parentId=${encodeURIComponent(node.parentId)}` : ""
}`,
channels: (listing?.channels ?? []).map(({ label, url }) => ({ label, url })),
};
}),

reconcileAttendance: builder.reconcileAttendance.use(requireAuth).effect(function* ({
input,
context,
Expand Down
101 changes: 101 additions & 0 deletions api/tests/integration/onboard-community.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Effect } from "effect";
import { afterAll, describe, expect, it, vi } from "vitest";
import { daoContext, getPluginClient, orgContext, teardown } from "../setup";

vi.mock("@/services/dao", () => ({
verifyDaoMembership: vi.fn(() =>
Effect.succeed({ isSputnikContract: true, isMember: true, policy: { roles: [] } }),
),
parsePolicyGroupMembers: vi.fn(() => []),
isExplicitDaoMember: vi.fn(() => true),
}));
afterAll(teardown);

async function fixture() {
const id = crypto.randomUUID();
const org = `onboard-${id}`;
const provisioner = await getPluginClient(daoContext(id, org, `o-${id}.near`));
const tenant = await provisioner.createTenant({
name: "Onboard city",
accountId: `o-${id}.near`,
});
const node = await provisioner.createNode({
name: "Lisbon",
slug: `lisbon-${id}`,
kind: "city",
tenantId: tenant.id,
});
return {
id,
org,
node,
tenant,
provisioner,
editor: await getPluginClient(orgContext(id, org)),
publicClient: await getPluginClient(),
};
}

const profile = {
summary: "Builders by the river",
location: "Lisbon",
region: "Portugal",
latitude: 38.72,
longitude: -9.14,
channels: [
{ label: "Telegram", url: "https://t.me/example" },
{ label: "X", url: "https://x.com/example" },
],
published: true,
};

describe("the joined screen's community for an organization", () => {
it("returns the community page and its published channels, signed out", async () => {
const { org, node, editor, publicClient } = await fixture();
await editor.saveDiscoveryProfile({ nodeId: node.id, ...profile });

expect(await publicClient.getOnboardCommunity({ organizationId: org })).toEqual({
name: "Lisbon",
href: `/n/${node.slug}`,
channels: profile.channels,
});
});

it("still links the community when it has no published channels", async () => {
const { org, node, editor, publicClient } = await fixture();
expect(await publicClient.getOnboardCommunity({ organizationId: org })).toEqual({
name: "Lisbon",
href: `/n/${node.slug}`,
channels: [],
});

await editor.saveDiscoveryProfile({ nodeId: node.id, ...profile, published: false });
expect((await publicClient.getOnboardCommunity({ organizationId: org })).channels).toEqual([]);
});

it("picks the community's first node by name and keeps a child node's parent", async () => {
const { id, org, node, tenant, provisioner, publicClient } = await fixture();
const child = await provisioner.createNode({
name: "Alfama",
slug: `alfama-${id}`,
kind: "city",
tenantId: tenant.id,
parentId: node.id,
});
expect((await publicClient.getOnboardCommunity({ organizationId: org })).href).toBe(
`/n/${child.slug}?parentId=${node.id}`,
);
});

it("is not found for unknown or suspended communities", async () => {
const { org, tenant, provisioner, publicClient } = await fixture();
await expect(
publicClient.getOnboardCommunity({ organizationId: `missing-${crypto.randomUUID()}` }),
).rejects.toMatchObject({ code: "NOT_FOUND" });

await provisioner.updateTenant({ tenantId: tenant.id, status: "suspended" });
await expect(publicClient.getOnboardCommunity({ organizationId: org })).rejects.toMatchObject({
code: "NOT_FOUND",
});
});
});
9 changes: 8 additions & 1 deletion bos.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default App({
"CityNodes are local communities that each run a NEAR validator. Find yours, join its events, and stake to keep it online.",
// The base runtime this app extends — inherit the platform, override only what you change.
extends: "bos://dev.everything.near/everything.dev",
platform: "2.0.0-rc.27",
platform: "2.0.0-rc.31",
// The NEAR account this app publishes under.
account: "v1.citynode.near",
// The gateway: FastKV lookup key and public ingress for this runtime.
Expand Down Expand Up @@ -44,6 +44,13 @@ export default App({
auth: {
variables: {
organizationMembershipLimit: 1000,
// Joined screen after an onboarding code (everything-dev #662): "Visit
// {community}" plus its channels. The default next/home/explore links fit.
onboard: {
community: {
url: "/api/communities/by-organization/{organizationId}",
},
},
deviceLink: {
clientId: "citynode-web",
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "citynode.app",
"private": true,
"type": "module",
"packageManager": "pnpm@12.10.1+sha512.ba40a37eb1a370d60fea8c4cf1d364c13bcccef518e98ad2bcee954f539d38da37458e58261a3fa55e06523450ea0ffff9f497b135be41f2c15c1642bacace6c",
"packageManager": "pnpm@12.16.1",
"engines": {
"node": ">=20.11"
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/proposals/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as schema from "./schema";

export type Database = PgDatabase<PgQueryResultHKT, typeof schema>;

export { DatabaseError, unwrapDatabaseError } from "everything-dev/db";
export { DatabaseError } from "everything-dev/db";

export interface DatabaseDriver {
readonly db: Database;
Expand Down
11 changes: 7 additions & 4 deletions plugins/proposals/src/db/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Effect } from "effect";
import {
type DatabaseError,
detectDrift,
type LoadedMigrations,
loadMigrations as loadSharedMigrations,
type Migration,
type MigrationDatabase,
type MigrationReport,
type MigrationStorage,
runMigrations,
} from "everything-dev/db";

export type { DriftReport, LoadedMigrations } from "everything-dev/db";
export { detectDrift } from "everything-dev/db";
type MigrationDatabase = Parameters<typeof runMigrations>[0];
type MigrationReport = Effect.Success<ReturnType<typeof runMigrations>>;
export type DriftReport = Effect.Success<ReturnType<typeof detectDrift>>;

export type { LoadedMigrations };
export { detectDrift };

export const loadMigrations: Effect.Effect<LoadedMigrations, DatabaseError> = loadSharedMigrations({
fromDir: import.meta.dirname,
Expand Down
2 changes: 1 addition & 1 deletion plugins/proposals/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default createPlugin({
Effect.gen(function* () {
const Database = DatabaseLive(config.secrets.PROPOSALS_DATABASE_URL);
const publisher = new MemoryPublisher<ProposalEvents>({
resume: { enabled: true, seconds: 120 },
resume: { enabled: true, ttl: 120_000 },
});

yield* Effect.log("[Proposals] Services Initialized");
Expand Down
Loading
Loading