From b908eb4cea39d59a5a18fb3682a16be77e51b271 Mon Sep 17 00:00:00 2001 From: victory Date: Thu, 17 Jun 2021 05:43:35 +0100 Subject: [PATCH] update: adjusted /product documentation --- README.md | 4 +- docs/index.html | 21 +++++- netlify/functions/notification.js | 2 +- netlify/functions/product.js | 17 +++-- openapi-docs/.openapi-generator/FILES | 3 - openapi-docs/README.md | 3 +- openapi-docs/docs/DefaultApi.md | 18 ++--- openapi-docs/src/api/DefaultApi.js | 22 +++---- openapi-docs/src/index.js | 7 -- openapi-spec.yaml | 66 ++++++++----------- ...nctions-collection.postman_collection.json | 10 +-- 11 files changed, 88 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index 439851a..10ec24c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Before executing the `netlify dev` command, create a `.env` file in the root dir # Access key from Stripe to access your Stripe resources STRIPE_KEY=STRIPE_KEY -# The ID of the email price product used in billing subscribers. +# The ID of the price entity attached to a product. EMAIL_PRODUCT_PRICE_ID=EMAIL_PRODUCT_PRICE_ID # Your Auth0 Domain @@ -65,7 +65,7 @@ The following environment variables used within the serverless functions, and sh # Access key from Stripe to access your Stripe resources STRIPE_KEY=STRIPE_KEY -# The ID of the email price product used in billing subscribers. +# The ID of the price entity attached to a product. EMAIL_PRODUCT_PRICE_ID=EMAIL_PRODUCT_PRICE_ID # Your Auth0 Domain diff --git a/docs/index.html b/docs/index.html index fce8827..6e1ece2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -52,7 +52,7 @@

Summary

GET -

Retrieve notification product

+

An endpoint to retrieve details about an Ambianic premium subscription product.

@@ -199,12 +199,12 @@

POST /notifi
-
Retrieve notification product
+
An endpoint to retrieve details about an Ambianic premium subscription product.

GET /product

-

An endpoint to retrieve details about the Ambianic notifications product.

+

Retrieve product and pricing information associated with an Ambianic product.

@@ -236,6 +236,21 @@

GET /product + + + productId + +

Unique ID of product to be retrieved

