@theihtisham/devtools-with-cloud 1.0.0

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.
Files changed (150) hide show
  1. package/.env.example +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +73 -0
  4. package/docker-compose.yml +23 -0
  5. package/jest.config.js +7 -0
  6. package/next-env.d.ts +5 -0
  7. package/next.config.mjs +22 -0
  8. package/package.json +82 -0
  9. package/postcss.config.js +6 -0
  10. package/prisma/schema.prisma +105 -0
  11. package/prisma/seed.ts +211 -0
  12. package/src/app/(app)/ai/page.tsx +122 -0
  13. package/src/app/(app)/collections/page.tsx +155 -0
  14. package/src/app/(app)/environments/page.tsx +96 -0
  15. package/src/app/(app)/history/page.tsx +107 -0
  16. package/src/app/(app)/import/page.tsx +102 -0
  17. package/src/app/(app)/layout.tsx +60 -0
  18. package/src/app/(app)/settings/page.tsx +79 -0
  19. package/src/app/(app)/workspace/page.tsx +284 -0
  20. package/src/app/api/ai/discover/route.ts +17 -0
  21. package/src/app/api/ai/explain/route.ts +29 -0
  22. package/src/app/api/ai/generate-tests/route.ts +37 -0
  23. package/src/app/api/ai/suggest/route.ts +29 -0
  24. package/src/app/api/collections/[id]/route.ts +66 -0
  25. package/src/app/api/collections/route.ts +48 -0
  26. package/src/app/api/environments/route.ts +40 -0
  27. package/src/app/api/export/openapi/route.ts +17 -0
  28. package/src/app/api/export/postman/route.ts +18 -0
  29. package/src/app/api/import/curl/route.ts +18 -0
  30. package/src/app/api/import/har/route.ts +20 -0
  31. package/src/app/api/import/openapi/route.ts +21 -0
  32. package/src/app/api/import/postman/route.ts +21 -0
  33. package/src/app/api/proxy/route.ts +35 -0
  34. package/src/app/api/requests/[id]/execute/route.ts +85 -0
  35. package/src/app/api/requests/[id]/history/route.ts +23 -0
  36. package/src/app/api/requests/[id]/route.ts +66 -0
  37. package/src/app/api/requests/route.ts +49 -0
  38. package/src/app/api/workspaces/route.ts +38 -0
  39. package/src/app/globals.css +99 -0
  40. package/src/app/layout.tsx +24 -0
  41. package/src/app/page.tsx +182 -0
  42. package/src/components/ai/ai-panel.tsx +65 -0
  43. package/src/components/ai/code-explainer.tsx +51 -0
  44. package/src/components/ai/endpoint-discovery.tsx +62 -0
  45. package/src/components/ai/test-generator.tsx +49 -0
  46. package/src/components/collections/collection-actions.tsx +36 -0
  47. package/src/components/collections/collection-tree.tsx +55 -0
  48. package/src/components/collections/folder-creator.tsx +54 -0
  49. package/src/components/landing/comparison.tsx +43 -0
  50. package/src/components/landing/cta.tsx +16 -0
  51. package/src/components/landing/features.tsx +24 -0
  52. package/src/components/landing/hero.tsx +23 -0
  53. package/src/components/response/body-viewer.tsx +33 -0
  54. package/src/components/response/headers-viewer.tsx +23 -0
  55. package/src/components/response/status-badge.tsx +25 -0
  56. package/src/components/response/test-results.tsx +50 -0
  57. package/src/components/response/timing-chart.tsx +39 -0
  58. package/src/components/ui/badge.tsx +24 -0
  59. package/src/components/ui/button.tsx +32 -0
  60. package/src/components/ui/code-editor.tsx +51 -0
  61. package/src/components/ui/dialog.tsx +56 -0
  62. package/src/components/ui/dropdown.tsx +63 -0
  63. package/src/components/ui/input.tsx +22 -0
  64. package/src/components/ui/key-value-editor.tsx +75 -0
  65. package/src/components/ui/select.tsx +24 -0
  66. package/src/components/ui/tabs.tsx +85 -0
  67. package/src/components/ui/textarea.tsx +22 -0
  68. package/src/components/ui/toast.tsx +54 -0
  69. package/src/components/workspace/request-panel.tsx +38 -0
  70. package/src/components/workspace/response-panel.tsx +81 -0
  71. package/src/components/workspace/sidebar.tsx +52 -0
  72. package/src/components/workspace/split-pane.tsx +49 -0
  73. package/src/components/workspace/tabs/auth-tab.tsx +94 -0
  74. package/src/components/workspace/tabs/body-tab.tsx +41 -0
  75. package/src/components/workspace/tabs/headers-tab.tsx +23 -0
  76. package/src/components/workspace/tabs/params-tab.tsx +23 -0
  77. package/src/components/workspace/tabs/pre-request-tab.tsx +26 -0
  78. package/src/components/workspace/url-bar.tsx +53 -0
  79. package/src/hooks/use-ai.ts +115 -0
  80. package/src/hooks/use-collection.ts +71 -0
  81. package/src/hooks/use-environment.ts +73 -0
  82. package/src/hooks/use-request.ts +111 -0
  83. package/src/lib/ai/endpoint-discovery.ts +158 -0
  84. package/src/lib/ai/explainer.ts +127 -0
  85. package/src/lib/ai/suggester.ts +164 -0
  86. package/src/lib/ai/test-generator.ts +161 -0
  87. package/src/lib/auth/api-key.ts +28 -0
  88. package/src/lib/auth/aws-sig.ts +131 -0
  89. package/src/lib/auth/basic.ts +17 -0
  90. package/src/lib/auth/bearer.ts +15 -0
  91. package/src/lib/auth/oauth2.ts +155 -0
  92. package/src/lib/auth/types.ts +16 -0
  93. package/src/lib/db/client.ts +15 -0
  94. package/src/lib/env/manager.ts +32 -0
  95. package/src/lib/env/resolver.ts +30 -0
  96. package/src/lib/exporters/openapi.ts +193 -0
  97. package/src/lib/exporters/postman.ts +140 -0
  98. package/src/lib/graphql/builder.ts +249 -0
  99. package/src/lib/graphql/formatter.ts +147 -0
  100. package/src/lib/graphql/index.ts +43 -0
  101. package/src/lib/graphql/introspection.ts +175 -0
  102. package/src/lib/graphql/types.ts +99 -0
  103. package/src/lib/graphql/validator.ts +216 -0
  104. package/src/lib/http/client.ts +112 -0
  105. package/src/lib/http/proxy.ts +83 -0
  106. package/src/lib/http/request-builder.ts +214 -0
  107. package/src/lib/http/response-parser.ts +106 -0
  108. package/src/lib/http/timing.ts +63 -0
  109. package/src/lib/importers/curl-parser.ts +346 -0
  110. package/src/lib/importers/har-parser.ts +128 -0
  111. package/src/lib/importers/openapi.ts +324 -0
  112. package/src/lib/importers/postman.ts +312 -0
  113. package/src/lib/test-runner/assertions.ts +163 -0
  114. package/src/lib/test-runner/reporter.ts +90 -0
  115. package/src/lib/test-runner/runner.ts +69 -0
  116. package/src/lib/utils/api-response.ts +85 -0
  117. package/src/lib/utils/cn.ts +6 -0
  118. package/src/lib/utils/content-type.ts +123 -0
  119. package/src/lib/utils/download.ts +53 -0
  120. package/src/lib/utils/errors.ts +92 -0
  121. package/src/lib/utils/format.ts +142 -0
  122. package/src/lib/utils/syntax-highlight.ts +108 -0
  123. package/src/lib/utils/validation.ts +231 -0
  124. package/src/lib/websocket/client.ts +182 -0
  125. package/src/lib/websocket/frames.ts +96 -0
  126. package/src/lib/websocket/history.ts +121 -0
  127. package/src/lib/websocket/index.ts +25 -0
  128. package/src/lib/websocket/types.ts +57 -0
  129. package/src/types/ai.ts +28 -0
  130. package/src/types/collection.ts +24 -0
  131. package/src/types/environment.ts +16 -0
  132. package/src/types/request.ts +54 -0
  133. package/src/types/response.ts +37 -0
  134. package/tailwind.config.ts +82 -0
  135. package/tests/lib/env/resolver.test.ts +108 -0
  136. package/tests/lib/graphql/builder.test.ts +349 -0
  137. package/tests/lib/graphql/formatter.test.ts +99 -0
  138. package/tests/lib/http/request-builder.test.ts +160 -0
  139. package/tests/lib/http/response-parser.test.ts +150 -0
  140. package/tests/lib/http/timing.test.ts +188 -0
  141. package/tests/lib/importers/curl-parser.test.ts +245 -0
  142. package/tests/lib/test-runner/assertions.test.ts +342 -0
  143. package/tests/lib/utils/cn.test.ts +46 -0
  144. package/tests/lib/utils/content-type.test.ts +175 -0
  145. package/tests/lib/utils/format.test.ts +188 -0
  146. package/tests/lib/utils/validation.test.ts +237 -0
  147. package/tests/lib/websocket/history.test.ts +186 -0
  148. package/tsconfig.json +29 -0
  149. package/tsconfig.tsbuildinfo +1 -0
  150. package/vitest.config.ts +21 -0
