@boostercloud/framework-provider-azure 2.0.0 → 2.1.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.
- package/dist/index.js +11 -0
- package/dist/library/health-adapter.d.ts +15 -0
- package/dist/library/health-adapter.js +111 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const events_searcher_adapter_1 = require("./library/events-searcher-adapter");
|
|
|
14
14
|
const subscription_adapter_1 = require("./library/subscription-adapter");
|
|
15
15
|
const connections_adapter_1 = require("./library/connections-adapter");
|
|
16
16
|
const rocket_adapter_1 = require("./library/rocket-adapter");
|
|
17
|
+
const health_adapter_1 = require("./library/health-adapter");
|
|
17
18
|
let cosmosClient;
|
|
18
19
|
if (typeof process.env[constants_1.environmentVarNames.cosmosDbConnectionString] === 'undefined') {
|
|
19
20
|
cosmosClient = {};
|
|
@@ -75,6 +76,16 @@ const Provider = (rockets) => ({
|
|
|
75
76
|
rockets: {
|
|
76
77
|
rawToEnvelopes: rocket_adapter_1.rawRocketInputToEnvelope,
|
|
77
78
|
},
|
|
79
|
+
sensor: {
|
|
80
|
+
databaseEventsHealthDetails: health_adapter_1.databaseEventsHealthDetails.bind(null, cosmosClient),
|
|
81
|
+
databaseReadModelsHealthDetails: health_adapter_1.databaseReadModelsHealthDetails.bind(null, cosmosClient),
|
|
82
|
+
isDatabaseEventUp: health_adapter_1.isDatabaseEventUp.bind(null, cosmosClient),
|
|
83
|
+
areDatabaseReadModelsUp: health_adapter_1.areDatabaseReadModelsUp.bind(null, cosmosClient),
|
|
84
|
+
databaseUrls: health_adapter_1.databaseUrl.bind(null, cosmosClient),
|
|
85
|
+
graphQLFunctionUrl: health_adapter_1.graphqlFunctionUrl,
|
|
86
|
+
isGraphQLFunctionUp: health_adapter_1.isGraphQLFunctionUp,
|
|
87
|
+
rawRequestToHealthEnvelope: health_adapter_1.rawRequestToSensorHealth,
|
|
88
|
+
},
|
|
78
89
|
// ProviderInfrastructureGetter
|
|
79
90
|
infrastructure: () => {
|
|
80
91
|
const infrastructurePackageName = require('../package.json').name + '-infrastructure';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BoosterConfig, HealthEnvelope } from '@boostercloud/framework-types';
|
|
2
|
+
import { Container, CosmosClient } from '@azure/cosmos';
|
|
3
|
+
import { Context } from '@azure/functions';
|
|
4
|
+
export declare function databaseUrl(cosmosDb: CosmosClient, config: BoosterConfig): Promise<Array<string>>;
|
|
5
|
+
export declare function getContainer(cosmosDb: CosmosClient, config: BoosterConfig, containerName: string): Container;
|
|
6
|
+
export declare function isContainerUp(cosmosDb: CosmosClient, config: BoosterConfig, containerName: string): Promise<boolean>;
|
|
7
|
+
export declare function countAll(container: Container): Promise<number>;
|
|
8
|
+
export declare function databaseEventsHealthDetails(cosmosDb: CosmosClient, config: BoosterConfig): Promise<unknown>;
|
|
9
|
+
export declare function graphqlFunctionUrl(): Promise<string>;
|
|
10
|
+
export declare function isDatabaseEventUp(cosmosDb: CosmosClient, config: BoosterConfig): Promise<boolean>;
|
|
11
|
+
export declare function areDatabaseReadModelsUp(cosmosDb: CosmosClient, config: BoosterConfig): Promise<boolean>;
|
|
12
|
+
export declare function isGraphQLFunctionUp(): Promise<boolean>;
|
|
13
|
+
export declare function rawRequestToSensorHealthComponentPath(rawRequest: Context): string;
|
|
14
|
+
export declare function rawRequestToSensorHealth(context: Context): HealthEnvelope;
|
|
15
|
+
export declare function databaseReadModelsHealthDetails(cosmosDb: CosmosClient, config: BoosterConfig): Promise<unknown>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.databaseReadModelsHealthDetails = exports.rawRequestToSensorHealth = exports.rawRequestToSensorHealthComponentPath = exports.isGraphQLFunctionUp = exports.areDatabaseReadModelsUp = exports.isDatabaseEventUp = exports.graphqlFunctionUrl = exports.databaseEventsHealthDetails = exports.countAll = exports.isContainerUp = exports.getContainer = exports.databaseUrl = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const framework_common_helpers_1 = require("@boostercloud/framework-common-helpers");
|
|
6
|
+
async function databaseUrl(cosmosDb, config) {
|
|
7
|
+
const database = cosmosDb.database(config.resourceNames.applicationStack);
|
|
8
|
+
return [database.url];
|
|
9
|
+
}
|
|
10
|
+
exports.databaseUrl = databaseUrl;
|
|
11
|
+
function getContainer(cosmosDb, config, containerName) {
|
|
12
|
+
return cosmosDb.database(config.resourceNames.applicationStack).container(containerName);
|
|
13
|
+
}
|
|
14
|
+
exports.getContainer = getContainer;
|
|
15
|
+
async function isContainerUp(cosmosDb, config, containerName) {
|
|
16
|
+
const container = getContainer(cosmosDb, config, containerName);
|
|
17
|
+
const { resources } = await container.items.query('SELECT TOP 1 1 FROM c', { maxItemCount: -1 }).fetchAll();
|
|
18
|
+
return resources !== undefined;
|
|
19
|
+
}
|
|
20
|
+
exports.isContainerUp = isContainerUp;
|
|
21
|
+
async function countAll(container) {
|
|
22
|
+
const { resources } = await container.items.query('SELECT VALUE COUNT(1) FROM c', { maxItemCount: -1 }).fetchAll();
|
|
23
|
+
return resources ? resources[0] : 0;
|
|
24
|
+
}
|
|
25
|
+
exports.countAll = countAll;
|
|
26
|
+
async function databaseEventsHealthDetails(cosmosDb, config) {
|
|
27
|
+
const container = getContainer(cosmosDb, config, config.resourceNames.eventsStore);
|
|
28
|
+
const url = container.url;
|
|
29
|
+
const count = await countAll(container);
|
|
30
|
+
return {
|
|
31
|
+
url: url,
|
|
32
|
+
count: count,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.databaseEventsHealthDetails = databaseEventsHealthDetails;
|
|
36
|
+
async function graphqlFunctionUrl() {
|
|
37
|
+
try {
|
|
38
|
+
const basePath = process.env[constants_1.environmentVarNames.restAPIURL];
|
|
39
|
+
return `${basePath}/graphql`;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.graphqlFunctionUrl = graphqlFunctionUrl;
|
|
46
|
+
async function isDatabaseEventUp(cosmosDb, config) {
|
|
47
|
+
return await isContainerUp(cosmosDb, config, config.resourceNames.eventsStore);
|
|
48
|
+
}
|
|
49
|
+
exports.isDatabaseEventUp = isDatabaseEventUp;
|
|
50
|
+
async function areDatabaseReadModelsUp(cosmosDb, config) {
|
|
51
|
+
const promises = Object.values(config.readModels).map((readModel) => {
|
|
52
|
+
const name = readModel.class.name;
|
|
53
|
+
const container = config.resourceNames.forReadModel(name);
|
|
54
|
+
return isContainerUp(cosmosDb, config, container);
|
|
55
|
+
});
|
|
56
|
+
const containersUp = await Promise.all(promises);
|
|
57
|
+
return containersUp.every((isContainerUp) => isContainerUp);
|
|
58
|
+
}
|
|
59
|
+
exports.areDatabaseReadModelsUp = areDatabaseReadModelsUp;
|
|
60
|
+
async function isGraphQLFunctionUp() {
|
|
61
|
+
try {
|
|
62
|
+
const restAPIUrl = await graphqlFunctionUrl();
|
|
63
|
+
const response = await (0, framework_common_helpers_1.request)(restAPIUrl, 'POST');
|
|
64
|
+
return response.status === 200;
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.isGraphQLFunctionUp = isGraphQLFunctionUp;
|
|
71
|
+
function rawRequestToSensorHealthComponentPath(rawRequest) {
|
|
72
|
+
var _a;
|
|
73
|
+
const parameters = (_a = rawRequest.req) === null || _a === void 0 ? void 0 : _a.url.replace(/^.*sensor\/health\/?/, '');
|
|
74
|
+
return parameters !== null && parameters !== void 0 ? parameters : '';
|
|
75
|
+
}
|
|
76
|
+
exports.rawRequestToSensorHealthComponentPath = rawRequestToSensorHealthComponentPath;
|
|
77
|
+
function rawRequestToSensorHealth(context) {
|
|
78
|
+
var _a, _b, _c, _d;
|
|
79
|
+
const componentPath = rawRequestToSensorHealthComponentPath(context);
|
|
80
|
+
const requestID = context.executionContext.invocationId;
|
|
81
|
+
return {
|
|
82
|
+
requestID: requestID,
|
|
83
|
+
context: {
|
|
84
|
+
request: {
|
|
85
|
+
headers: (_a = context.req) === null || _a === void 0 ? void 0 : _a.headers,
|
|
86
|
+
body: (_b = context.req) === null || _b === void 0 ? void 0 : _b.body,
|
|
87
|
+
},
|
|
88
|
+
rawContext: context,
|
|
89
|
+
},
|
|
90
|
+
componentPath: componentPath,
|
|
91
|
+
token: (_d = (_c = context.req) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? void 0 : _d.authorization,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
exports.rawRequestToSensorHealth = rawRequestToSensorHealth;
|
|
95
|
+
async function databaseReadModelsHealthDetails(cosmosDb, config) {
|
|
96
|
+
const readModels = Object.values(config.readModels);
|
|
97
|
+
const result = [];
|
|
98
|
+
for (const readModel of readModels) {
|
|
99
|
+
const name = readModel.class.name;
|
|
100
|
+
const containerName = config.resourceNames.forReadModel(name);
|
|
101
|
+
const container = getContainer(cosmosDb, config, containerName);
|
|
102
|
+
const url = container.url;
|
|
103
|
+
const count = await countAll(container);
|
|
104
|
+
result.push({
|
|
105
|
+
url: url,
|
|
106
|
+
count: count,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
exports.databaseReadModelsHealthDetails = databaseReadModelsHealthDetails;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boostercloud/framework-provider-azure",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Handle Booster's integration with Azure",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework-provider-azure"
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"@azure/cosmos": "^4.0.0",
|
|
27
27
|
"@azure/functions": "^1.2.2",
|
|
28
28
|
"@azure/identity": "~2.1.0",
|
|
29
|
-
"@boostercloud/framework-common-helpers": "^2.
|
|
30
|
-
"@boostercloud/framework-types": "^2.
|
|
29
|
+
"@boostercloud/framework-common-helpers": "^2.1.0",
|
|
30
|
+
"@boostercloud/framework-types": "^2.1.0",
|
|
31
31
|
"tslib": "^2.4.0",
|
|
32
32
|
"@effect-ts/core": "^0.60.4",
|
|
33
33
|
"@azure/web-pubsub": "~1.1.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@boostercloud/eslint-config": "^2.
|
|
36
|
+
"@boostercloud/eslint-config": "^2.1.0",
|
|
37
37
|
"@types/chai": "4.2.18",
|
|
38
38
|
"@types/chai-as-promised": "7.1.4",
|
|
39
39
|
"@types/faker": "5.1.5",
|