-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(metering, billing)!: update metering interface, provider and…
… simplify function interfaces (#91) This commit adds missing functionality for the metering interface and provider. It also refactors the interfaces for metering and billing functions to simplify and standardize the way they are defined and triggered. Key changes: 1. Added missing functionality for managing meters and fixed GET /meters/{meterId} path. 2. Introduced new interfaces `IASyncFunction` and `ISyncFunction` to represent async functions (triggered by events) and sync functions (triggered by API Gateway routes), respectively. 3. Updated the `IBilling` and `IMetering` interfaces to use the new `IASyncFunction` and `ISyncFunction` interfaces for defining their respective functions. 4. Removed the `IFunctionTrigger` interface and the `createEventTarget` utility function, as their functionality is now covered by the new interfaces and the `IEventManager.addTargetToEvent` method. 5. Added a new `AddTargetToEventProps` interface to encapsulate the properties required for adding a target to an event in the `IEventManager.addTargetToEvent` method. 6. Introduced a new `IFunctionPath` interface to represent functions triggered by API Gateway routes, including the path and the function handler.
- Loading branch information
Showing
9 changed files
with
432 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,76 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IFunction } from 'aws-cdk-lib/aws-lambda'; | ||
import { IFunctionTrigger } from '../../utils'; | ||
import { IASyncFunction, ISyncFunction } from '../../utils'; | ||
|
||
/** | ||
* Encapsulates the list of properties for an IMetering construct. | ||
*/ | ||
export interface IMetering { | ||
/** | ||
* The function to trigger to create a meter -- POST /meters | ||
* The sync function responsible for creating a meter. | ||
* Once created, the meter can be used to track and analyze the specific usage metrics for tenants. | ||
* -- POST /meters | ||
*/ | ||
createMeterFunction: IFunction; | ||
createMeterFunction: ISyncFunction; | ||
|
||
/** | ||
* The scope required to authorize requests for creating a new meter. | ||
* The sync function responsible for fetching a single a meter based on its id. | ||
* -- GET /meters/{meterId} | ||
*/ | ||
createMeterScope?: string; | ||
fetchMeterFunction: ISyncFunction; | ||
|
||
/** | ||
* The function to trigger to update a meter -- PUT /meters/meterId | ||
* The sync function responsible for fetching multiple meters. This should support pagination. | ||
* -- GET /meters | ||
*/ | ||
updateMeterFunction?: IFunction; | ||
fetchAllMetersFunction: ISyncFunction; | ||
|
||
/** | ||
* The scope required to authorize requests for updating a meter. | ||
* The sync function responsible for updating a meter. | ||
* -- PUT /meters/{meterId} | ||
*/ | ||
updateMeterScope?: string; | ||
updateMeterFunction?: ISyncFunction; | ||
|
||
/** | ||
* The function to trigger to ingest a usage event. | ||
* Usage events are used to measure and track the usage metrics associated with the meter. | ||
* | ||
* Default event trigger: INGEST_USAGE | ||
* The sync function responsible for deleting a meter. | ||
* -- DELETE /meters/{meterId} | ||
*/ | ||
ingestUsageEventFunction: IFunction | IFunctionTrigger; | ||
deleteMeterFunction?: ISyncFunction; | ||
|
||
/** | ||
* The function to trigger to get the usage data that has been recorded for a specific meter. | ||
* -- GET /usage/meterId | ||
* The async function responsible for ingesting a usage event. | ||
* Usage events are used to measure and track the usage metrics associated with the meter. | ||
* -- Default event trigger: INGEST_USAGE | ||
*/ | ||
fetchUsageFunction: IFunction; // use 'fetch*' instead of 'get*' to avoid error JSII5000 | ||
ingestUsageEventFunction: IASyncFunction; | ||
|
||
/** | ||
* The scope required to authorize requests for fetching metering usage. | ||
* The function responsible for getting usage data for a specific meter. | ||
* -- GET /usage/{meterId} | ||
*/ | ||
fetchUsageScope?: string; | ||
fetchUsageFunction: ISyncFunction; // use 'fetch*' instead of 'get*' to avoid error JSII5000 | ||
|
||
/** | ||
* The function to trigger to exclude specific events from being recorded or included in the usage data. | ||
* Used for canceling events that were incorrectly ingested. | ||
* -- DELETE /usage | ||
*/ | ||
cancelUsageEventsFunction?: IFunction; | ||
|
||
/** | ||
* The scope required to authorize requests for cancelling usage events. | ||
*/ | ||
cancelUsageEventsScope?: string; | ||
cancelUsageEventsFunction?: ISyncFunction; | ||
|
||
/** | ||
* The function to trigger to create a new customer. | ||
* The function responsible for creating a new customer. | ||
* (Customer in this context is a tenant.) | ||
* | ||
* Default event trigger: ONBOARDING_REQUEST | ||
*/ | ||
createCustomerFunction?: IFunction | IFunctionTrigger; | ||
createCustomerFunction?: IASyncFunction; | ||
|
||
/** | ||
* The function to trigger to delete a customer. | ||
* The function responsible for deleting an existing customer. | ||
* (Customer in this context is a tenant.) | ||
* | ||
* Default event trigger: OFFBOARDING_REQUEST | ||
*/ | ||
deleteCustomerFunction?: IFunction | IFunctionTrigger; | ||
deleteCustomerFunction?: IASyncFunction; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.