@ontahi/runtime-nextjs 0.1.0-alpha.0 → 0.1.0-alpha.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/README.md +15 -0
- package/dist/operation-invocation/index.d.ts +1 -1
- package/dist/operation-invocation/index.d.ts.map +1 -1
- package/dist/operation-invocation/index.js.map +1 -1
- package/dist/operation-invocation/route.d.ts +4 -1
- package/dist/operation-invocation/route.d.ts.map +1 -1
- package/dist/operation-invocation/route.js +6 -2
- package/dist/operation-invocation/route.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,3 +9,18 @@ This package depends on `@ontahi/core` and owns the Next.js / `next-safe-action`
|
|
|
9
9
|
3. `@ontahi/runtime-nextjs/operation-invocation`: an App Router `Request`/`Response` adapter for the transport-neutral operation invocation protocol from `@ontahi/core`.
|
|
10
10
|
|
|
11
11
|
New generic consumers should import action metadata and result helpers from `@ontahi/core/runtime/actions`. React hooks and operation bridge adapters live in `@ontahi/react/actions` so this package can stay focused on Next.js runtime concerns.
|
|
12
|
+
|
|
13
|
+
The operation route can derive an Ontahi invocation context from each web request. Authentication
|
|
14
|
+
remains a host concern; the adapter receives only the resulting Principal:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
const POST = createNextOperationInvocationRouteHandler({
|
|
18
|
+
dispatcher,
|
|
19
|
+
invocationContext: async request => ({
|
|
20
|
+
principal: await resolvePrincipal(request),
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The Principal and resource map remain scoped to that invocation and are visible to operation
|
|
26
|
+
requirements, execution, nested operations, and permission checks.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createNextOperationInvocationRouteHandler, type CreateNextOperationInvocationRouteHandlerOptions, } from './route.js';
|
|
1
|
+
export { createNextOperationInvocationRouteHandler, type CreateNextOperationInvocationRouteHandlerOptions, type NextInvocationContextFactory, } from './route.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,EACzC,KAAK,gDAAgD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,EACzC,KAAK,gDAAgD,EACrD,KAAK,4BAA4B,GAClC,MAAM,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/operation-invocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yCAAyC,GAG1C,MAAM,YAAY,CAAC","sourcesContent":["export {\n createNextOperationInvocationRouteHandler,\n type CreateNextOperationInvocationRouteHandlerOptions,\n type NextInvocationContextFactory,\n} from './route.js';\n"]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { type OperationInvocationDispatcher } from '@ontahi/core/runtime/operation-invocation';
|
|
2
|
+
import { type InvocationContextInput } from '@ontahi/core/runtime/server';
|
|
3
|
+
export type NextInvocationContextFactory = (request: Request) => InvocationContextInput | Promise<InvocationContextInput>;
|
|
2
4
|
export type CreateNextOperationInvocationRouteHandlerOptions = {
|
|
3
5
|
dispatcher: OperationInvocationDispatcher;
|
|
6
|
+
invocationContext?: NextInvocationContextFactory;
|
|
4
7
|
reportError?: (error: unknown, request: Request) => void;
|
|
5
8
|
};
|
|
6
|
-
export declare const createNextOperationInvocationRouteHandler: ({ dispatcher, reportError }: CreateNextOperationInvocationRouteHandlerOptions) => (request: Request) => Promise<Response>;
|
|
9
|
+
export declare const createNextOperationInvocationRouteHandler: ({ dispatcher, invocationContext, reportError, }: CreateNextOperationInvocationRouteHandlerOptions) => (request: Request) => Promise<Response>;
|
|
7
10
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,6BAA6B,EAEnC,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,6BAA6B,EAEnC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAyB,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEjG,MAAM,MAAM,4BAA4B,GAAG,CACzC,OAAO,EAAE,OAAO,KACb,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAE9D,MAAM,MAAM,gDAAgD,GAAG;IAC7D,UAAU,EAAE,6BAA6B,CAAC;IAC1C,iBAAiB,CAAC,EAAE,4BAA4B,CAAC;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,CAAC;AAKF,eAAO,MAAM,yCAAyC,GACnD,iDAIE,gDAAgD,MAC5C,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAyBzC,CAAC"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { operationInvocationProtocolError, parseOperationInvocationRequest, } from '@ontahi/core/runtime/operation-invocation';
|
|
2
|
+
import { withInvocationContext } from '@ontahi/core/runtime/server';
|
|
2
3
|
const responseStatus = (response) => response.kind === 'protocol-error' ? 500 : 200;
|
|
3
|
-
export const createNextOperationInvocationRouteHandler = ({ dispatcher, reportError }) => async (request) => {
|
|
4
|
+
export const createNextOperationInvocationRouteHandler = ({ dispatcher, invocationContext, reportError, }) => async (request) => {
|
|
4
5
|
const parsedRequest = parseOperationInvocationRequest(await request.json().catch(() => null));
|
|
5
6
|
if (!parsedRequest.success) {
|
|
6
7
|
return Response.json(parsedRequest.error, { status: 400 });
|
|
7
8
|
}
|
|
8
9
|
try {
|
|
9
|
-
const
|
|
10
|
+
const dispatch = () => dispatcher(parsedRequest.request);
|
|
11
|
+
const response = invocationContext
|
|
12
|
+
? await withInvocationContext(await invocationContext(request), dispatch)
|
|
13
|
+
: await dispatch();
|
|
10
14
|
return Response.json(response, { status: responseStatus(response) });
|
|
11
15
|
}
|
|
12
16
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,GAGhC,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/operation-invocation/route.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,GAGhC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAA+B,MAAM,6BAA6B,CAAC;AAYjG,MAAM,cAAc,GAAG,CAAC,QAA6C,EAAE,EAAE,CACvE,QAAQ,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAEjD,MAAM,CAAC,MAAM,yCAAyC,GACpD,CAAC,EACC,UAAU,EACV,iBAAiB,EACjB,WAAW,GACsC,EAAE,EAAE,CACvD,KAAK,EAAE,OAAgB,EAAqB,EAAE;IAC5C,MAAM,aAAa,GAAG,+BAA+B,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAE9F,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,iBAAiB;YAChC,CAAC,CAAC,MAAM,qBAAqB,CAAC,MAAM,iBAAiB,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC;YACzE,CAAC,CAAC,MAAM,QAAQ,EAAE,CAAC;QAErB,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAE9B,OAAO,QAAQ,CAAC,IAAI,CAClB,gCAAgC,CAC9B,wBAAwB,EACxB,kDAAkD,CACnD,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n operationInvocationProtocolError,\n parseOperationInvocationRequest,\n type OperationInvocationDispatcher,\n type OperationInvocationProtocolResponse,\n} from '@ontahi/core/runtime/operation-invocation';\nimport { withInvocationContext, type InvocationContextInput } from '@ontahi/core/runtime/server';\n\nexport type NextInvocationContextFactory = (\n request: Request,\n) => InvocationContextInput | Promise<InvocationContextInput>;\n\nexport type CreateNextOperationInvocationRouteHandlerOptions = {\n dispatcher: OperationInvocationDispatcher;\n invocationContext?: NextInvocationContextFactory;\n reportError?: (error: unknown, request: Request) => void;\n};\n\nconst responseStatus = (response: OperationInvocationProtocolResponse) =>\n response.kind === 'protocol-error' ? 500 : 200;\n\nexport const createNextOperationInvocationRouteHandler =\n ({\n dispatcher,\n invocationContext,\n reportError,\n }: CreateNextOperationInvocationRouteHandlerOptions) =>\n async (request: Request): Promise<Response> => {\n const parsedRequest = parseOperationInvocationRequest(await request.json().catch(() => null));\n\n if (!parsedRequest.success) {\n return Response.json(parsedRequest.error, { status: 400 });\n }\n\n try {\n const dispatch = () => dispatcher(parsedRequest.request);\n const response = invocationContext\n ? await withInvocationContext(await invocationContext(request), dispatch)\n : await dispatch();\n\n return Response.json(response, { status: responseStatus(response) });\n } catch (error) {\n reportError?.(error, request);\n\n return Response.json(\n operationInvocationProtocolError(\n 'invocation_unavailable',\n 'Operation invocation is temporarily unavailable.',\n ),\n { status: 500 },\n );\n }\n };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontahi/runtime-nextjs",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
4
|
"description": "Next.js action runtime and transport helpers for Ontahi applications",
|
|
5
5
|
"homepage": "https://github.com/javifernandes/ontahi/tree/main/packages/runtime-nextjs",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"next-safe-action": "^8.3.0",
|
|
50
50
|
"server-only": "^0.0.1",
|
|
51
51
|
"zod": "^4.3.6",
|
|
52
|
-
"@ontahi/core": "0.1.0-alpha.
|
|
52
|
+
"@ontahi/core": "0.1.0-alpha.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^20.0.0",
|