@boostercloud/framework-provider-azure 2.0.0 → 2.2.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/constants.d.ts +8 -0
- package/dist/constants.js +9 -1
- package/dist/index.js +44 -0
- package/dist/library/events-stream-consumer-adapter.d.ts +5 -0
- package/dist/library/events-stream-consumer-adapter.js +54 -0
- package/dist/library/events-stream-producer-adapter.d.ts +3 -0
- package/dist/library/events-stream-producer-adapter.js +43 -0
- package/dist/library/health-adapter.d.ts +15 -0
- package/dist/library/health-adapter.js +111 -0
- package/package.json +5 -4
package/dist/constants.d.ts
CHANGED
|
@@ -15,10 +15,18 @@ export declare const connectionsStoreAttributes: {
|
|
|
15
15
|
readonly partitionKey: "connectionID";
|
|
16
16
|
readonly ttl: "expirationTime";
|
|
17
17
|
};
|
|
18
|
+
export declare const dedupAttributes: {
|
|
19
|
+
readonly partitionKey: "primaryKey";
|
|
20
|
+
readonly ttl: "expirationTime";
|
|
21
|
+
};
|
|
18
22
|
export declare const environmentVarNames: {
|
|
19
23
|
readonly restAPIURL: "BOOSTER_REST_API_URL";
|
|
20
24
|
readonly websocketAPIURL: "BOOSTER_WEBSOCKET_API_URL";
|
|
21
25
|
readonly cosmosDbConnectionString: "COSMOSDB_CONNECTION_STRING";
|
|
26
|
+
readonly eventHubConnectionString: "EVENTHUB_CONNECTION_STRING";
|
|
27
|
+
readonly eventHubName: "EVENTHUB_NAME";
|
|
28
|
+
readonly eventHubMaxRetries: "EVENTHUB_MAX_RETRIES";
|
|
29
|
+
readonly eventHubMode: "EVENTHUB_MODE";
|
|
22
30
|
};
|
|
23
31
|
export declare const AZURE_CONFLICT_ERROR_CODE = 409;
|
|
24
32
|
export declare const AZURE_PRECONDITION_FAILED_ERROR = 412;
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AZURE_PRECONDITION_FAILED_ERROR = exports.AZURE_CONFLICT_ERROR_CODE = exports.environmentVarNames = exports.connectionsStoreAttributes = exports.subscriptionsStoreAttributes = exports.eventsStoreAttributes = void 0;
|
|
3
|
+
exports.AZURE_PRECONDITION_FAILED_ERROR = exports.AZURE_CONFLICT_ERROR_CODE = exports.environmentVarNames = exports.dedupAttributes = exports.connectionsStoreAttributes = exports.subscriptionsStoreAttributes = exports.eventsStoreAttributes = void 0;
|
|
4
4
|
exports.eventsStoreAttributes = {
|
|
5
5
|
partitionKey: 'entityTypeName_entityID_kind',
|
|
6
6
|
sortKey: 'createdAt',
|
|
@@ -17,10 +17,18 @@ exports.connectionsStoreAttributes = {
|
|
|
17
17
|
partitionKey: 'connectionID',
|
|
18
18
|
ttl: 'expirationTime',
|
|
19
19
|
};
|
|
20
|
+
exports.dedupAttributes = {
|
|
21
|
+
partitionKey: 'primaryKey',
|
|
22
|
+
ttl: 'expirationTime',
|
|
23
|
+
};
|
|
20
24
|
exports.environmentVarNames = {
|
|
21
25
|
restAPIURL: 'BOOSTER_REST_API_URL',
|
|
22
26
|
websocketAPIURL: 'BOOSTER_WEBSOCKET_API_URL',
|
|
23
27
|
cosmosDbConnectionString: 'COSMOSDB_CONNECTION_STRING',
|
|
28
|
+
eventHubConnectionString: 'EVENTHUB_CONNECTION_STRING',
|
|
29
|
+
eventHubName: 'EVENTHUB_NAME',
|
|
30
|
+
eventHubMaxRetries: 'EVENTHUB_MAX_RETRIES',
|
|
31
|
+
eventHubMode: 'EVENTHUB_MODE',
|
|
24
32
|
};
|
|
25
33
|
// Azure special error codes
|
|
26
34
|
exports.AZURE_CONFLICT_ERROR_CODE = 409;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.Provider = exports.loadInfrastructurePackage = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -14,6 +15,10 @@ const events_searcher_adapter_1 = require("./library/events-searcher-adapter");
|
|
|
14
15
|
const subscription_adapter_1 = require("./library/subscription-adapter");
|
|
15
16
|
const connections_adapter_1 = require("./library/connections-adapter");
|
|
16
17
|
const rocket_adapter_1 = require("./library/rocket-adapter");
|
|
18
|
+
const events_stream_producer_adapter_1 = require("./library/events-stream-producer-adapter");
|
|
19
|
+
const event_hubs_1 = require("@azure/event-hubs");
|
|
20
|
+
const events_stream_consumer_adapter_1 = require("./library/events-stream-consumer-adapter");
|
|
21
|
+
const health_adapter_1 = require("./library/health-adapter");
|
|
17
22
|
let cosmosClient;
|
|
18
23
|
if (typeof process.env[constants_1.environmentVarNames.cosmosDbConnectionString] === 'undefined') {
|
|
19
24
|
cosmosClient = {};
|
|
@@ -21,6 +26,32 @@ if (typeof process.env[constants_1.environmentVarNames.cosmosDbConnectionString]
|
|
|
21
26
|
else {
|
|
22
27
|
cosmosClient = new cosmos_1.CosmosClient(process.env[constants_1.environmentVarNames.cosmosDbConnectionString]);
|
|
23
28
|
}
|
|
29
|
+
let producer;
|
|
30
|
+
const eventHubConnectionString = process.env[constants_1.environmentVarNames.eventHubConnectionString];
|
|
31
|
+
const eventHubName = process.env[constants_1.environmentVarNames.eventHubName];
|
|
32
|
+
const DEFAULT_MAX_RETRY = 5;
|
|
33
|
+
const DEFAULT_EVENT_HUB_MODE = event_hubs_1.RetryMode.Exponential;
|
|
34
|
+
if (typeof eventHubConnectionString === 'undefined' ||
|
|
35
|
+
typeof eventHubName === 'undefined' ||
|
|
36
|
+
eventHubConnectionString === '' ||
|
|
37
|
+
eventHubName === '') {
|
|
38
|
+
producer = {};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const maxRetries = process.env[constants_1.environmentVarNames.eventHubMaxRetries]
|
|
42
|
+
? Number(process.env[constants_1.environmentVarNames.eventHubMaxRetries])
|
|
43
|
+
: DEFAULT_MAX_RETRY;
|
|
44
|
+
const mode = process.env[constants_1.environmentVarNames.eventHubMaxRetries] &&
|
|
45
|
+
((_a = process.env[constants_1.environmentVarNames.eventHubMode]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'FIXED'
|
|
46
|
+
? event_hubs_1.RetryMode.Fixed
|
|
47
|
+
: DEFAULT_EVENT_HUB_MODE;
|
|
48
|
+
producer = new event_hubs_1.EventHubProducerClient(eventHubConnectionString, eventHubName, {
|
|
49
|
+
retryOptions: {
|
|
50
|
+
maxRetries: maxRetries,
|
|
51
|
+
mode: mode,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
24
55
|
/* We load the infrastructure package dynamically here to avoid including it in the
|
|
25
56
|
* dependencies that are deployed in the lambda functions. The infrastructure
|
|
26
57
|
* package is only used during the deploy.
|
|
@@ -33,6 +64,9 @@ const Provider = (rockets) => ({
|
|
|
33
64
|
// ProviderEventsLibrary
|
|
34
65
|
events: {
|
|
35
66
|
rawToEnvelopes: events_adapter_1.rawEventsToEnvelopes,
|
|
67
|
+
rawStreamToEnvelopes: events_stream_consumer_adapter_1.rawEventsStreamToEnvelopes,
|
|
68
|
+
dedupEventStream: events_stream_consumer_adapter_1.dedupEventStream.bind(null, cosmosClient),
|
|
69
|
+
produce: events_stream_producer_adapter_1.produceEventsStream.bind(null, producer),
|
|
36
70
|
store: events_adapter_1.storeEvents.bind(null, cosmosClient),
|
|
37
71
|
storeSnapshot: events_adapter_1.storeSnapshot.bind(null, cosmosClient),
|
|
38
72
|
forEntitySince: events_adapter_1.readEntityEventsSince.bind(null, cosmosClient),
|
|
@@ -75,6 +109,16 @@ const Provider = (rockets) => ({
|
|
|
75
109
|
rockets: {
|
|
76
110
|
rawToEnvelopes: rocket_adapter_1.rawRocketInputToEnvelope,
|
|
77
111
|
},
|
|
112
|
+
sensor: {
|
|
113
|
+
databaseEventsHealthDetails: health_adapter_1.databaseEventsHealthDetails.bind(null, cosmosClient),
|
|
114
|
+
databaseReadModelsHealthDetails: health_adapter_1.databaseReadModelsHealthDetails.bind(null, cosmosClient),
|
|
115
|
+
isDatabaseEventUp: health_adapter_1.isDatabaseEventUp.bind(null, cosmosClient),
|
|
116
|
+
areDatabaseReadModelsUp: health_adapter_1.areDatabaseReadModelsUp.bind(null, cosmosClient),
|
|
117
|
+
databaseUrls: health_adapter_1.databaseUrl.bind(null, cosmosClient),
|
|
118
|
+
graphQLFunctionUrl: health_adapter_1.graphqlFunctionUrl,
|
|
119
|
+
isGraphQLFunctionUp: health_adapter_1.isGraphQLFunctionUp,
|
|
120
|
+
rawRequestToHealthEnvelope: health_adapter_1.rawRequestToSensorHealth,
|
|
121
|
+
},
|
|
78
122
|
// ProviderInfrastructureGetter
|
|
79
123
|
infrastructure: () => {
|
|
80
124
|
const infrastructurePackageName = require('../package.json').name + '-infrastructure';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BoosterConfig, EventEnvelope, EventStream } from '@boostercloud/framework-types';
|
|
2
|
+
import { Context } from '@azure/functions';
|
|
3
|
+
import { CosmosClient } from '@azure/cosmos';
|
|
4
|
+
export declare function dedupEventStream(cosmosDb: CosmosClient, config: BoosterConfig, context: Context): Promise<EventStream>;
|
|
5
|
+
export declare function rawEventsStreamToEnvelopes(config: BoosterConfig, context: Context, dedupEventStream: EventStream): Array<EventEnvelope>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rawEventsStreamToEnvelopes = exports.dedupEventStream = void 0;
|
|
4
|
+
const framework_common_helpers_1 = require("@boostercloud/framework-common-helpers");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const DEFAULT_DEDUP_TTL = 86400;
|
|
7
|
+
async function dedupEventStream(cosmosDb, config, context) {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const logger = (0, framework_common_helpers_1.getLogger)(config, 'dedup-events-stream#dedupEventsStream');
|
|
10
|
+
const events = context.bindings.eventHubMessages || [];
|
|
11
|
+
logger.debug(`Dedup ${events.length} events`);
|
|
12
|
+
const resources = [];
|
|
13
|
+
for (const event of events) {
|
|
14
|
+
const rawParsed = JSON.parse(event);
|
|
15
|
+
const eventTag = {
|
|
16
|
+
primaryKey: rawParsed._etag,
|
|
17
|
+
createdAt: new Date().toISOString(),
|
|
18
|
+
ttl: (_b = (_a = config.eventStreamConfiguration.parameters) === null || _a === void 0 ? void 0 : _a.dedupTtl) !== null && _b !== void 0 ? _b : DEFAULT_DEDUP_TTL,
|
|
19
|
+
};
|
|
20
|
+
try {
|
|
21
|
+
const { resource } = await cosmosDb
|
|
22
|
+
.database(config.resourceNames.applicationStack)
|
|
23
|
+
.container(config.resourceNames.eventsDedup)
|
|
24
|
+
.items.create(eventTag);
|
|
25
|
+
if (resource) {
|
|
26
|
+
resources.push(event);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code !== constants_1.AZURE_CONFLICT_ERROR_CODE) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
logger.warn(`Ignoring duplicated event with etag ${eventTag}.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return resources;
|
|
37
|
+
}
|
|
38
|
+
exports.dedupEventStream = dedupEventStream;
|
|
39
|
+
function rawEventsStreamToEnvelopes(config, context, dedupEventStream) {
|
|
40
|
+
const logger = (0, framework_common_helpers_1.getLogger)(config, 'events-adapter#rawEventsStreamToEnvelopes');
|
|
41
|
+
logger.debug(`Mapping ${dedupEventStream.length} events`);
|
|
42
|
+
const bindingData = context.bindingData;
|
|
43
|
+
return dedupEventStream.map((message, index) => {
|
|
44
|
+
const rawParsed = JSON.parse(message);
|
|
45
|
+
const instance = process.env.WEBSITE_INSTANCE_ID;
|
|
46
|
+
const partitionKeyArrayElement = bindingData.partitionKeyArray[index];
|
|
47
|
+
const offset = bindingData.offsetArray[index];
|
|
48
|
+
const sequence = bindingData.sequenceNumberArray[index];
|
|
49
|
+
const time = bindingData.enqueuedTimeUtcArray[index];
|
|
50
|
+
logger.debug(`CONSUMED_EVENT:${instance}#${partitionKeyArrayElement}=>(${index}#${offset}#${sequence}#${time})`);
|
|
51
|
+
return rawParsed;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.rawEventsStreamToEnvelopes = rawEventsStreamToEnvelopes;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BoosterConfig, EventEnvelope } from '@boostercloud/framework-types';
|
|
2
|
+
import { EventHubProducerClient } from '@azure/event-hubs';
|
|
3
|
+
export declare function produceEventsStream(producer: EventHubProducerClient, entityName: string, entityID: string, eventEnvelopes: Array<EventEnvelope>, config: BoosterConfig): Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.produceEventsStream = void 0;
|
|
4
|
+
const framework_common_helpers_1 = require("@boostercloud/framework-common-helpers");
|
|
5
|
+
const partition_keys_1 = require("./partition-keys");
|
|
6
|
+
async function produceEventsStream(producer, entityName, entityID, eventEnvelopes, config) {
|
|
7
|
+
const logger = (0, framework_common_helpers_1.getLogger)(config, 'events-stream-producer#produceEventsStream');
|
|
8
|
+
logger.debug('Producing eventEnvelopes', eventEnvelopes);
|
|
9
|
+
const batchOptions = {
|
|
10
|
+
partitionKey: (0, partition_keys_1.partitionKeyForEvent)(entityName, entityID),
|
|
11
|
+
};
|
|
12
|
+
let batch = await producer.createBatch(batchOptions);
|
|
13
|
+
let numEventsSent = 0;
|
|
14
|
+
let i = 0;
|
|
15
|
+
while (i < eventEnvelopes.length) {
|
|
16
|
+
// messages can fail to be added to the batch if they exceed the maximum size configured for the EventHub.
|
|
17
|
+
const eventEnvelope = eventEnvelopes[i];
|
|
18
|
+
const isAdded = batch.tryAdd({ body: eventEnvelope });
|
|
19
|
+
if (isAdded) {
|
|
20
|
+
logger.info(`Added ${JSON.stringify(eventEnvelope)} to the batch`);
|
|
21
|
+
++i;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (batch.count === 0) {
|
|
25
|
+
throw new Error(`Message was too large and can't be sent until it's made smaller. ${JSON.stringify(eventEnvelope)}`);
|
|
26
|
+
}
|
|
27
|
+
// We reached the batch size limit
|
|
28
|
+
logger.info(`Sending ${batch.count} messages`);
|
|
29
|
+
await producer.sendBatch(batch);
|
|
30
|
+
numEventsSent += batch.count;
|
|
31
|
+
batch = await producer.createBatch(batchOptions);
|
|
32
|
+
}
|
|
33
|
+
if (batch.count > 0) {
|
|
34
|
+
logger.info(`Sending remaining ${batch.count} messages`);
|
|
35
|
+
await producer.sendBatch(batch);
|
|
36
|
+
numEventsSent += batch.count;
|
|
37
|
+
}
|
|
38
|
+
logger.info(`Sent ${numEventsSent} events`);
|
|
39
|
+
if (numEventsSent !== eventEnvelopes.length) {
|
|
40
|
+
throw new Error(`Not all messages were sent (${numEventsSent}/${eventEnvelopes.length})`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.produceEventsStream = produceEventsStream;
|
|
@@ -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.2.0",
|
|
4
4
|
"description": "Handle Booster's integration with Azure",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework-provider-azure"
|
|
@@ -26,14 +26,15 @@
|
|
|
26
26
|
"@azure/cosmos": "^4.0.0",
|
|
27
27
|
"@azure/functions": "^1.2.2",
|
|
28
28
|
"@azure/identity": "~2.1.0",
|
|
29
|
-
"@
|
|
30
|
-
"@boostercloud/framework-
|
|
29
|
+
"@azure/event-hubs": "5.11.1",
|
|
30
|
+
"@boostercloud/framework-common-helpers": "^2.2.0",
|
|
31
|
+
"@boostercloud/framework-types": "^2.2.0",
|
|
31
32
|
"tslib": "^2.4.0",
|
|
32
33
|
"@effect-ts/core": "^0.60.4",
|
|
33
34
|
"@azure/web-pubsub": "~1.1.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@boostercloud/eslint-config": "^2.
|
|
37
|
+
"@boostercloud/eslint-config": "^2.2.0",
|
|
37
38
|
"@types/chai": "4.2.18",
|
|
38
39
|
"@types/chai-as-promised": "7.1.4",
|
|
39
40
|
"@types/faker": "5.1.5",
|