Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated readme architecture image #17

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ jobs:
run: npm install

- name: Generate OpenAPI specs
run: |
npm run generate-swagger && ./scripts.sh cleanup

# - name: Install Newman dependency
# run: npm install --prefix tests/
run: npm run generate-swagger && ./scripts.sh cleanup

- name: Local function testing
run: npm run netlify-dev & sleep 10 && npm run test:postman
Expand All @@ -43,13 +39,15 @@ jobs:
# ENDPOINT: https://deploy-preview-${{github.event.number}}--ambianic-serverless.netlify.app/.netlify/functions

- name: Wait for successful preview deployment
if: ${{ github.event_name == 'pull_request' }}
uses: jakepartusch/wait-for-netlify-action@v1
id: get-netlify-url
with:
site_name: "ambianic-serverless"
max_timeout: 60

- name: Run tests against deployed preview
if: ${{ github.event_name == 'pull_request' }}
run: npm run test:postman
env:
STRIPE_TEST_KEY: ${{ secrets.STRIPE_TEST_KEY }}
Expand All @@ -68,12 +66,15 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
personal_token: ${{ secrets.REPOSITORY_ACCESS_TOKEN }}
publish_dir: ./github-pages
publish_dir: ./docs

- name: Test env variables
run: echo ${{ secrets.GH_TOKEN }} ${{ secrets.NPM_TOKEN }}

- name: Run the semantic-release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Code Coverage Report
Expand Down
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# [1.4.0](https://github.com/vickywane/ambianic-subscriptions/compare/v1.3.0...v1.4.0) (2021-05-23)


### Features