package/.env.example ADDED
@@ -0,0 +1,15 @@
1
+ # Database
2
+ DATABASE_URL="postgresql://postgres:postgres@localhost:5432/api_tester?schema=public"
3
+
4
+ # AI Provider (OpenAI-compatible)
5
+ OPENAI_API_KEY="sk-your-openai-api-key-here"
6
+ OPENAI_BASE_URL="https://api.openai.com/v1"
7
+ OPENAI_MODEL="gpt-4o"
8
+
9
+ # App
10
+ NEXT_PUBLIC_APP_URL="http://localhost:3000"
11
+ NEXT_PUBLIC_APP_NAME="APITester"
12
+
13
+ # Optional: For cloud features
14
+ # NEXT_PUBLIC_STRIPE_KEY=""
15
+ # NEXT_PUBLIC_AUTH_URL=""
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 APITester
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Devtools With Cloud
2
+
3
+ Open-source API testing tool with AI-powered features — a Postman alternative
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @theihtisham/devtools-with-cloud
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { } from '@theihtisham/devtools-with-cloud';
15
+ ```
16
+
17
+ ## Features
18
+
19
+ - Written in TypeScript with full type definitions
20
+ - Zero external dependencies (minimal footprint)
21
+ - Event-driven architecture
22
+ - Comprehensive test suite
23
+
24
+ ## API
25
+
26
+ ### Quick Start
27
+
28
+ ```typescript
29
+ import { } from '@theihtisham/devtools-with-cloud';
30
+
31
+ // Initialize and use the package
32
+ ```
33
+
34
+ ## Configuration
35
+
36
+ Configuration options and their defaults:
37
+
38
+ ```typescript
39
+ const config = {
40
+ // Add configuration options here
41
+ };
42
+ ```
43
+
44
+ ## Examples
45
+
46
+ See the `tests/` directory for usage examples.
47
+
48
+ ## Development
49
+
50
+ ```bash
51
+ # Install dependencies
52
+ npm install
53
+
54
+ # Build
55
+ npm run build
56
+
57
+ # Run tests
58
+ npm test
59
+
60
+ # Lint
61
+ npm run lint
62
+ ```
63
+
64
+ ## License
65
+
66
+ MIT License - see [LICENSE](LICENSE) for details.
67
+
68
+ ## Author
69
+
70
+ **ihtisham**
71
+
72
+ - GitHub: [https://github.com/ihtisham](https://github.com/ihtisham)
73
+ - npm: [@theihtisham](https://www.npmjs.com/~theihtisham)
@@ -0,0 +1,23 @@
1
+ version: '3.8'
2
+
3
+ services:
4
+ postgres:
5
+ image: postgres:16-alpine
6
+ container_name: api_tester_db
7
+ restart: unless-stopped
8
+ ports:
9
+ - '5432:5432'
10
+ environment:
11
+ POSTGRES_USER: postgres
12
+ POSTGRES_PASSWORD: postgres
13
+ POSTGRES_DB: api_tester
14
+ volumes:
15
+ - postgres_data:/var/lib/postgresql/data
16
+ healthcheck:
17
+ test: ['CMD-SHELL', 'pg_isready -U postgres']
18
+ interval: 5s
19
+ timeout: 5s
20
+ retries: 5
21
+
22
+ volumes:
23
+ postgres_data:
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ roots: ['<rootDir>/tests'],
5
+ testMatch: ['**/*.test.ts'],
6
+ moduleFileExtensions: ['ts', 'js', 'json'],
7
+ };
package/next-env.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /// <reference types="next" />
2
+ /// <reference types="next/image-types/global" />
3
+
4
+ // NOTE: This file should not be edited
5
+ // see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
@@ -0,0 +1,22 @@
1
+ /** @type {import('next').NextConfig} */
2
+ const nextConfig = {
3
+ reactStrictMode: true,
4
+ experimental: {
5
+ serverActions: {
6
+ bodySizeLimit: '10mb',
7
+ },
8
+ },
9
+ webpack: (config) => {
10
+ // Monaco editor needs these workarounds
11
+ config.resolve = config.resolve ?? {};
12
+ config.resolve.fallback = {
13
+ ...config.resolve.fallback,
14
+ fs: false,
15
+ net: false,
16
+ tls: false,
17
+ };
18
+ return config;
19
+ },
20
+ };
21
+
22
+ export default nextConfig;
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@theihtisham/devtools-with-cloud",
3
+ "version": "1.0.0",
4
+ "description": "Open-source API testing tool with AI-powered features \u2014 a Postman alternative",
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start",
9
+ "lint": "next lint",
10
+ "type-check": "tsc --noEmit",
11
+ "db:generate": "prisma generate",
12
+ "db:push": "prisma db push",
13
+ "db:migrate": "prisma migrate dev",
14
+ "db:seed": "tsx prisma/seed.ts",
15
+ "db:studio": "prisma studio",
16
+ "test": "vitest run",
17
+ "test:watch": "vitest",
18
+ "test:coverage": "vitest run --coverage"
19
+ },
20
+ "dependencies": {
21
+ "next": "^14.2.15",
22
+ "react": "^18.3.1",
23
+ "react-dom": "^18.3.1",
24
+ "@prisma/client": "^5.22.0",
25
+ "openai": "^4.68.0",
26
+ "zod": "^3.23.8",
27
+ "@monaco-editor/react": "^4.6.0",
28
+ "monaco-editor": "^0.52.0",
29
+ "lucide-react": "^0.453.0",
30
+ "clsx": "^2.1.1",
31
+ "tailwind-merge": "^2.5.4",
32
+ "class-variance-authority": "^0.7.0",
33
+ "nanoid": "^5.0.8",
34
+ "json-schema-library": "^10.0.0",
35
+ "fast-xml-parser": "^4.5.0",
36
+ "js-yaml": "^4.1.0",
37
+ "highlight.js": "^11.10.0",
38
+ "date-fns": "^4.1.0",
39
+ "zustand": "^5.0.0"
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "^5.6.3",
43
+ "@types/node": "^22.8.1",
44
+ "@types/react": "^18.3.11",
45
+ "@types/react-dom": "^18.3.1",
46
+ "@types/js-yaml": "^4.0.9",
47
+ "prisma": "^5.22.0",
48
+ "tailwindcss": "^3.4.14",
49
+ "postcss": "^8.4.47",
50
+ "autoprefixer": "^10.4.20",
51
+ "eslint": "^8.57.0",
52
+ "eslint-config-next": "^14.2.15",
53
+ "tsx": "^4.19.1",
54
+ "vitest": "^2.1.3",
55
+ "@vitejs/plugin-react": "^4.3.2",
56
+ "jest": "^29.7.0",
57
+ "ts-jest": "^29.1.0",
58
+ "@types/jest": "^29.5.0"
59
+ },
60
+ "prisma": {
61
+ "seed": "tsx prisma/seed.ts"
62
+ },
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "git+https://github.com/theihtisham/devtools-with-cloud.git"
69
+ },
70
+ "author": "ihtisham",
71
+ "license": "MIT",
72
+ "bugs": {
73
+ "url": "https://github.com/theihtisham/devtools-with-cloud/issues"
74
+ },
75
+ "homepage": "https://github.com/theihtisham/devtools-with-cloud#readme",
76
+ "keywords": [
77
+ "devtools with cloud",
78
+ "typescript",
79
+ "ai",
80
+ "developer-tools"
81
+ ]
82
+ }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
@@ -0,0 +1,105 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "postgresql"
7
+ url = env("DATABASE_URL")
8
+ }
9
+
10
+ model User {
11
+ id String @id @default(cuid())
12
+ email String @unique
13
+ name String?
14
+ workspaces Workspace[]
15
+ createdAt DateTime @default(now())
16
+ updatedAt DateTime @updatedAt
17
+ }
18
+
19
+ model Workspace {
20
+ id String @id @default(cuid())
21
+ name String
22
+ description String?
23
+ userId String
24
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
25
+ collections Collection[]
26
+ environments Environment[]
27
+ createdAt DateTime @default(now())
28
+ updatedAt DateTime @updatedAt
29
+ }
30
+
31
+ model Collection {
32
+ id String @id @default(cuid())
33
+ name String
34
+ description String?
35
+ workspaceId String
36
+ workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
37
+ parentId String?
38
+ parent Collection? @relation("NestedCollection", fields: [parentId], references: [id], onDelete: Cascade)
39
+ children Collection[] @relation("NestedCollection")
40
+ requests Request[]
41
+ variables Json @default("{}")
42
+ preScript String?
43
+ postScript String?
44
+ sortOrder Int @default(0)
45
+ createdAt DateTime @default(now())
46
+ updatedAt DateTime @updatedAt
47
+
48
+ @@index([workspaceId])
49
+ @@index([parentId])
50
+ }
51
+
52
+ model Request {
53
+ id String @id @default(cuid())
54
+ name String
55
+ description String?
56
+ collectionId String
57
+ collection Collection @relation(fields: [collectionId], references: [id], onDelete: Cascade)
58
+ method String @default("GET")
59
+ url String @default("")
60
+ headers Json @default("[]")
61
+ params Json @default("[]")
62
+ body Json?
63
+ bodyType String? @default("none")
64
+ auth Json?
65
+ preRequestScript String?
66
+ tests String?
67
+ history History[]
68
+ sortOrder Int @default(0)
69
+ createdAt DateTime @default(now())
70
+ updatedAt DateTime @updatedAt
71
+
72
+ @@index([collectionId])
73
+ }
74
+
75
+ model History {
76
+ id String @id @default(cuid())
77
+ requestId String
78
+ request Request @relation(fields: [requestId], references: [id], onDelete: Cascade)
79
+ method String
80
+ url String
81
+ status Int?
82
+ statusText String?
83
+ headers Json?
84
+ body String?
85
+ bodySize Int?
86
+ timing Json?
87
+ testResults Json?
88
+ duration Int?
89
+ createdAt DateTime @default(now())
90
+
91
+ @@index([requestId, createdAt])
92
+ }
93
+
94
+ model Environment {
95
+ id String @id @default(cuid())
96
+ name String
97
+ workspaceId String
98
+ workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
99
+ variables Json @default("[]")
100
+ isDefault Boolean @default(false)
101
+ createdAt DateTime @default(now())
102
+ updatedAt DateTime @updatedAt
103
+
104
+ @@index([workspaceId])
105
+ }
package/prisma/seed.ts ADDED
@@ -0,0 +1,211 @@
1
+ import { PrismaClient } from '@prisma/client';
2
+
3
+ const prisma = new PrismaClient();
4
+
5
+ async function main(): Promise<void> {
6
+ console.log('Seeding database...');
7
+
8
+ // Create a demo user
9
+ const user = await prisma.user.upsert({
10
+ where: { email: 'demo@apitester.dev' },
11
+ update: {},
12
+ create: {
13
+ email: 'demo@apitester.dev',
14
+ name: 'Demo User',
15
+ },
16
+ });
17
+
18
+ // Create a demo workspace
19
+ const workspace = await prisma.workspace.create({
20
+ data: {
21
+ name: 'My API Workspace',
22
+ description: 'A workspace for testing APIs',
23
+ userId: user.id,
24
+ },
25
+ });
26
+
27
+ // Create environments
28
+ await prisma.environment.createMany({
29
+ data: [
30
+ {
31
+ name: 'Development',
32
+ workspaceId: workspace.id,
33
+ isDefault: true,
34
+ variables: [
35
+ { key: 'base_url', value: 'http://localhost:3000', type: 'string', enabled: true },
36
+ { key: 'api_key', value: 'dev-test-key', type: 'string', enabled: true },
37
+ { key: 'auth_token', value: '', type: 'secret', enabled: true },
38
+ ],
39
+ },
40
+ {
41
+ name: 'Staging',
42
+ workspaceId: workspace.id,
43
+ variables: [
44
+ { key: 'base_url', value: 'https://staging.api.example.com', type: 'string', enabled: true },
45
+ { key: 'api_key', value: 'staging-key', type: 'string', enabled: true },
46
+ ],
47
+ },
48
+ {
49
+ name: 'Production',
50
+ workspaceId: workspace.id,
51
+ variables: [
52
+ { key: 'base_url', value: 'https://api.example.com', type: 'string', enabled: true },
53
+ { key: 'api_key', value: 'prod-key-xxxx', type: 'secret', enabled: true },
54
+ ],
55
+ },
56
+ ],
57
+ });
58
+
59
+ // Create a sample collection
60
+ const collection = await prisma.collection.create({
61
+ data: {
62
+ name: 'User API',
63
+ description: 'User management endpoints',
64
+ workspaceId: workspace.id,
65
+ variables: { user_id: '1' },
66
+ sortOrder: 0,
67
+ },
68
+ });
69
+
70
+ // Create sample requests
71
+ await prisma.request.createMany({
72
+ data: [
73
+ {
74
+ name: 'List Users',
75
+ collectionId: collection.id,
76
+ method: 'GET',
77
+ url: '{{base_url}}/api/users',
78
+ headers: [
79
+ { key: 'Accept', value: 'application/json', enabled: true },
80
+ ],
81
+ params: [
82
+ { key: 'page', value: '1', enabled: true },
83
+ { key: 'limit', value: '10', enabled: true },
84
+ ],
85
+ bodyType: 'none',
86
+ sortOrder: 0,
87
+ },
88
+ {
89
+ name: 'Get User',
90
+ collectionId: collection.id,
91
+ method: 'GET',
92
+ url: '{{base_url}}/api/users/{{user_id}}',
93
+ headers: [
94
+ { key: 'Accept', value: 'application/json', enabled: true },
95
+ { key: 'Authorization', value: 'Bearer {{auth_token}}', enabled: true },
96
+ ],
97
+ bodyType: 'none',
98
+ sortOrder: 1,
99
+ },
100
+ {
101
+ name: 'Create User',
102
+ collectionId: collection.id,
103
+ method: 'POST',
104
+ url: '{{base_url}}/api/users',
105
+ headers: [
106
+ { key: 'Content-Type', value: 'application/json', enabled: true },
107
+ { key: 'Authorization', value: 'Bearer {{auth_token}}', enabled: true },
108
+ ],
109
+ bodyType: 'json',
110
+ body: {
111
+ raw: JSON.stringify({
112
+ name: 'John Doe',
113
+ email: 'john@example.com',
114
+ role: 'user',
115
+ }, null, 2),
116
+ },
117
+ sortOrder: 2,
118
+ },
119
+ {
120
+ name: 'Update User',
121
+ collectionId: collection.id,
122
+ method: 'PUT',
123
+ url: '{{base_url}}/api/users/{{user_id}}',
124
+ headers: [
125
+ { key: 'Content-Type', value: 'application/json', enabled: true },
126
+ { key: 'Authorization', value: 'Bearer {{auth_token}}', enabled: true },
127
+ ],
128
+ bodyType: 'json',
129
+ body: {
130
+ raw: JSON.stringify({
131
+ name: 'Jane Doe',
132
+ email: 'jane@example.com',
133
+ }, null, 2),
134
+ },
135
+ sortOrder: 3,
136
+ },
137
+ {
138
+ name: 'Delete User',
139
+ collectionId: collection.id,
140
+ method: 'DELETE',
141
+ url: '{{base_url}}/api/users/{{user_id}}',
142
+ headers: [
143
+ { key: 'Authorization', value: 'Bearer {{auth_token}}', enabled: true },
144
+ ],
145
+ bodyType: 'none',
146
+ sortOrder: 4,
147
+ },
148
+ ],
149
+ });
150
+
151
+ // Create a second collection for auth examples
152
+ const authCollection = await prisma.collection.create({
153
+ data: {
154
+ name: 'Auth Examples',
155
+ description: 'Various authentication examples',
156
+ workspaceId: workspace.id,
157
+ sortOrder: 1,
158
+ },
159
+ });
160
+
161
+ await prisma.request.createMany({
162
+ data: [
163
+ {
164
+ name: 'Basic Auth Request',
165
+ collectionId: authCollection.id,
166
+ method: 'GET',
167
+ url: '{{base_url}}/api/protected',
168
+ headers: [],
169
+ bodyType: 'none',
170
+ auth: { type: 'basic', username: 'user', password: 'pass' },
171
+ sortOrder: 0,
172
+ },
173
+ {
174
+ name: 'Bearer Token Request',
175
+ collectionId: authCollection.id,
176
+ method: 'GET',
177
+ url: '{{base_url}}/api/me',
178
+ headers: [],
179
+ bodyType: 'none',
180
+ auth: { type: 'bearer', token: '{{auth_token}}' },
181
+ sortOrder: 1,
182
+ },
183
+ {
184
+ name: 'API Key Request',
185
+ collectionId: authCollection.id,
186
+ method: 'GET',
187
+ url: '{{base_url}}/api/data',
188
+ headers: [],
189
+ bodyType: 'none',
190
+ auth: { type: 'apikey', key: 'X-API-Key', value: '{{api_key}}', addTo: 'header' },
191
+ sortOrder: 2,
192
+ },
193
+ ],
194
+ });
195
+
196
+ console.log('Seed data created successfully!');
197
+ console.log(` User: ${user.email}`);
198
+ console.log(` Workspace: ${workspace.name}`);
199
+ console.log(' Collections: User API, Auth Examples');
200
+ console.log(' Environments: Development, Staging, Production');
201
+ }
202
+
203
+ main()
204
+ .then(async () => {
205
+ await prisma.$disconnect();
206
+ })
207
+ .catch(async (e) => {
208
+ console.error('Seed failed:', e);
209
+ await prisma.$disconnect();
210
+ process.exit(1);
211
+ });