History

Feed the cloud membership mirror from login and member writes (#2004)

Rhys Sullivan committed 1 month ago

Commit ddfe3f51 parent 89f424633 files · +5374 −606Browse files

Showing the changes to apps/cloud/src/api (4 of 33 files). Show all

Unified · Split

4 files
  1. apps/cloud/src/api/layers.ts +3 −1
  2. apps/cloud/src/api/protected-api-key-auth.node.test.ts +9 −0
  3. apps/cloud/src/api/protected-jwt-auth.node.test.ts +9 −0
  4. apps/cloud/src/api/router.ts +4 −1
apps/cloud/src/api/layers.ts+3−1
@@ -56,7 +56,9 @@ export const BootSharedServices = Layer.mergeAll( · 55 unmodified lines
56// `AutumnService.Default` is provided HERE because the `createOrganization`56// `AutumnService.Default` is provided HERE because the `createOrganization`
57// handler reads it for the free-organizations-per-user limit gate — one of the57// handler reads it for the free-organizations-per-user limit gate — one of the
58// few app-only billing touchpoints. (It is NOT on the neutral boot core.)58// few app-only billing touchpoints. (It is NOT on the neutral boot core.)
59export const makeNonProtectedApiLive = (rsLive: Layer.Layer<DbService | UserStoreService>) =>59export const makeNonProtectedApiLive = (
60 rsLive: Layer.Layer<DbService | UserStoreService | WorkOsMirror>,
61) =>
60 HttpApiBuilder.layer(NonProtectedApi).pipe(62 HttpApiBuilder.layer(NonProtectedApi).pipe(
61 Layer.provide(Layer.mergeAll(CloudAuthPublicHandlers, CloudSessionAuthHandlers)),63 Layer.provide(Layer.mergeAll(CloudAuthPublicHandlers, CloudSessionAuthHandlers)),
62 Layer.provide(requestScopedMiddleware(rsLive).layer),64 Layer.provide(requestScopedMiddleware(rsLive).layer),
apps/cloud/src/api/protected-api-key-auth.node.test.ts+9−0
@@ -68,18 +68,27 @@ const stubUsers = Layer.succeed(UserStoreService)({ · 67 unmodified lines
68 upsertOrganization: async (org: { id: string; name: string }) => ({68 upsertOrganization: async (org: { id: string; name: string }) => ({
69 ...org,69 ...org,
70 slug: `org-slug-${org.id}`,70 slug: `org-slug-${org.id}`,
71 backfilledAt: null,
72 deletedAt: null,
73 workosUpdatedAt: null,
71 createdAt,74 createdAt,
72 }),75 }),
73 getOrganization: async (id: string) => ({76 getOrganization: async (id: string) => ({
74 id,77 id,
75 name: `Org ${id}`,78 name: `Org ${id}`,
76 slug: `org-slug-${id}`,79 slug: `org-slug-${id}`,
80 backfilledAt: null,
81 deletedAt: null,
82 workosUpdatedAt: null,
77 createdAt,83 createdAt,
78 }),84 }),
79 getOrganizationBySlug: async (slug: string) => ({85 getOrganizationBySlug: async (slug: string) => ({
80 id: "org_by_slug",86 id: "org_by_slug",
81 name: `Org ${slug}`,87 name: `Org ${slug}`,
82 slug,88 slug,
89 backfilledAt: null,
90 deletedAt: null,
91 workosUpdatedAt: null,
83 createdAt,92 createdAt,
84 }),93 }),
85 deleteOrganizationCascade: async () => {},94 deleteOrganizationCascade: async () => {},
apps/cloud/src/api/protected-jwt-auth.node.test.ts+9−0
@@ -85,18 +85,27 @@ const stubUsers = Layer.succeed(UserStoreService)({ · 84 unmodified lines
85 upsertOrganization: async (org: { id: string; name: string }) => ({85 upsertOrganization: async (org: { id: string; name: string }) => ({
86 ...org,86 ...org,
87 slug: `org-slug-${org.id}`,87 slug: `org-slug-${org.id}`,
88 backfilledAt: null,
89 deletedAt: null,
90 workosUpdatedAt: null,
88 createdAt,91 createdAt,
89 }),92 }),
90 getOrganization: async (id: string) => ({93 getOrganization: async (id: string) => ({
91 id,94 id,
92 name: `Org ${id}`,95 name: `Org ${id}`,
93 slug: `org-slug-${id}`,96 slug: `org-slug-${id}`,
97 backfilledAt: null,
98 deletedAt: null,
99 workosUpdatedAt: null,
94 createdAt,100 createdAt,
95 }),101 }),
96 getOrganizationBySlug: async (slug: string) => ({102 getOrganizationBySlug: async (slug: string) => ({
97 id: "org_by_slug",103 id: "org_by_slug",
98 name: `Org ${slug}`,104 name: `Org ${slug}`,
99 slug,105 slug,
106 backfilledAt: null,
107 deletedAt: null,
108 workosUpdatedAt: null,
100 createdAt,109 createdAt,
101 }),110 }),
102 deleteOrganizationCascade: async () => {},111 deleteOrganizationCascade: async () => {},
apps/cloud/src/api/router.ts+4−1
@@ -4,6 +4,7 @@ import { HttpRouter } from "effect/unstable/http"; · 3 unmodified lines
4import { RouterConfigLive, requestScopedMiddleware } from "@executor-js/api/server";4import { RouterConfigLive, requestScopedMiddleware } from "@executor-js/api/server";
5 5
6import { UserStoreService } from "../auth/context";6import { UserStoreService } from "../auth/context";
7import { WorkOsMirror } from "../auth/workos-mirror";
7import { DbService } from "../db/db";8import { DbService } from "../db/db";
8import { makeAccountApiLive } from "../account/account-api";9import { makeAccountApiLive } from "../account/account-api";
9 10
@@ -29,7 +30,9 @@ import { makeProtectedApiLive } from "./protected"; · 19 unmodified lines
29// so tests can substitute a counting fake for `DbService.Live` and30// so tests can substitute a counting fake for `DbService.Live` and
30// assert per-request semantics — see31// assert per-request semantics — see
31// `apps/cloud/src/api.request-scope.node.test.ts`.32// `apps/cloud/src/api.request-scope.node.test.ts`.
32export const makeApiLive = (requestScopedLive: Layer.Layer<DbService | UserStoreService>) => {33export const makeApiLive = (
34 requestScopedLive: Layer.Layer<DbService | UserStoreService | WorkOsMirror>,
35) => {
33 const BillingRoutesLive = AutumnRoutesLive.pipe(36 const BillingRoutesLive = AutumnRoutesLive.pipe(
34 Layer.provide(requestScopedMiddleware(requestScopedLive).layer),37 Layer.provide(requestScopedMiddleware(requestScopedLive).layer),
35 );38 );