@getstrata/bootstrap 0.2.8 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap/membershipService.d.ts +3 -0
- package/dist/bootstrap/public-api.d.ts +3 -1
- package/dist/bootstrap/queue/defaultJobs.d.ts +2 -0
- package/dist/core/auth/authContext.d.ts +1 -2
- package/dist/core/auth/membershipContext.d.ts +1 -2
- package/dist/core/auth/membershipService.d.ts +1 -2
- package/dist/core/http/requestMetaContext.d.ts +1 -2
- package/dist/core/queue/createAppQueue.d.ts +3 -3
- package/dist/core/runtime/asyncContextStore.d.ts +3 -0
- package/dist/core/tenant/tenantContext.d.ts +1 -2
- package/dist/core/tracing/traceContext.d.ts +1 -2
- package/dist/entries/applicationRegistry.js +15 -2
- package/dist/entries/context.js +272 -321
- package/dist/entries/createWebRoutes.js +18 -6
- package/dist/entries/http/securedRouteModelBinding.js +19 -179
- package/dist/entries/membershipService.js +317 -0
- package/dist/entries/providers/view.js +18 -6
- package/dist/entries/providers.js +279 -413
- package/dist/entries/queue/defaultJobs.js +390 -0
- package/dist/index.js +288 -125
- package/package.json +13 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @getstrata/bootstrap — application shell for Strata sibling apps.
|
|
3
3
|
*/
|
|
4
|
-
export { resolveApplicationQueue, setActiveApplicationContext } from "@getstrata/core";
|
|
4
|
+
export { resolveApplicationAuth, resolveApplicationCache, resolveApplicationConfig, resolveApplicationDependencies, resolveApplicationLogger, resolveApplicationPolicyGate, resolveApplicationQueue, setActiveApplicationContext, } from "@getstrata/core";
|
|
5
5
|
export { scheduleRunCommand } from "../cli/commands/scheduleRun.ts";
|
|
6
6
|
export type { ScheduledTask } from "../core/scheduler/schedule.ts";
|
|
7
7
|
export { appSchedule, runDueScheduledTasks, Schedule } from "../core/scheduler/schedule.ts";
|
|
@@ -12,6 +12,8 @@ export { assertAppDependenciesComplete, getRequiredDependency, resolveService, S
|
|
|
12
12
|
export { createWebRoutes, mergeWebRoutes } from "./createWebRoutes.ts";
|
|
13
13
|
export { type RouteModelAuthorization, securedBindRouteModel, securedBindRouteModelByKey, } from "./http/securedRouteModelBinding.ts";
|
|
14
14
|
export { createHttpKernel, type HttpKernel, type MiddlewareGroupName } from "./httpKernel.ts";
|
|
15
|
+
export { resolveMembershipService } from "./membershipService.ts";
|
|
15
16
|
export { prefixRouteMap } from "./prefixRouteMap.ts";
|
|
16
17
|
export { coreProviders } from "./providers/index.ts";
|
|
18
|
+
export { registerDefaultJobs } from "./queue/defaultJobs.ts";
|
|
17
19
|
export { CookieSessionStore, createCsrfProtection, createRouteKernel, createWebServer, type ParsedForm, parseFormBody, routeParams, type SessionUser, slugify, toRouteRequest, type WebServerOptions, wrapSecuredRouteModelByKey, wrapWebLogin, wrapWebRegister, } from "./web/index.ts";
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
type AuthUser = {
|
|
3
2
|
id: number | string;
|
|
4
3
|
role?: string;
|
|
5
4
|
abilities?: string[];
|
|
6
5
|
tokenId?: number;
|
|
7
6
|
};
|
|
8
|
-
declare const authContext: AsyncLocalStorage<AuthUser | null>;
|
|
7
|
+
declare const authContext: import("node:async_hooks").AsyncLocalStorage<AuthUser | null>;
|
|
9
8
|
declare function runWithAuthUser<T>(user: AuthUser | null, callback: () => T | Promise<T>): T | Promise<T>;
|
|
10
9
|
declare function currentAuthUser(): AuthUser | null;
|
|
11
10
|
export type { AuthUser };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
import OrganizationMemberRepository from "../../modules/organization/memberRepository";
|
|
3
2
|
import type { OrganizationMemberRole } from "../../modules/organization/memberTypes";
|
|
4
3
|
type MembershipContext = {
|
|
5
4
|
organizationIds: number[];
|
|
6
5
|
rolesByOrganizationId: Map<number, OrganizationMemberRole>;
|
|
7
6
|
};
|
|
8
|
-
declare const membershipContext: AsyncLocalStorage<MembershipContext>;
|
|
7
|
+
declare const membershipContext: import("node:async_hooks").AsyncLocalStorage<MembershipContext>;
|
|
9
8
|
declare const membershipRepository: OrganizationMemberRepository;
|
|
10
9
|
declare function runWithMembershipContext<T>(callback: () => T | Promise<T>): Promise<T | Promise<T>>;
|
|
11
10
|
declare function currentOrgRole(organizationId: number): OrganizationMemberRole | null;
|
|
@@ -18,7 +18,6 @@ declare class MembershipService {
|
|
|
18
18
|
}): Promise<import("../../modules/organization/memberTypes").OrganizationMemberRecord>;
|
|
19
19
|
removeMember(organizationId: number, userId: number): Promise<boolean>;
|
|
20
20
|
}
|
|
21
|
-
declare function resolveMembershipService(): MembershipService;
|
|
22
21
|
export type { MembershipRepositoryLike };
|
|
23
22
|
export default MembershipService;
|
|
24
|
-
export { resolveMembershipService };
|
|
23
|
+
export { resolveMembershipService } from "../../bootstrap/membershipService.ts";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
type RequestMeta = {
|
|
3
2
|
ipAddress: string | null;
|
|
4
3
|
userAgent: string | null;
|
|
@@ -9,7 +8,7 @@ type RequestMeta = {
|
|
|
9
8
|
} | null;
|
|
10
9
|
csrfToken?: string;
|
|
11
10
|
};
|
|
12
|
-
declare const requestMetaContext: AsyncLocalStorage<RequestMeta>;
|
|
11
|
+
declare const requestMetaContext: import("node:async_hooks").AsyncLocalStorage<RequestMeta>;
|
|
13
12
|
declare function runWithRequestMeta<T>(meta: RequestMeta, callback: () => T | Promise<T>): T | Promise<T>;
|
|
14
13
|
declare function currentRequestMeta(): RequestMeta;
|
|
15
14
|
export type { RequestMeta };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Queue } from "./index";
|
|
2
2
|
import { createFailedJobService, createQueueWorker, createTrackedJob, type FailedJobService } from "./publicQueue";
|
|
3
3
|
declare const FAILED_JOB_SERVICE_TOKEN = "core.failedJobs";
|
|
4
|
-
declare function
|
|
5
|
-
|
|
6
|
-
export { createAppQueue, createFailedJobService, createQueueWorker, createTrackedJob, FAILED_JOB_SERVICE_TOKEN,
|
|
4
|
+
declare function createAppQueue(driver: "sync" | "async" | "redis", redisUrl?: string, failedJobs?: FailedJobService, registerJobs?: () => void): Queue;
|
|
5
|
+
export { registerDefaultJobs } from "../../bootstrap/queue/defaultJobs.ts";
|
|
6
|
+
export { createAppQueue, createFailedJobService, createQueueWorker, createTrackedJob, FAILED_JOB_SERVICE_TOKEN, };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
type TenantContext = {
|
|
3
2
|
id: number;
|
|
4
3
|
slug: string;
|
|
5
4
|
plan: "free" | "pro" | "enterprise";
|
|
6
5
|
region: "eu" | "us" | "apac";
|
|
7
6
|
};
|
|
8
|
-
declare const tenantContext: AsyncLocalStorage<TenantContext>;
|
|
7
|
+
declare const tenantContext: import("node:async_hooks").AsyncLocalStorage<TenantContext>;
|
|
9
8
|
declare function runWithTenant<T>(tenant: TenantContext, callback: () => T | Promise<T>): T | Promise<T>;
|
|
10
9
|
declare function currentTenant(): TenantContext | null;
|
|
11
10
|
declare function currentTenantId(): number;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
type TraceContext = {
|
|
3
2
|
traceId: string;
|
|
4
3
|
spanId: string;
|
|
5
4
|
};
|
|
6
|
-
declare const traceContextStorage: AsyncLocalStorage<TraceContext>;
|
|
5
|
+
declare const traceContextStorage: import("node:async_hooks").AsyncLocalStorage<TraceContext>;
|
|
7
6
|
declare function runWithTraceContext<T>(context: TraceContext, callback: () => T | Promise<T>): T | Promise<T>;
|
|
8
7
|
declare function currentTraceId(): string | null;
|
|
9
8
|
export type { TraceContext };
|
|
@@ -142,15 +142,28 @@ function resolveService(dependencies, token) {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
// ../../src/bootstrap/applicationRegistry.ts
|
|
145
|
+
var APPLICATION_CONTEXT_KEY = Symbol.for("@getstrata/applicationContext");
|
|
145
146
|
var activeContext;
|
|
147
|
+
function readStoredApplicationContext() {
|
|
148
|
+
if (activeContext) {
|
|
149
|
+
return activeContext;
|
|
150
|
+
}
|
|
151
|
+
const globalContext = globalThis[APPLICATION_CONTEXT_KEY];
|
|
152
|
+
if (globalContext) {
|
|
153
|
+
activeContext = globalContext;
|
|
154
|
+
}
|
|
155
|
+
return activeContext;
|
|
156
|
+
}
|
|
146
157
|
function setActiveApplicationContext(context) {
|
|
147
158
|
activeContext = context;
|
|
159
|
+
globalThis[APPLICATION_CONTEXT_KEY] = context;
|
|
148
160
|
}
|
|
149
161
|
function requireActiveApplicationContext() {
|
|
150
|
-
|
|
162
|
+
const context = readStoredApplicationContext();
|
|
163
|
+
if (!context) {
|
|
151
164
|
throw new Error("The application context has not been bootstrapped.");
|
|
152
165
|
}
|
|
153
|
-
return
|
|
166
|
+
return context;
|
|
154
167
|
}
|
|
155
168
|
function resolveApplicationCache() {
|
|
156
169
|
return getRequiredDependency(requireActiveApplicationContext().dependencies, "cache");
|