@momentumcms/server-analog 0.0.1

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/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@momentumcms/server-analog",
3
+ "version": "0.0.1",
4
+ "description": "Nitro/h3 adapter for Momentum CMS with Analog.js support",
5
+ "license": "MIT",
6
+ "author": "Momentum CMS Contributors",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/momentum-cms/momentum-cms.git",
10
+ "directory": "libs/server-analog"
11
+ },
12
+ "homepage": "https://github.com/momentum-cms/momentum-cms#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/momentum-cms/momentum-cms/issues"
15
+ },
16
+ "keywords": [
17
+ "cms",
18
+ "momentum-cms",
19
+ "analog",
20
+ "nitro",
21
+ "h3",
22
+ "server"
23
+ ],
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "type": "commonjs",
28
+ "main": "./index.cjs",
29
+ "types": "./src/index.d.ts",
30
+ "peerDependencies": {
31
+ "@momentumcms/core": ">=0.0.1",
32
+ "@momentumcms/server-core": ">=0.0.1"
33
+ },
34
+ "dependencies": {
35
+ "@aws-sdk/client-s3": "^3.983.0",
36
+ "@aws-sdk/s3-request-presigner": "^3.983.0",
37
+ "graphql": "^16.12.0"
38
+ }
39
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/server-analog';
@@ -0,0 +1,120 @@
1
+ import { type MomentumResponse } from '@momentumcms/server-core';
2
+ import type { MomentumConfig, ResolvedMomentumConfig, UserContext } from '@momentumcms/core';
3
+ /**
4
+ * H3 Event interface (simplified for type compatibility).
5
+ */
6
+ export interface H3Event {
7
+ method: string;
8
+ path: string;
9
+ context: {
10
+ params?: Record<string, string>;
11
+ };
12
+ node?: {
13
+ req: {
14
+ url?: string;
15
+ };
16
+ };
17
+ }
18
+ /**
19
+ * Type for readBody function from h3.
20
+ */
21
+ export type ReadBodyFn = (event: H3Event) => Promise<Record<string, unknown>>;
22
+ /**
23
+ * Type for getQuery function from h3.
24
+ */
25
+ export type GetQueryFn = (event: H3Event) => Record<string, string | string[]>;
26
+ /**
27
+ * Type for getRouterParams function from h3.
28
+ */
29
+ export type GetRouterParamsFn = (event: H3Event) => Record<string, string>;
30
+ /**
31
+ * Type for setResponseHeader function from h3.
32
+ */
33
+ export type SetResponseHeaderFn = (event: H3Event, key: string, value: string) => void;
34
+ /**
35
+ * Type for readMultipartFormData function from h3.
36
+ */
37
+ export type ReadMultipartFormDataFn = (event: H3Event) => Promise<Array<{
38
+ name?: string;
39
+ filename?: string;
40
+ type?: string;
41
+ data: Buffer;
42
+ }> | undefined>;
43
+ /**
44
+ * Type for send function from h3.
45
+ */
46
+ export type SendFn = (event: H3Event, data: Buffer | string, type?: string) => unknown;
47
+ /**
48
+ * Extended h3 utilities for comprehensive API handling.
49
+ */
50
+ export interface MomentumH3Utils {
51
+ readBody(event: H3Event): Promise<Record<string, unknown>>;
52
+ getQuery(event: H3Event): Record<string, string | string[]>;
53
+ getRouterParams(event: H3Event): Record<string, string>;
54
+ setResponseStatus(event: H3Event, status: number): void;
55
+ setResponseHeader(event: H3Event, key: string, value: string): void;
56
+ readMultipartFormData(event: H3Event): Promise<Array<{
57
+ name?: string;
58
+ filename?: string;
59
+ type?: string;
60
+ data: Buffer;
61
+ }> | undefined>;
62
+ send(event: H3Event, data: Buffer | string, type?: string): unknown;
63
+ }
64
+ /**
65
+ * Creates an h3 event handler for Momentum CMS API.
66
+ *
67
+ * Usage in Analog.js:
68
+ * ```typescript
69
+ * // src/server/routes/api/[...momentum].ts
70
+ * import { defineEventHandler, readBody, getQuery, getRouterParams } from 'h3';
71
+ * import { createMomentumHandler } from '@momentumcms/server-analog';
72
+ * import momentumConfig from '../../../momentum.config';
73
+ *
74
+ * const handler = createMomentumHandler(momentumConfig);
75
+ *
76
+ * export default defineEventHandler(async (event) => {
77
+ * return handler(event, { readBody, getQuery, getRouterParams });
78
+ * });
79
+ * ```
80
+ */
81
+ export declare function createMomentumHandler(config: MomentumConfig | ResolvedMomentumConfig): (event: H3Event, utils: {
82
+ readBody: ReadBodyFn;
83
+ getQuery: GetQueryFn;
84
+ getRouterParams: GetRouterParamsFn;
85
+ }) => Promise<{
86
+ status: number;
87
+ body: MomentumResponse;
88
+ }>;
89
+ /**
90
+ * Simplified handler that returns the response directly (for use with defineEventHandler).
91
+ * This version handles method extraction and body parsing internally.
92
+ */
93
+ export declare function createSimpleMomentumHandler(config: MomentumConfig | ResolvedMomentumConfig): (event: H3Event, utils: {
94
+ readBody: ReadBodyFn;
95
+ getQuery: GetQueryFn;
96
+ getRouterParams: GetRouterParamsFn;
97
+ setResponseStatus: (event: H3Event, status: number) => void;
98
+ }) => Promise<MomentumResponse>;
99
+ /**
100
+ * Creates a comprehensive h3 event handler that mirrors all Express API routes.
101
+ * Handles: access control, GraphQL, globals, versioning, publishing, media,
102
+ * batch operations, search, import/export, custom endpoints, preview, and CRUD.
103
+ *
104
+ * Usage in Analog.js:
105
+ * ```typescript
106
+ * import { defineEventHandler, readBody, getQuery, getRouterParams,
107
+ * setResponseStatus, setResponseHeader, readMultipartFormData, send, getHeaders } from 'h3';
108
+ * import { createComprehensiveMomentumHandler } from '@momentumcms/server-analog';
109
+ *
110
+ * const handler = createComprehensiveMomentumHandler(momentumConfig);
111
+ *
112
+ * export default defineEventHandler(async (event) => {
113
+ * const user = await resolveSession(event);
114
+ * return handler(event, { readBody, getQuery, ... }, { user });
115
+ * });
116
+ * ```
117
+ */
118
+ export declare function createComprehensiveMomentumHandler(config: MomentumConfig | ResolvedMomentumConfig): (event: H3Event, utils: MomentumH3Utils, context?: {
119
+ user?: UserContext;
120
+ }) => Promise<unknown>;