@twin.org/api-processors 0.0.1 → 0.0.2-next.2

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.
@@ -437,6 +437,39 @@ class LoggingProcessor {
437
437
  }
438
438
  }
439
439
 
440
+ /**
441
+ * Process the JSON-LD mime type.
442
+ */
443
+ class JsonLdMimeTypeProcessor {
444
+ /**
445
+ * The namespace supported by the processor.
446
+ */
447
+ static NAMESPACE = "json-ld";
448
+ /**
449
+ * Runtime name for the class.
450
+ */
451
+ CLASS_NAME = "JsonLdMimeTypeProcessor";
452
+ /**
453
+ * Get the MIME types that this handler can handle.
454
+ * @returns The MIME types that this handler can handle.
455
+ */
456
+ getTypes() {
457
+ return [web.MimeTypes.JsonLd];
458
+ }
459
+ /**
460
+ * Handle content.
461
+ * @param body The body to process.
462
+ * @returns The processed body.
463
+ */
464
+ async handle(body) {
465
+ const json = core.ObjectHelper.fromBytes(body);
466
+ if (core.Is.empty(json) || core.Is.empty(json["@context"])) {
467
+ throw new core.GeneralError(this.CLASS_NAME, "invalidJsonLd");
468
+ }
469
+ return json;
470
+ }
471
+ }
472
+
440
473
  /**
441
474
  * Process the JWT mime type.
442
475
  */
@@ -466,6 +499,7 @@ class JwtMimeTypeProcessor {
466
499
  }
467
500
  }
468
501
 
502
+ exports.JsonLdMimeTypeProcessor = JsonLdMimeTypeProcessor;
469
503
  exports.JwtMimeTypeProcessor = JwtMimeTypeProcessor;
470
504
  exports.LoggingProcessor = LoggingProcessor;
471
505
  exports.NodeIdentityProcessor = NodeIdentityProcessor;
@@ -1,5 +1,5 @@
1
1
  import { HttpErrorHelper } from '@twin.org/api-models';
2
- import { Is, NotFoundError, Guards, ObjectHelper, Coerce, Converter } from '@twin.org/core';
2
+ import { Is, NotFoundError, Guards, ObjectHelper, Coerce, GeneralError, Converter } from '@twin.org/core';
3
3
  import { HttpStatusCode, HeaderTypes, MimeTypes } from '@twin.org/web';
4
4
  import { LoggingConnectorFactory } from '@twin.org/logging-models';
5
5
 
@@ -435,6 +435,39 @@ class LoggingProcessor {
435
435
  }
436
436
  }
437
437
 
438
+ /**
439
+ * Process the JSON-LD mime type.
440
+ */
441
+ class JsonLdMimeTypeProcessor {
442
+ /**
443
+ * The namespace supported by the processor.
444
+ */
445
+ static NAMESPACE = "json-ld";
446
+ /**
447
+ * Runtime name for the class.
448
+ */
449
+ CLASS_NAME = "JsonLdMimeTypeProcessor";
450
+ /**
451
+ * Get the MIME types that this handler can handle.
452
+ * @returns The MIME types that this handler can handle.
453
+ */
454
+ getTypes() {
455
+ return [MimeTypes.JsonLd];
456
+ }
457
+ /**
458
+ * Handle content.
459
+ * @param body The body to process.
460
+ * @returns The processed body.
461
+ */
462
+ async handle(body) {
463
+ const json = ObjectHelper.fromBytes(body);
464
+ if (Is.empty(json) || Is.empty(json["@context"])) {
465
+ throw new GeneralError(this.CLASS_NAME, "invalidJsonLd");
466
+ }
467
+ return json;
468
+ }
469
+ }
470
+
438
471
  /**
439
472
  * Process the JWT mime type.
440
473
  */
@@ -464,4 +497,4 @@ class JwtMimeTypeProcessor {
464
497
  }
465
498
  }
466
499
 
467
- export { JwtMimeTypeProcessor, LoggingProcessor, NodeIdentityProcessor, RestRouteProcessor, SocketRouteProcessor, StaticUserIdentityProcessor };
500
+ export { JsonLdMimeTypeProcessor, JwtMimeTypeProcessor, LoggingProcessor, NodeIdentityProcessor, RestRouteProcessor, SocketRouteProcessor, StaticUserIdentityProcessor };
@@ -3,6 +3,7 @@ export * from "./data/socketRouteProcessor";
3
3
  export * from "./identity/nodeIdentityProcessor";
4
4
  export * from "./identity/staticUserIdentityProcessor";
5
5
  export * from "./logging/loggingProcessor";
6
+ export * from "./mimeType/jsonLdMimeTypeProcessor";
6
7
  export * from "./mimeType/jwtMimeTypeProcessor";
7
8
  export * from "./models/ILoggingProcessorConfig";
8
9
  export * from "./models/ILoggingProcessorConstructorOptions";
