@3sixty/api-service 0.0.0-stage → 0.20.0-next.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 (71) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +24 -2
  3. package/dist/es/healthApplicationTask.js +151 -0
  4. package/dist/es/healthApplicationTask.js.map +1 -0
  5. package/dist/es/healthRoutes.js +116 -0
  6. package/dist/es/healthRoutes.js.map +1 -0
  7. package/dist/es/healthService.js +308 -0
  8. package/dist/es/healthService.js.map +1 -0
  9. package/dist/es/index.js +15 -0
  10. package/dist/es/index.js.map +1 -0
  11. package/dist/es/informationRoutes.js +298 -0
  12. package/dist/es/informationRoutes.js.map +1 -0
  13. package/dist/es/informationService.js +123 -0
  14. package/dist/es/informationService.js.map +1 -0
  15. package/dist/es/models/IHealthServiceConfig.js +4 -0
  16. package/dist/es/models/IHealthServiceConfig.js.map +1 -0
  17. package/dist/es/models/IHealthServiceConstructorOptions.js +2 -0
  18. package/dist/es/models/IHealthServiceConstructorOptions.js.map +1 -0
  19. package/dist/es/models/IInformationServiceConfig.js +2 -0
  20. package/dist/es/models/IInformationServiceConfig.js.map +1 -0
  21. package/dist/es/models/IInformationServiceConstructorOptions.js +2 -0
  22. package/dist/es/models/IInformationServiceConstructorOptions.js.map +1 -0
  23. package/dist/es/models/IPlatformServiceConfig.js +4 -0
  24. package/dist/es/models/IPlatformServiceConfig.js.map +1 -0
  25. package/dist/es/models/IPlatformServiceConstructorOptions.js +2 -0
  26. package/dist/es/models/IPlatformServiceConstructorOptions.js.map +1 -0
  27. package/dist/es/platformService.js +159 -0
  28. package/dist/es/platformService.js.map +1 -0
  29. package/dist/es/restEntryPoints.js +20 -0
  30. package/dist/es/restEntryPoints.js.map +1 -0
  31. package/dist/types/healthApplicationTask.d.ts +20 -0
  32. package/dist/types/healthRoutes.d.ts +20 -0
  33. package/dist/types/healthService.d.ts +42 -0
  34. package/dist/types/index.d.ts +12 -0
  35. package/dist/types/informationRoutes.d.ts +60 -0
  36. package/dist/types/informationService.d.ts +60 -0
  37. package/dist/types/models/IHealthServiceConfig.d.ts +37 -0
  38. package/dist/types/models/IHealthServiceConstructorOptions.d.ts +15 -0
  39. package/dist/types/models/IInformationServiceConfig.d.ts +18 -0
  40. package/dist/types/models/IInformationServiceConstructorOptions.d.ts +10 -0
  41. package/dist/types/models/IPlatformServiceConfig.d.ts +10 -0
  42. package/dist/types/models/IPlatformServiceConstructorOptions.d.ts +15 -0
  43. package/dist/types/platformService.d.ts +39 -0
  44. package/dist/types/restEntryPoints.d.ts +5 -0
  45. package/docs/changelog.md +0 -0
  46. package/docs/examples.md +74 -0
  47. package/docs/open-api/spec.json +712 -0
  48. package/docs/reference/classes/HealthService.md +127 -0
  49. package/docs/reference/classes/InformationService.md +179 -0
  50. package/docs/reference/classes/PlatformService.md +123 -0
  51. package/docs/reference/functions/generateRestRoutesHealth.md +25 -0
  52. package/docs/reference/functions/generateRestRoutesInformation.md +25 -0
  53. package/docs/reference/functions/serverFavIcon.md +31 -0
  54. package/docs/reference/functions/serverHealth.md +31 -0
  55. package/docs/reference/functions/serverInfo.md +31 -0
  56. package/docs/reference/functions/serverLivez.md +31 -0
  57. package/docs/reference/functions/serverReadyz.md +31 -0
  58. package/docs/reference/functions/serverRoot.md +31 -0
  59. package/docs/reference/functions/serverSpec.md +31 -0
  60. package/docs/reference/index.md +34 -0
  61. package/docs/reference/interfaces/IHealthServiceConfig.md +79 -0
  62. package/docs/reference/interfaces/IHealthServiceConstructorOptions.md +25 -0
  63. package/docs/reference/interfaces/IInformationServiceConfig.md +27 -0
  64. package/docs/reference/interfaces/IInformationServiceConstructorOptions.md +11 -0
  65. package/docs/reference/interfaces/IPlatformServiceConfig.md +17 -0
  66. package/docs/reference/interfaces/IPlatformServiceConstructorOptions.md +25 -0
  67. package/docs/reference/variables/restEntryPoints.md +5 -0
  68. package/docs/reference/variables/tagsHealth.md +5 -0
  69. package/docs/reference/variables/tagsInformation.md +5 -0
  70. package/locales/en.json +11 -0
  71. package/package.json +57 -5