+ + query + + object + + + + + + diff --git a/netlify/functions/notification.js b/netlify/functions/notification.js index 684a5b1..852a220 100644 --- a/netlify/functions/notification.js +++ b/netlify/functions/notification.js @@ -72,7 +72,7 @@ exports.handler = async (event, context, callback) => { statusCode: 403, headers, body: JSON.stringify({ - message: "NO ACTIVE SUBSCRIPTION TO SEND EMAIL", + message: "Premium subscription inactive. Cannot send notification email. Please (re)activate premium subscription service.", }), }); } diff --git a/netlify/functions/product.js b/netlify/functions/product.js index 2868cf6..7e101b8 100644 --- a/netlify/functions/product.js +++ b/netlify/functions/product.js @@ -7,19 +7,28 @@ const headers = { "Content-Type": "application/json", }; -exports.handler = async (event, context, callback) => { +exports.handler = async ({ httpMethod, queryStringParameters }, context, callback) => { + const { productId } = queryStringParameters - if (event.httpMethod === "OPTIONS") { + if (!productId) { + callback(null, { + statusCode: 422, + headers, + body: JSON.stringify({ message: "Provide productId param to retrieve product details" }), + }); + } + + if (httpMethod === "OPTIONS") { // for preflight check callback(null, { statusCode: 200, headers, body: JSON.stringify({ status: "OK" }), }); - } else if (event.httpMethod === "GET") { + } else if (httpMethod === "GET") { try { - const product = await stripe.products.retrieve(process.env.EMAIL_PRODUCT_ID); + const product = await stripe.products.retrieve(productId); callback(null, { statusCode: 200, diff --git a/openapi-docs/.openapi-generator/FILES b/openapi-docs/.openapi-generator/FILES index 026433d..4772ded 100644 --- a/openapi-docs/.openapi-generator/FILES +++ b/openapi-docs/.openapi-generator/FILES @@ -3,7 +3,6 @@ README.md docs/DefaultApi.md docs/InlineObject.md -docs/InlineObject1.md docs/InlineResponse200.md docs/InlineResponse2001.md docs/InlineResponse2002.md @@ -14,11 +13,9 @@ src/ApiClient.js src/api/DefaultApi.js src/index.js src/model/InlineObject.js -src/model/InlineObject1.js src/model/InlineResponse200.js src/model/InlineResponse2001.js src/model/InlineResponse2002.js src/model/InlineResponse2003.js src/model/InlineResponse2004.js src/model/InlineResponse2004Product.js -test/model/InlineResponse2004Product.spec.js diff --git a/openapi-docs/README.md b/openapi-docs/README.md index f941e88..6939b19 100644 --- a/openapi-docs/README.md +++ b/openapi-docs/README.md @@ -127,7 +127,7 @@ Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *AmbianicCloudApiCollection.DefaultApi* | [**createSubscription**](docs/DefaultApi.md#createSubscription) | **POST** /subscription | Subscribe a user to Ambianic's Premium Services *AmbianicCloudApiCollection.DefaultApi* | [**deleteSubscription**](docs/DefaultApi.md#deleteSubscription) | **DELETE** /subscription | Delete an Ambianic's user subscription -*AmbianicCloudApiCollection.DefaultApi* | [**getNotificationProduct**](docs/DefaultApi.md#getNotificationProduct) | **GET** /product | Retrieve notification product +*AmbianicCloudApiCollection.DefaultApi* | [**getProductInfo**](docs/DefaultApi.md#getProductInfo) | **GET** /product | An endpoint to retrieve details about an Ambianic premium subscription product. *AmbianicCloudApiCollection.DefaultApi* | [**getSubscriptionData**](docs/DefaultApi.md#getSubscriptionData) | **GET** /subscription | Get a user's subscription data *AmbianicCloudApiCollection.DefaultApi* | [**sendNotification**](docs/DefaultApi.md#sendNotification) | **POST** /notification | Send an event detection notification @@ -135,7 +135,6 @@ Class | Method | HTTP request | Description ## Documentation for Models - [AmbianicCloudApiCollection.InlineObject](docs/InlineObject.md) - - [AmbianicCloudApiCollection.InlineObject1](docs/InlineObject1.md) - [AmbianicCloudApiCollection.InlineResponse200](docs/InlineResponse200.md) - [AmbianicCloudApiCollection.InlineResponse2001](docs/InlineResponse2001.md) - [AmbianicCloudApiCollection.InlineResponse2002](docs/InlineResponse2002.md) diff --git a/openapi-docs/docs/DefaultApi.md b/openapi-docs/docs/DefaultApi.md index 915a454..856d152 100644 --- a/openapi-docs/docs/DefaultApi.md +++ b/openapi-docs/docs/DefaultApi.md @@ -6,7 +6,7 @@ Method | HTTP request | Description ------------- | ------------- | ------------- [**createSubscription**](DefaultApi.md#createSubscription) | **POST** /subscription | Subscribe a user to Ambianic's Premium Services [**deleteSubscription**](DefaultApi.md#deleteSubscription) | **DELETE** /subscription | Delete an Ambianic's user subscription -[**getNotificationProduct**](DefaultApi.md#getNotificationProduct) | **GET** /product | Retrieve notification product +[**getProductInfo**](DefaultApi.md#getProductInfo) | **GET** /product | An endpoint to retrieve details about an Ambianic premium subscription product. [**getSubscriptionData**](DefaultApi.md#getSubscriptionData) | **GET** /subscription | Get a user's subscription data [**sendNotification**](DefaultApi.md#sendNotification) | **POST** /notification | Send an event detection notification @@ -118,13 +118,13 @@ No authorization required - **Accept**: application/json -## getNotificationProduct +## getProductInfo -> InlineResponse2004 getNotificationProduct(accessControlAllowOrigin, opts) +> InlineResponse2004 getProductInfo(accessControlAllowOrigin, opts) -Retrieve notification product +An endpoint to retrieve details about an Ambianic premium subscription product. -An endpoint to retrieve details about the Ambianic notifications product. +Retrieve product and pricing information associated with an Ambianic product. ### Example @@ -134,9 +134,9 @@ import AmbianicCloudApiCollection from 'ambianic_cloud_api_collection'; let apiInstance = new AmbianicCloudApiCollection.DefaultApi(); let accessControlAllowOrigin = *; // String | let opts = { - 'inlineObject1': new AmbianicCloudApiCollection.InlineObject1() // InlineObject1 | + 'productId': "productId_example" // String | Unique ID of product to be retrieved }; -apiInstance.getNotificationProduct(accessControlAllowOrigin, opts, (error, data, response) => { +apiInstance.getProductInfo(accessControlAllowOrigin, opts, (error, data, response) => { if (error) { console.error(error); } else { @@ -151,7 +151,7 @@ apiInstance.getNotificationProduct(accessControlAllowOrigin, opts, (error, data, Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **accessControlAllowOrigin** | **String**| | - **inlineObject1** | [**InlineObject1**](InlineObject1.md)| | [optional] + **productId** | **String**| Unique ID of product to be retrieved | [optional] ### Return type @@ -163,7 +163,7 @@ No authorization required ### HTTP request headers -- **Content-Type**: application/json +- **Content-Type**: Not defined - **Accept**: application/json diff --git a/openapi-docs/src/api/DefaultApi.js b/openapi-docs/src/api/DefaultApi.js index df13199..f46cbcd 100644 --- a/openapi-docs/src/api/DefaultApi.js +++ b/openapi-docs/src/api/DefaultApi.js @@ -14,7 +14,6 @@ import ApiClient from "../ApiClient"; import InlineObject from '../model/InlineObject'; -import InlineObject1 from '../model/InlineObject1'; import InlineResponse200 from '../model/InlineResponse200'; import InlineResponse2001 from '../model/InlineResponse2001'; import InlineResponse2002 from '../model/InlineResponse2002'; @@ -175,33 +174,34 @@ export default class DefaultApi { } /** - * Callback function to receive the result of the getNotificationProduct operation. - * @callback module:api/DefaultApi~getNotificationProductCallback + * Callback function to receive the result of the getProductInfo operation. + * @callback module:api/DefaultApi~getProductInfoCallback * @param {String} error Error message, if any. * @param {module:model/InlineResponse2004} data The data returned by the service call. * @param {String} response The complete HTTP response. */ /** - * Retrieve notification product - * An endpoint to retrieve details about the Ambianic notifications product. + * An endpoint to retrieve details about an Ambianic premium subscription product. + * Retrieve product and pricing information associated with an Ambianic product. * @param {String} accessControlAllowOrigin * @param {Object} opts Optional parameters - * @param {module:model/InlineObject1} opts.inlineObject1 - * @param {module:api/DefaultApi~getNotificationProductCallback} callback The callback function, accepting three arguments: error, data, response + * @param {String} opts.productId Unique ID of product to be retrieved + * @param {module:api/DefaultApi~getProductInfoCallback} callback The callback function, accepting three arguments: error, data, response * data is of type: {@link module:model/InlineResponse2004} */ - getNotificationProduct(accessControlAllowOrigin, opts, callback) { + getProductInfo(accessControlAllowOrigin, opts, callback) { opts = opts || {}; - let postBody = opts['inlineObject1']; + let postBody = null; // verify the required parameter 'accessControlAllowOrigin' is set if (accessControlAllowOrigin === undefined || accessControlAllowOrigin === null) { - throw new Error("Missing the required parameter 'accessControlAllowOrigin' when calling getNotificationProduct"); + throw new Error("Missing the required parameter 'accessControlAllowOrigin' when calling getProductInfo"); } let pathParams = { }; let queryParams = { + 'productId': opts['productId'] }; let headerParams = { 'Access-Control-Allow-Origin': accessControlAllowOrigin @@ -210,7 +210,7 @@ export default class DefaultApi { }; let authNames = []; - let contentTypes = ['application/json']; + let contentTypes = []; let accepts = ['application/json']; let returnType = InlineResponse2004; return this.apiClient.callApi( diff --git a/openapi-docs/src/index.js b/openapi-docs/src/index.js index b5a3153..c2f9013 100644 --- a/openapi-docs/src/index.js +++ b/openapi-docs/src/index.js @@ -14,7 +14,6 @@ import ApiClient from './ApiClient'; import InlineObject from './model/InlineObject'; -import InlineObject1 from './model/InlineObject1'; import InlineResponse200 from './model/InlineResponse200'; import InlineResponse2001 from './model/InlineResponse2001'; import InlineResponse2002 from './model/InlineResponse2002'; @@ -68,12 +67,6 @@ export { */ InlineObject, - /** - * The InlineObject1 model constructor. - * @property {module:model/InlineObject1} - */ - InlineObject1, - /** * The InlineResponse200 model constructor. * @property {module:model/InlineResponse200} diff --git a/openapi-spec.yaml b/openapi-spec.yaml index 5406d26..a3aef1b 100644 --- a/openapi-spec.yaml +++ b/openapi-spec.yaml @@ -402,9 +402,9 @@ paths: examples: {} /product: get: - summary: Retrieve notification product - description: An endpoint to retrieve details about the Ambianic notifications product. - operationId: get-notification-product + summary: An endpoint to retrieve details about an Ambianic premium subscription product. + description: Retrieve product and pricing information associated with an Ambianic product. + operationId: get-product-info parameters: - name: Access-Control-Allow-Origin in: header @@ -413,6 +413,11 @@ paths: schema: type: string example: '*' + - schema: + type: string + in: query + name: productId + description: Unique ID of product to be retrieved responses: '200': description: '' @@ -430,8 +435,8 @@ paths: attributes: type: array items: - required: [ ] - properties: { } + required: [] + properties: {} created: type: number description: @@ -443,30 +448,30 @@ paths: images: type: array items: - required: [ ] - properties: { } + required: [] + properties: {} livemode: type: boolean metadata: type: object - properties: { } - required: [ ] + properties: {} + required: [] name: type: string minLength: 1 object: type: string minLength: 1 - package_dimensions: { } - shippable: { } - statement_descriptor: { } + package_dimensions: {} + shippable: {} + statement_descriptor: {} type: type: string minLength: 1 - unit_label: { } + unit_label: {} updated: type: number - url: { } + url: {} required: - active - attributes @@ -486,13 +491,13 @@ paths: example-1: product: active: true - attributes: [ ] + attributes: [] created: 1614166650 - description: Ambianic Email Notification product + description: Ambianic product id: prod_123456789 - images: [ ] + images: [] livemode: false - metadata: { } + metadata: {} name: Email_subs object: product package_dimensions: null @@ -503,18 +508,17 @@ paths: updated: 1615738932 url: null examples: - notification-product-reponse: - summary: A successful notification response + product-reponse: value: product: active: true - attributes: [ ] + attributes: [] created: 1614166650 - description: Ambianic email notification product + description: Ambianic product id: prod_123456789 - images: [ ] + images: [] livemode: false - metadata: { } + metadata: {} name: Email_subs object: product package_dimensions: null @@ -524,20 +528,6 @@ paths: uni_label: null updated: 1615738932 url: null - requestBody: - content: - application/json: - schema: - description: '' - type: object - properties: - message: - type: string - minLength: 1 - x-examples: - example-1: - message: Notification Sent - examples: { } components: parameters: number: diff --git a/tests/ambianic-functions-collection.postman_collection.json b/tests/ambianic-functions-collection.postman_collection.json index 83635df..c6498ba 100644 --- a/tests/ambianic-functions-collection.postman_collection.json +++ b/tests/ambianic-functions-collection.postman_collection.json @@ -301,7 +301,7 @@ } ], "url": { - "raw": "{{FUNCTION_URL}}/product", + "raw": "{{FUNCTION_URL}}/product?productId=PRODUCT_ID", "host": [ "{{FUNCTION_URL}}" ], @@ -310,13 +310,13 @@ ], "query": [ { - "key": "", - "value": "*", - "disabled": true + "key": "productId", + "value": "PRODUCT_ID", + "description": "Unique ID of product to be retrieved" } ] }, - "description": "Retrieve the notification product details from Stripe" + "description": "An endpoint to retrieve details about an Ambianic premium subscription product." }, "response": [] }