@@ -0,0 +1,25 @@
1
+ import type { IMimeTypeProcessor } from "@twin.org/api-models";
2
+ /**
3
+ * Process the JSON-LD mime type.
4
+ */
5
+ export declare class JsonLdMimeTypeProcessor implements IMimeTypeProcessor {
6
+ /**
7
+ * The namespace supported by the processor.
8
+ */
9
+ static readonly NAMESPACE: string;
10
+ /**
11
+ * Runtime name for the class.
12
+ */
13
+ readonly CLASS_NAME: string;
14
+ /**
15
+ * Get the MIME types that this handler can handle.
16
+ * @returns The MIME types that this handler can handle.
17
+ */
18
+ getTypes(): string[];
19
+ /**
20
+ * Handle content.
21
+ * @param body The body to process.
22
+ * @returns The processed body.
23
+ */
24
+ handle(body: Uint8Array): Promise<unknown>;
25
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @twin.org/api-processors - Changelog
2
2
 
3
+ ## [0.0.2-next.2](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.1...api-processors-v0.0.2-next.2) (2025-07-17)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **api-processors:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/api-models bumped from 0.0.2-next.1 to 0.0.2-next.2
16
+
17
+ ## [0.0.2-next.1](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.0...api-processors-v0.0.2-next.1) (2025-07-08)
18
+
19
+
20
+ ### Features
21
+
22
+ * add json-ld mime type processor and auth admin component ([8861791](https://github.com/twinfoundation/api/commit/88617916e23bfbca023dbae1976fe421983a02ff))
23
+ * update dependencies ([1171dc4](https://github.com/twinfoundation/api/commit/1171dc416a9481737f6a640e3cf30145768f37e9))
24
+ * use shared store mechanism ([#19](https://github.com/twinfoundation/api/issues/19)) ([32116df](https://github.com/twinfoundation/api/commit/32116df3b4380a30137f5056f242a5c99afa2df9))
25
+
26
+
27
+ ### Dependencies
28
+
29
+ * The following workspace dependencies were updated
30
+ * dependencies
31
+ * @twin.org/api-models bumped from 0.0.2-next.0 to 0.0.2-next.1
32
+
3
33
  ## 0.0.1 (2025-07-03)
4
34
 
5
35
 
@@ -0,0 +1,81 @@
1
+ # Class: JsonLdMimeTypeProcessor
2
+
3
+ Process the JSON-LD mime type.
4
+
5
+ ## Implements
6
+
7
+ - `IMimeTypeProcessor`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new JsonLdMimeTypeProcessor**(): `JsonLdMimeTypeProcessor`
14
+
15
+ #### Returns
16
+
17
+ `JsonLdMimeTypeProcessor`
18
+
19
+ ## Properties
20
+
21
+ ### NAMESPACE
22
+
23
+ > `readonly` `static` **NAMESPACE**: `string` = `"json-ld"`
24
+
25
+ The namespace supported by the processor.
26
+
27
+ ***
28
+
29
+ ### CLASS\_NAME
30
+
31
+ > `readonly` **CLASS\_NAME**: `string`
32
+
33
+ Runtime name for the class.
34
+
35
+ #### Implementation of
36
+
37
+ `IMimeTypeProcessor.CLASS_NAME`
38
+
39
+ ## Methods
40
+
41
+ ### getTypes()
42
+
43
+ > **getTypes**(): `string`[]
44
+
45
+ Get the MIME types that this handler can handle.
46
+
47
+ #### Returns
48
+
49
+ `string`[]
50
+
51
+ The MIME types that this handler can handle.
52
+
53
+ #### Implementation of
54
+
55
+ `IMimeTypeProcessor.getTypes`
56
+
57
+ ***
58
+
59
+ ### handle()
60
+
61
+ > **handle**(`body`): `Promise`\<`unknown`\>
62
+
63
+ Handle content.
64
+
65
+ #### Parameters
66
+
67
+ ##### body
68
+
69
+ `Uint8Array`
70
+
71
+ The body to process.
72
+
73
+ #### Returns
74
+
75
+ `Promise`\<`unknown`\>
76
+
77
+ The processed body.
78
+
79
+ #### Implementation of
80
+
81
+ `IMimeTypeProcessor.handle`
@@ -7,6 +7,7 @@
7
7
  - [NodeIdentityProcessor](classes/NodeIdentityProcessor.md)
8
8
  - [StaticUserIdentityProcessor](classes/StaticUserIdentityProcessor.md)
9
9
  - [LoggingProcessor](classes/LoggingProcessor.md)
10
+ - [JsonLdMimeTypeProcessor](classes/JsonLdMimeTypeProcessor.md)
10
11
  - [JwtMimeTypeProcessor](classes/JwtMimeTypeProcessor.md)
11
12
 
12
13
  ## Interfaces
package/locales/en.json CHANGED
@@ -10,6 +10,9 @@
10
10
  "jwtMissing": "The JSON Web token could not be found in the authorization header or a cookie",
11
11
  "jwtSignatureInvalid": "The JSON Web token signature could not be validated",
12
12
  "jwtExpired": "The JSON Web token has expired"
13
+ },
14
+ "jsonLdMimeTypeProcessor": {
15
+ "invalidJsonLd": "The JSON-LD content is invalid or missing '@context'."
13
16
  }
14
17
  }
15
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-processors",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-next.2",
4
4
  "description": "Route processors for use with API servers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,13 +14,11 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/api-models": "^0.0.1",
18
- "@twin.org/core": "^0.0.1",
19
- "@twin.org/entity": "^0.0.1",
20
- "@twin.org/entity-storage-models": "^0.0.1-next.2",
21
- "@twin.org/logging-models": "^0.0.1-next.2",
22
- "@twin.org/nameof": "^0.0.1",
23
- "@twin.org/web": "^0.0.1"
17
+ "@twin.org/api-models": "0.0.2-next.2",
18
+ "@twin.org/core": "next",
19
+ "@twin.org/logging-models": "next",
20
+ "@twin.org/nameof": "next",
21
+ "@twin.org/web": "next"
24
22
  },
25
23
  "main": "./dist/cjs/index.cjs",
26
24
  "module": "./dist/esm/index.mjs",