@@ -0,0 +1,60 @@
1
+ import type { IInformationComponent, IServerInfo } from "@3sixty/api-models";
2
+ import type { IInformationServiceConstructorOptions } from "./models/IInformationServiceConstructorOptions.js";
3
+ /**
4
+ * The information service for the server.
5
+ */
6
+ export declare class InformationService implements IInformationComponent {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static readonly CLASS_NAME: string;
11
+ /**
12
+ * Create a new instance of InformationService.
13
+ * @param options The options to create the service.
14
+ */
15
+ constructor(options: IInformationServiceConstructorOptions);
16
+ /**
17
+ * Returns the class name of the component.
18
+ * @returns The class name of the component.
19
+ */
20
+ className(): string;
21
+ /**
22
+ * The service needs to be started when the application is initialized.
23
+ * @returns A promise that resolves when the OpenAPI spec and favicon have been loaded from disk.
24
+ */
25
+ start(): Promise<void>;
26
+ /**
27
+ * Get the root information.
28
+ * @returns The root information.
29
+ */
30
+ root(): Promise<string>;
31
+ /**
32
+ * Get the server information.
33
+ * @returns The service information.
34
+ */
35
+ info(): Promise<IServerInfo>;
36
+ /**
37
+ * Get the favicon.
38
+ * @returns The favicon.
39
+ */
40
+ favicon(): Promise<Uint8Array | undefined>;
41
+ /**
42
+ * Get the OpenAPI spec.
43
+ * @returns The OpenAPI spec.
44
+ */
45
+ spec(): Promise<unknown>;
46
+ /**
47
+ * Is the server live.
48
+ * @returns The liveness status of the server.
49
+ */
50
+ livez(): Promise<{
51
+ status: "alive" | "dead";
52
+ }>;
53
+ /**
54
+ * Is the server ready.
55
+ * @returns The readyz status of the server.
56
+ */
57
+ readyz(): Promise<{
58
+ status: "ready" | "not ready";
59
+ }>;
60
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Configuration for the health service.
3
+ */
4
+ export interface IHealthServiceConfig {
5
+ /**
6
+ * The interval for checking the health of the components.
7
+ * @default 60000
8
+ */
9
+ healthCheckInterval?: number;
10
+ /**
11
+ * The interval for running the application health lifecycle (init, application, teardown).
12
+ * @default 300000
13
+ */
14
+ healthCheckApplicationInterval?: number;
15
+ /**
16
+ * The initial interval for checking the health of the components and setting it in the health service.
17
+ * This is used to check the health of the components immediately after the service is started.
18
+ * @default 2000
19
+ */
20
+ initialInterval?: number;
21
+ /**
22
+ * Whether to include stack traces in health check error details.
23
+ * @default false
24
+ */
25
+ includeErrorStack?: boolean;
26
+ /**
27
+ * The URL of the module to use for the application health background task.
28
+ * If not provided, the default healthApplicationTask module will be used.
29
+ */
30
+ overrideApplicationHealthTaskHandler?: string;
31
+ /**
32
+ * The component types to exclude from the engine clone used by the application health
33
+ * background task. Each entry is a regular expression matched against the engine config
34
+ * type keys, for example "^rightsManagement" or "messaging.*Connector".
35
+ */
36
+ excludeCloneComponents?: string[];
37
+ }
@@ -0,0 +1,15 @@
1
+ import type { IHealthServiceConfig } from "./IHealthServiceConfig.js";
2
+ /**
3
+ * Options for the HealthService constructor.
4
+ */
5
+ export interface IHealthServiceConstructorOptions {
6
+ /**
7
+ * The background task component type to use for running application health checks.
8
+ * @default background-task
9
+ */
10
+ backgroundTaskComponentType?: string;
11
+ /**
12
+ * The configuration for the service.
13
+ */
14
+ config?: IHealthServiceConfig;
15
+ }
@@ -0,0 +1,18 @@
1
+ import type { IServerInfo } from "@3sixty/api-models";
2
+ /**
3
+ * Configuration for the information service.
4
+ */
5
+ export interface IInformationServiceConfig {
6
+ /**
7
+ * The server information.
8
+ */
9
+ serverInfo: IServerInfo;
10
+ /**
11
+ * The path to the OpenAPI Spec.
12
+ */
13
+ openApiSpecPath?: string;
14
+ /**
15
+ * The path to the favicon.
16
+ */
17
+ favIconPath?: string;
18
+ }
@@ -0,0 +1,10 @@
1
+ import type { IInformationServiceConfig } from "./IInformationServiceConfig.js";
2
+ /**
3
+ * Options for the InformationService constructor.
4
+ */
5
+ export interface IInformationServiceConstructorOptions {
6
+ /**
7
+ * The configuration for the service.
8
+ */
9
+ config: IInformationServiceConfig;
10
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Configuration for the platform service
3
+ */
4
+ export interface IPlatformServiceConfig {
5
+ /**
6
+ * Indicates whether the service is running in a multi-tenant environment.
7
+ * @default false
8
+ */
9
+ isMultiTenant?: boolean;
10
+ }
@@ -0,0 +1,15 @@
1
+ import type { IPlatformServiceConfig } from "./IPlatformServiceConfig.js";
2
+ /**
3
+ * Options for the Platform Service constructor.
4
+ */
5
+ export interface IPlatformServiceConstructorOptions {
6
+ /**
7
+ * The entity storage for the tenants.
8
+ * @default tenant
9
+ */
10
+ tenantEntityStorageType?: string;
11
+ /**
12
+ * Configuration for the service.
13
+ */
14
+ config?: IPlatformServiceConfig;
15
+ }
@@ -0,0 +1,39 @@
1
+ import { type IPlatformComponent } from "@3sixty/api-models";
2
+ import { type IContextIds } from "@3sixty/context";
3
+ import type { IPlatformServiceConstructorOptions } from "./models/IPlatformServiceConstructorOptions.js";
4
+ /**
5
+ * Service for performing platform operations.
6
+ */
7
+ export declare class PlatformService implements IPlatformComponent {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of PlatformService.
14
+ * @param options The options for the connector.
15
+ */
16
+ constructor(options?: IPlatformServiceConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
22
+ /**
23
+ * Indicates whether the component is running in a multi-tenant environment.
24
+ * @returns True if the component is running in a multi-tenant environment, false otherwise.
25
+ */
26
+ isMultiTenant(): boolean;
27
+ /**
28
+ * Execute a method, if single tenant will run once, if multi-tenant will run for each tenant.
29
+ * @param method The method to run for each tenant, returning false will stop any further iterations.
30
+ * @returns A promise that resolves when the method has been executed for all applicable tenants.
31
+ */
32
+ execute(method: () => Promise<undefined | boolean> | Promise<void>): Promise<void>;
33
+ /**
34
+ * Get the local origin context IDs for the given URL.
35
+ * @param url The URL to check.
36
+ * @returns A promise that resolves to the context IDs if the URL is a local origin, undefined otherwise.
37
+ */
38
+ getLocalOriginContext(url: string): Promise<IContextIds | undefined>;
39
+ }
@@ -0,0 +1,5 @@
1
+ import type { IRestRouteEntryPoint } from "@3sixty/api-models";
2
+ /**
3
+ * REST entry points for the information and health services.
4
+ */
5
+ export declare const restEntryPoints: IRestRouteEntryPoint[];
File without changes
@@ -0,0 +1,74 @@
1
+ # Service Examples
2
+
3
+ These snippets demonstrate how to configure service-level URL generation and expose operational information for monitoring.
4
+
5
+ ## InformationService
6
+
7
+ ```typescript
8
+ import { InformationService } from '@3sixty/api-service';
9
+
10
+ const infoService = new InformationService({
11
+ config: {
12
+ serverInfo: {
13
+ name: '3Sixty API',
14
+ version: '1.2.0'
15
+ }
16
+ }
17
+ });
18
+
19
+ await infoService.start();
20
+ console.log(infoService.className()); // InformationService
21
+
22
+ const root = await infoService.root();
23
+ const info = await infoService.info();
24
+ const favicon = await infoService.favicon();
25
+
26
+ console.log(root); // 3Sixty API - 1.2.0
27
+ console.log(info.version); // 1.2.0
28
+ console.log((favicon?.byteLength ?? 0) > 0); // true
29
+ ```
30
+
31
+ ```typescript
32
+ import { InformationService } from '@3sixty/api-service';
33
+
34
+ const infoService = new InformationService({
35
+ config: {
36
+ serverInfo: {
37
+ name: '3Sixty API',
38
+ version: '1.2.0'
39
+ }
40
+ }
41
+ });
42
+
43
+ const spec = await infoService.spec();
44
+ const live = await infoService.livez();
45
+ const health = await infoService.health();
46
+
47
+ await infoService.setComponentHealth('queue', 'ok');
48
+ await infoService.removeComponentHealth('queue');
49
+
50
+ console.log(typeof spec); // undefined
51
+ console.log(live); // true
52
+ console.log(health.status); // ok
53
+ ```
54
+
55
+ ## HostingService
56
+
57
+ ```typescript
58
+ import { HostingService } from '@3sixty/api-service';
59
+
60
+ const hostingService = new HostingService({
61
+ config: {
62
+ localOrigin: 'http://localhost:3000',
63
+ publicOrigin: 'https://api.example.org'
64
+ }
65
+ });
66
+
67
+ console.log(hostingService.className()); // HostingService
68
+
69
+ const publicOrigin = await hostingService.getPublicOrigin('http://localhost:3000/users');
70
+ const usersUrl = await hostingService.buildPublicUrl('http://localhost:3000/users');
71
+
72
+ console.log(publicOrigin); // https://api.example.org
73
+ console.log(usersUrl); // https://api.example.org/users
74
+ ```