@supaku/agentfactory-nextjs 0.4.5 → 0.4.6

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=middleware-edge-safety.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware-edge-safety.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/middleware-edge-safety.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,74 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { readFileSync } from 'fs';
3
+ import { resolve, dirname } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+ /**
7
+ * Edge Runtime safety tests for the /middleware subpath.
8
+ *
9
+ * Next.js middleware runs in Edge Runtime which cannot load Node.js
10
+ * built-in modules (crypto, ioredis, etc.). The /middleware subpath
11
+ * must NEVER transitively import these modules.
12
+ *
13
+ * These tests inspect the source code of the middleware barrel and
14
+ * its transitive imports to verify no Node.js-only modules are pulled in.
15
+ */
16
+ const FORBIDDEN_NODE_MODULES = [
17
+ 'crypto',
18
+ 'ioredis',
19
+ 'fs',
20
+ 'child_process',
21
+ 'net',
22
+ 'tls',
23
+ 'dns',
24
+ ];
25
+ const FORBIDDEN_PACKAGE_IMPORTS = [
26
+ '@supaku/agentfactory-server',
27
+ ];
28
+ function readSource(relativePath) {
29
+ return readFileSync(resolve(__dirname, '..', relativePath), 'utf-8');
30
+ }
31
+ describe('middleware Edge Runtime safety', () => {
32
+ it('middleware barrel (index.ts) only imports from factory and types', () => {
33
+ const source = readSource('middleware/index.ts');
34
+ const importLines = source.split('\n').filter(line => line.match(/^(?:export|import)\s/) && line.includes('from'));
35
+ for (const line of importLines) {
36
+ // Allow imports from ./factory.js and ./types.js only
37
+ expect(line).toMatch(/from\s+['"]\.\/(?:factory|types)\.js['"]/);
38
+ }
39
+ });
40
+ it('middleware factory (factory.ts) does not import Node.js modules', () => {
41
+ const source = readSource('middleware/factory.ts');
42
+ for (const mod of FORBIDDEN_NODE_MODULES) {
43
+ expect(source).not.toMatch(new RegExp(`from\\s+['"]${mod}['"]`));
44
+ expect(source).not.toMatch(new RegExp(`require\\s*\\(\\s*['"]${mod}['"]`));
45
+ }
46
+ });
47
+ it('middleware factory (factory.ts) does not import @supaku/agentfactory-server', () => {
48
+ const source = readSource('middleware/factory.ts');
49
+ for (const pkg of FORBIDDEN_PACKAGE_IMPORTS) {
50
+ expect(source).not.toMatch(new RegExp(`from\\s+['"]${pkg}`));
51
+ expect(source).not.toMatch(new RegExp(`require\\s*\\(\\s*['"]${pkg}`));
52
+ }
53
+ });
54
+ it('middleware types (types.ts) has no runtime imports', () => {
55
+ const source = readSource('middleware/types.ts');
56
+ // types.ts should only have type-level imports (import type) or no imports at all
57
+ const runtimeImports = source.split('\n').filter(line => line.match(/^import\s+(?!type\s)/) && !line.includes('import type'));
58
+ expect(runtimeImports).toEqual([]);
59
+ });
60
+ it('middleware factory only imports from next/server and local types', () => {
61
+ const source = readSource('middleware/factory.ts');
62
+ const importLines = source.split('\n').filter(line => line.match(/^import\s/) && line.includes('from'));
63
+ for (const line of importLines) {
64
+ const fromMatch = line.match(/from\s+['"]([^'"]+)['"]/);
65
+ if (!fromMatch)
66
+ continue;
67
+ const specifier = fromMatch[1];
68
+ // Allow: next/server, ./types.js (relative local imports)
69
+ const isAllowed = specifier === 'next/server' ||
70
+ specifier.startsWith('./');
71
+ expect(isAllowed, `Unexpected import: ${specifier}`).toBe(true);
72
+ }
73
+ });
74
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=subpath-exports.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subpath-exports.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/subpath-exports.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ /**
3
+ * Subpath export resolution tests for @supaku/agentfactory-nextjs.
4
+ *
5
+ * Verifies that the /middleware subpath exports the expected factory
6
+ * function and does NOT transitively import Node.js-only modules
7
+ * (crypto, ioredis) that break Edge Runtime.
8
+ */
9
+ describe('@supaku/agentfactory-nextjs subpath exports', () => {
10
+ it('exports createAgentFactoryMiddleware from ./middleware', async () => {
11
+ const mod = await import('../middleware/index.js');
12
+ expect(mod.createAgentFactoryMiddleware).toBeDefined();
13
+ expect(typeof mod.createAgentFactoryMiddleware).toBe('function');
14
+ });
15
+ it('exports createAllRoutes from main barrel', async () => {
16
+ const mod = await import('../index.js');
17
+ expect(mod.createAllRoutes).toBeDefined();
18
+ expect(typeof mod.createAllRoutes).toBe('function');
19
+ });
20
+ it('exports createDefaultLinearClientResolver from main barrel', async () => {
21
+ const mod = await import('../index.js');
22
+ expect(mod.createDefaultLinearClientResolver).toBeDefined();
23
+ expect(typeof mod.createDefaultLinearClientResolver).toBe('function');
24
+ });
25
+ it('exports createWebhookOrchestrator from main barrel', async () => {
26
+ const mod = await import('../index.js');
27
+ expect(mod.createWebhookOrchestrator).toBeDefined();
28
+ expect(typeof mod.createWebhookOrchestrator).toBe('function');
29
+ });
30
+ it('exports createOAuthCallbackHandler from main barrel', async () => {
31
+ const mod = await import('../index.js');
32
+ expect(mod.createOAuthCallbackHandler).toBeDefined();
33
+ expect(typeof mod.createOAuthCallbackHandler).toBe('function');
34
+ });
35
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supaku/agentfactory-nextjs",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "type": "module",
5
5
  "description": "Next.js API route handlers for AgentFactory — webhook processor, worker/session management, public stats",
6
6
  "author": "Supaku (https://supaku.com)",
@@ -48,9 +48,9 @@
48
48
  "LICENSE"
49
49
  ],
50
50
  "dependencies": {
51
- "@supaku/agentfactory-server": "0.4.5",
52
- "@supaku/agentfactory": "0.4.5",
53
- "@supaku/agentfactory-linear": "0.4.5"
51
+ "@supaku/agentfactory": "0.4.6",
52
+ "@supaku/agentfactory-server": "0.4.6",
53
+ "@supaku/agentfactory-linear": "0.4.6"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "next": ">=14.0.0"