* corrected package name ([#14](https://github.com/vickywane/ambianic-subscriptions/issues/14)) ([ff6d3c9](https://github.com/vickywane/ambianic-subscriptions/commit/ff6d3c94ef21334c70608d2ab2bbb4ea72f83463))

# [1.3.0](https://github.com/vickywane/ambianic-subscriptions/compare/v1.2.0...v1.3.0) (2021-05-23)


### Features

* corrected ci steps ([#12](https://github.com/vickywane/ambianic-subscriptions/issues/12)) ([8dedc75](https://github.com/vickywane/ambianic-subscriptions/commit/8dedc758437f3a097f11b3e88876061adedb0ddf))
* corrected ci steps ([#13](https://github.com/vickywane/ambianic-subscriptions/issues/13)) ([f3f1293](https://github.com/vickywane/ambianic-subscriptions/commit/f3f129391e01d22feb9a8b1f4bf928e65f1d77f3))

# [1.2.0](https://github.com/vickywane/ambianic-subscriptions/compare/v1.1.0...v1.2.0) (2021-05-22)


### Features

* corrected ci steps ([#11](https://github.com/vickywane/ambianic-subscriptions/issues/11)) ([357b973](https://github.com/vickywane/ambianic-subscriptions/commit/357b973ae8c87972229915779bbae7a992afed80))

# [1.1.0](https://github.com/vickywane/ambianic-subscriptions/compare/v1.0.0...v1.1.0) (2021-05-22)


### Features

* fixed ci broken steps ([#10](https://github.com/vickywane/ambianic-subscriptions/issues/10)) ([f4b4f10](https://github.com/vickywane/ambianic-subscriptions/commit/f4b4f108763669940079dc334dfed67cf62ca90c)), closes [#6](https://github.com/vickywane/ambianic-subscriptions/issues/6)

# 1.0.0 (2021-05-22)


### Bug Fixes

* fix breaking CI setup ([9d6ec45](https://github.com/vickywane/ambianic-subscriptions/commit/9d6ec455276c65811a21f599448b5deec9a5caf7))
* fix breaking CI setup ([a8ef5db](https://github.com/vickywane/ambianic-subscriptions/commit/a8ef5db11754950b5706e801fdbb31a34a6475ca))
* removed lighthouse checks and updated readme ([49288ba](https://github.com/vickywane/ambianic-subscriptions/commit/49288baf78e296b0fe6c135a312fbafd71bc9640))


### Features

* added postman API test created with newman to CI ([f12e8ab](https://github.com/vickywane/ambianic-subscriptions/commit/f12e8abd0a63631794d6fdd422c11e8348b93947))
* corrected semantic release steps on gh ci ([#8](https://github.com/vickywane/ambianic-subscriptions/issues/8)) ([c55e72e](https://github.com/vickywane/ambianic-subscriptions/commit/c55e72e732307ecd79741d9396d6071276b5a537)), closes [#6](https://github.com/vickywane/ambianic-subscriptions/issues/6)
* implemented automatic publishing to github pages on each deployment ([#5](https://github.com/vickywane/ambianic-subscriptions/issues/5)) ([18299ea](https://github.com/vickywane/ambianic-subscriptions/commit/18299ea94cb35f3e7d38d47dd7b3e8b633972598))
* improved user documentation ([#6](https://github.com/vickywane/ambianic-subscriptions/issues/6)) ([fec4c09](https://github.com/vickywane/ambianic-subscriptions/commit/fec4c09867958f226c1bf8b66b732e0e68fc1d9d))
* improved user documentation ([#7](https://github.com/vickywane/ambianic-subscriptions/issues/7)) ([fb7129e](https://github.com/vickywane/ambianic-subscriptions/commit/fb7129e3ded828ad51e8440a433262f85c99db4f)), closes [#6](https://github.com/vickywane/ambianic-subscriptions/issues/6)
* project CI ([42f3999](https://github.com/vickywane/ambianic-subscriptions/commit/42f39991a24221bc451944bf6f3f985ecd7ca0e7))
* updated postman tests suites ([6893565](https://github.com/vickywane/ambianic-subscriptions/commit/6893565ab429ca5d4aca4c446871536c34e95cad))
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

## Repo for ambianic premium subscription management

<p> This repo hosts [Netlify functions](https://www.netlify.com/products/functions/) that handle Ambianic premium user subscriptions. This is code that cannot run in the browser PWA, because it needs access keys to subscription and payment gateway services (Stripe) shared between all app users. If the code runs in the PWA, users will be able to see and manipulate each other's premium subscription data </p>
This repo hosts [Netlify functions](https://www.netlify.com/products/functions) that handle Ambianic premium user subscriptions. This is code that cannot run in the browser PWA, because it needs access keys to subscription and payment gateway services (Stripe) shared between all app users. If the code runs in the PWA, users will be able to see and manipulate each other's premium subscription data.

The image below shows the architecture of these serverless functions in connection with the Ambianic [PWA](https://github.com/ambianic/ambianic-ui/).
![serverless-functions-architecture](./assets/serverless-architecture.png)
The image below shows the architecture of these serverless functions in connection with the Ambianic [PWA](https://github.com/ambianic/ambianic-ui/) and [Edge Device](https://github.com/ambianic/ambianic-edge).
![serverless-functions-architecture](./assets/cloud-api.png)

## Running Locally
## Running Functions Locally

The serverless functions within this project are managed using [netlify-dev](https://www.netlify.com/products/dev/). Start the functions emulator from the `netlify` directory using `yarn netlify-dev` to listen for requests to any of created functions on port `5050`.

Credentials within this project are managed using environment variables and [GitHub Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets). To run the functions here locally using the `netlify dev` command, create a `.env` file in the root directory with the following values;
All credentials within this project are managed using environment variables and [GitHub Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets). To run the functions here locally using the `netlify dev` command, create a `.env` file in the root directory with the following values;

```
STRIPE_TEST_KEY=STRIPE_KEY
Expand Down
Binary file added assets/cloud-api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions newman.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
require("dotenv").config()
const newman = require("newman");

console.log(`Running tests against : ${process.env.ENDPOINT}`)

newman.run(
{
collection: require("./tests/ambianic-functions-collection.postman_collection.json"),
reporters: "cli",
globalVar: [{ key: "FUNCTION_ENDPOINT", value: process.env.ENDPOINT || "https://localhost:5050"}],
globalVar: [{ key: "url", value: process.env.MOCK_ENDPOINT || "https://33743be6-3197-4dd4-8471-50b3640320c9.mock.pstmn.io"}],
},
function (err) {
if (err) {
throw err;
}
}
);
);
12 changes: 6 additions & 6 deletions openapi-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ AmbianicFunctionsCollection - JavaScript client for ambianic_functions_collectio
A postman collection documenting the Netlify cloud functions created for use within Ambianic-PWA
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- API version: 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
- Package version: 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
- API version: a7b6cde1-7435-479a-bd1a-20ab61f9ae08
- Package version: a7b6cde1-7435-479a-bd1a-20ab61f9ae08
- Build package: org.openapitools.codegen.languages.JavascriptClientCodegen

## Installation
Expand Down Expand Up @@ -123,10 +123,10 @@ All URIs are relative to *https://33743be6-3197-4dd4-8471-50b3640320c9.mock.pstm

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AmbianicFunctionsCollection.DefaultApi* | [**deleteSubscription**](docs/DefaultApi.md#deleteSubscription) | **DELETE** /mock-subscription | Delete an Ambianic&#39;s user subscription
*AmbianicFunctionsCollection.DefaultApi* | [**getSubscriptionData**](docs/DefaultApi.md#getSubscriptionData) | **GET** /mock-subscription | Get a user&#39;s subscription data
*AmbianicFunctionsCollection.DefaultApi* | [**sendNotification**](docs/DefaultApi.md#sendNotification) | **POST** /mock-notification | Send an event detection notification
*AmbianicFunctionsCollection.DefaultApi* | [**subscribeUser**](docs/DefaultApi.md#subscribeUser) | **POST** /mock-subscribe | Subscribe Ambianic user to premium notification
*AmbianicFunctionsCollection.DefaultApi* | [**deleteSubscription**](docs/DefaultApi.md#deleteSubscription) | **DELETE** /subscription | Delete an Ambianic&#39;s user subscription
*AmbianicFunctionsCollection.DefaultApi* | [**getSubscriptionData**](docs/DefaultApi.md#getSubscriptionData) | **GET** /subscription | Get a user&#39;s subscription data
*AmbianicFunctionsCollection.DefaultApi* | [**sendNotification**](docs/DefaultApi.md#sendNotification) | **POST** /notification | Send an event detection notification
*AmbianicFunctionsCollection.DefaultApi* | [**subscribeUser**](docs/DefaultApi.md#subscribeUser) | **POST** /subscribe | Subscribe Ambianic user to premium notification


## Documentation for Models
Expand Down
14 changes: 7 additions & 7 deletions openapi-docs/docs/DefaultApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ All URIs are relative to *https://33743be6-3197-4dd4-8471-50b3640320c9.mock.pstm

Method | HTTP request | Description
------------- | ------------- | -------------
[**deleteSubscription**](DefaultApi.md#deleteSubscription) | **DELETE** /mock-subscription | Delete an Ambianic&#39;s user subscription
[**getSubscriptionData**](DefaultApi.md#getSubscriptionData) | **GET** /mock-subscription | Get a user&#39;s subscription data
[**sendNotification**](DefaultApi.md#sendNotification) | **POST** /mock-notification | Send an event detection notification
[**subscribeUser**](DefaultApi.md#subscribeUser) | **POST** /mock-subscribe | Subscribe Ambianic user to premium notification
[**deleteSubscription**](DefaultApi.md#deleteSubscription) | **DELETE** /subscription | Delete an Ambianic&#39;s user subscription
[**getSubscriptionData**](DefaultApi.md#getSubscriptionData) | **GET** /subscription | Get a user&#39;s subscription data
[**sendNotification**](DefaultApi.md#sendNotification) | **POST** /notification | Send an event detection notification
[**subscribeUser**](DefaultApi.md#subscribeUser) | **POST** /subscribe | Subscribe Ambianic user to premium notification



Expand Down Expand Up @@ -129,8 +129,8 @@ An endpoint to send notifications about detected objects to a premium ambianic s
import AmbianicFunctionsCollection from 'ambianic_functions_collection';

let apiInstance = new AmbianicFunctionsCollection.DefaultApi();
let userId = AUTHO_USER_ID ; // String | Authenticated user ID gotten from auth0
let notification = NOTIFICATION_DATA; // String | Notification object containing detected event details from running ambianic edge device
let userId = AUTHO_USER_ID ; // String |
let notification = {dateTime: "monday"}; // String | Notification object containing detected event details from running ambianic edge device
let accessControlAllowOrigin = *; // String |
apiInstance.sendNotification(userId, notification, accessControlAllowOrigin, (error, data, response) => {
if (error) {
Expand All @@ -146,7 +146,7 @@ apiInstance.sendNotification(userId, notification, accessControlAllowOrigin, (er

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**userId** | **String**| Authenticated user ID gotten from auth0 |
**userId** | **String**| |
**notification** | **String**| Notification object containing detected event details from running ambianic edge device |
**accessControlAllowOrigin** | **String**| |

Expand Down
7 changes: 3 additions & 4 deletions openapi-docs/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ambianic-functions-collection
* A postman collection documenting the Netlify cloud functions created for use within Ambianic-PWA
*
* The version of the OpenAPI document: 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
* The version of the OpenAPI document: a7b6cde1-7435-479a-bd1a-20ab61f9ae08
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -17,7 +17,7 @@ import querystring from "querystring";

/**
* @module ApiClient
* @version 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
* @version a7b6cde1-7435-479a-bd1a-20ab61f9ae08
*/

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ class ApiClient {
* @default {}
*/
this.defaultHeaders = {
'User-Agent': 'OpenAPI-Generator/4b8f433d-5891-4ae3-bb49-ca6942a9b08d/Javascript'
'User-Agent': 'OpenAPI-Generator/a7b6cde1-7435-479a-bd1a-20ab61f9ae08/Javascript'
};

/**
Expand Down Expand Up @@ -91,7 +91,6 @@ class ApiClient {
* Allow user to add superagent plugins
*/
this.plugins = null;

}

/**
Expand Down
14 changes: 7 additions & 7 deletions openapi-docs/src/api/DefaultApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ambianic-functions-collection
* A postman collection documenting the Netlify cloud functions created for use within Ambianic-PWA
*
* The version of the OpenAPI document: 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
* The version of the OpenAPI document: a7b6cde1-7435-479a-bd1a-20ab61f9ae08
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -17,7 +17,7 @@ import ApiClient from "../ApiClient";
/**
* Default service.
* @module api/DefaultApi
* @version 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
* @version a7b6cde1-7435-479a-bd1a-20ab61f9ae08
*/
export default class DefaultApi {

Expand Down Expand Up @@ -87,7 +87,7 @@ export default class DefaultApi {
let accepts = [];
let returnType = null;
return this.apiClient.callApi(
'/mock-subscription', 'DELETE',
'/subscription', 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null, callback
);
Expand Down Expand Up @@ -153,7 +153,7 @@ export default class DefaultApi {
let accepts = [];
let returnType = null;
return this.apiClient.callApi(
'/mock-subscription', 'GET',
'/subscription', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null, callback
);
Expand All @@ -170,7 +170,7 @@ export default class DefaultApi {
/**
* Send an event detection notification
* An endpoint to send notifications about detected objects to a premium ambianic subscriber from a running edge device, delivered from the Cloud API.
* @param {String} userId Authenticated user ID gotten from auth0
* @param {String} userId
* @param {String} notification Notification object containing detected event details from running ambianic edge device
* @param {String} accessControlAllowOrigin
* @param {module:api/DefaultApi~sendNotificationCallback} callback The callback function, accepting three arguments: error, data, response
Expand Down Expand Up @@ -207,7 +207,7 @@ export default class DefaultApi {
let accepts = [];
let returnType = null;
return this.apiClient.callApi(
'/mock-notification', 'POST',
'/notification', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null, callback
);
Expand Down Expand Up @@ -291,7 +291,7 @@ export default class DefaultApi {
let accepts = [];
let returnType = null;
return this.apiClient.callApi(
'/mock-subscribe', 'POST',
'/subscribe', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null, callback
);
Expand Down
4 changes: 2 additions & 2 deletions openapi-docs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ambianic-functions-collection
* A postman collection documenting the Netlify cloud functions created for use within Ambianic-PWA
*
* The version of the OpenAPI document: 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
* The version of the OpenAPI document: a7b6cde1-7435-479a-bd1a-20ab61f9ae08
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -45,7 +45,7 @@ import DefaultApi from './api/DefaultApi';
* </pre>
* </p>
* @module index
* @version 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
* @version a7b6cde1-7435-479a-bd1a-20ab61f9ae08
*/
export {
/**
Expand Down
4 changes: 2 additions & 2 deletions openapi-docs/test/api/DefaultApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* A postman collection documenting the Netlify cloud functions created for use within Ambianic-PWA
*
* The version of the OpenAPI document: 4b8f433d-5891-4ae3-bb49-ca6942a9b08d
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
Expand Down Expand Up @@ -50,6 +50,7 @@
describe('DefaultApi', function() {
describe('send notification', function() {
it('should call sendNotification successfully', function(done) {

instance.sendNotification(Math.random().toString() , "Cat detected with 0.98172927612 confidence", "", (error, data, {res}) => {
if (error) throw error;
expect(res.statusCode).to.be(200)
Expand Down Expand Up @@ -88,5 +89,4 @@
});
});
});

}));
Loading