json-rest-api 0.1.1 → 1.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.
Files changed (50) hide show
  1. package/.claude/settings.local.json +16 -0
  2. package/LICENSE +674 -20
  3. package/README.md +728 -120
  4. package/RELATIONSHIPS.md +1013 -0
  5. package/TODO_rest-api-plugin-extras.js +142 -0
  6. package/connectors_ideas/express-plugin.js +120 -0
  7. package/connectors_ideas/fastify.js +219 -0
  8. package/connectors_ideas/http-plugin.js +138 -0
  9. package/connectors_ideas/koa-plugin.js +113 -0
  10. package/docs/fileUploads.md +722 -0
  11. package/docs/mini-guides/file-uploads-complete.md +159 -0
  12. package/examples/.gitkeep +0 -0
  13. package/examples/express-example.js +262 -0
  14. package/examples/express-plugin.js +366 -0
  15. package/examples/file-upload-example.js +205 -0
  16. package/examples/filename-strategies.js +140 -0
  17. package/examples/knex-basic.js +66 -0
  18. package/index.js +28 -202
  19. package/lib/payload-validators.js +685 -0
  20. package/lib/rest-api-errors.js +58 -0
  21. package/package.json +37 -20
  22. package/payloadValdators.js +686 -0
  23. package/plugins/core/connectors/express-plugin.js +449 -0
  24. package/plugins/core/connectors/http-plugin.js +450 -0
  25. package/plugins/core/file-handling-plugin.js +338 -0
  26. package/plugins/core/lib/busboy-detector.js +167 -0
  27. package/plugins/core/lib/formidable-detector.js +130 -0
  28. package/plugins/core/rest-api-knex-plugin.js +200 -0
  29. package/plugins/core/rest-api-plugin.js +1419 -0
  30. package/plugins/storage/local-storage.js +218 -0
  31. package/plugins/storage/s3-storage.js +125 -0
  32. package/test-examples/package-lock.json +906 -0
  33. package/test-examples/package.json +15 -0
  34. package/test-examples/test-basic-api.js +11 -0
  35. package/test-examples/test-books-resource.js +116 -0
  36. package/test-examples/test-complete-file-upload.js +140 -0
  37. package/test-examples/test-debug.js +28 -0
  38. package/test-examples/test-express-plugin.js +177 -0
  39. package/test-examples/test-express-simple.js +28 -0
  40. package/test-examples/test-express-with-import.js +71 -0
  41. package/test-examples/test-file-upload.js +132 -0
  42. package/test-examples/test-http-plugin.js +159 -0
  43. package/test-examples/test-programmatic-api.js +188 -0
  44. package/test-examples/test-rest-api-plugin.js +13 -0
  45. package/.jshintrc +0 -48
  46. package/.npmignore +0 -15
  47. package/examples/client.js +0 -18
  48. package/examples/client2.js +0 -27
  49. package/examples/server.js +0 -23
  50. package/test.js +0 -101
@@ -0,0 +1,58 @@
1
+ import { HookedApiError } from 'hooked-api';
2
+
3
+ /**
4
+ * REST API specific error classes that can be mapped to HTTP status codes
5
+ * by the HTTP plugin or other protocol plugins
6
+ */
7
+
8
+ /**
9
+ * Validation error for invalid payloads, schema violations, etc.
10
+ * HTTP plugin should map this to 422 Unprocessable Entity
11
+ */
12
+ export class RestApiValidationError extends HookedApiError {
13
+ constructor(message, { fields = [], violations = [] } = {}) {
14
+ super(message, 'REST_API_VALIDATION_ERROR');
15
+ this.code = 'REST_API_VALIDATION';
16
+ this.type = 'rest_api_validation';
17
+ this.details = {
18
+ fields,
19
+ violations
20
+ };
21
+ this.violations = violations;
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Resource-related errors (not found, conflicts, forbidden access)
27
+ * HTTP plugin should map based on subtype
28
+ */
29
+ export class RestApiResourceError extends HookedApiError {
30
+ constructor(message, { subtype, resourceType, resourceId } = {}) {
31
+ super(message, 'REST_API_RESOURCE_ERROR');
32
+ this.code = 'REST_API_RESOURCE';
33
+ this.type = 'rest_api_resource';
34
+ this.subtype = subtype; // 'not_found', 'conflict', 'forbidden'
35
+ this.details = {
36
+ resourceType,
37
+ resourceId
38
+ };
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Payload structure errors (malformed JSON:API documents)
44
+ * HTTP plugin should map this to 400 Bad Request
45
+ */
46
+ export class RestApiPayloadError extends HookedApiError {
47
+ constructor(message, { path, expected, received } = {}) {
48
+ super(message, 'REST_API_PAYLOAD_ERROR');
49
+ this.code = 'REST_API_PAYLOAD';
50
+ this.type = 'rest_api_payload';
51
+ this.path = path;
52
+ this.details = {
53
+ path,
54
+ expected,
55
+ received
56
+ };
57
+ }
58
+ }
package/package.json CHANGED
@@ -1,35 +1,52 @@
1
1
  {
2
2
  "name": "json-rest-api",
3
- "version": "0.1.1",
4
- "description": "A simple lightweight REST API that receives and responds to JSON HTTP requests, supports all verbs. Very simple.",
3
+ "version": "1.0.1",
5
4
  "main": "index.js",
5
+ "type": "module",
6
6
  "scripts": {
7
- "test": "./node_modules/.bin/mocha --reporter list ./test.js"
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git://github.com/stdarg/json-rest-api.git"
11
+ "url": "git+https://github.com/mobily-enterprises/jsonrestapi.git"
12
12
  },
13
- "keywords": [
14
- "simple",
15
- "REST",
16
- "HTTP",
17
- "JSON",
18
- "API",
19
- "interface"
20
- ],
21
- "author": "Edmond Meinfelder",
22
- "license": "MIT",
13
+ "author": "Tony Mobily",
14
+ "license": "GPL-3.0-or-later",
23
15
  "bugs": {
24
- "url": "https://github.com/stdarg/json-rest-api/issues"
16
+ "url": "https://github.com/mobily-enterprises/jsonrestapi/issues"
25
17
  },
18
+ "homepage": "https://github.com/mobily-enterprises/jsonrestapi#readme",
19
+ "description": "REST API plugin for hooked-api with JSON:API compliance",
26
20
  "dependencies": {
27
- "async-err": "0.0.2",
28
- "debug": "0.7.4",
29
- "is2": "0.0.12"
21
+ "hooked-api": "^1.0.0",
22
+ "jsonrestapi-schema": "^1.0.0",
23
+ "qs": "^6.0.0"
24
+ },
25
+ "peerDependencies": {
26
+ "busboy": "^1.0.0",
27
+ "content-type": "^1.0.0",
28
+ "express": "^4.0.0",
29
+ "formidable": "^3.0.0",
30
+ "raw-body": "^2.0.0"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "express": {
34
+ "optional": true
35
+ },
36
+ "content-type": {
37
+ "optional": true
38
+ },
39
+ "raw-body": {
40
+ "optional": true
41
+ },
42
+ "busboy": {
43
+ "optional": true
44
+ },
45
+ "formidable": {
46
+ "optional": true
47
+ }
30
48
  },
31
49
  "devDependencies": {
32
- "mocha": "1.17.1",
33
- "request": "2.33.0"
50
+ "express": "^5.1.0"
34
51
  }
35
52
  }