npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solar-quote-service

v1.28.3

Published

A service to return pricing quotes for the ecomm microsite

Downloads

9

Readme

Solar Quote/Pricing Service (BFF - Backend for Frontend)

This app was created with a cdk init --language=typescript and modified from there.

Running locally

You can run the lambda by configuring env variables, then running the docker container.

  1. Create a .env file inside of /quote-service/infra/quote. Follow the .env.example and fill out the appropriate secrets.

    • Some will need to be looked up via AWS Secrets Manager
    • The AWS_* credential data is obtained by SSO'ing into AWS and using the values from Command line or programmatic access before getting to the GUI.
  2. Install Docker

  3. Build & Run the docker container

  • Example:
    • cd /quote-service/infra/quote
    • docker build -t quote .
    • docker run -p 80:80 -it quote
    • curl http://localhost:80 (see curl at very bottom of this README.MD))
    • make a code change, stop the container, build & run again.

Testing

If you make infrastructure changes, run cdk synth to test them.

Useful commands

These commands from the CDK init boilerplate

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

Deploying

This package runs within the Lerna-controlled monorepo, and is deployed by using GitHub Actions from the root directory of the repository (../.github/workflows). You can also deploy to develop and staging temporarily using the deploy quote service [env] label.

Service Endpoint details

Get Solar Quote

Get solar quote data (pricing).

Request

POST /quote-service/quote
type body = {
  address: string;
  offset: Array<number>;
  provider: string;
  battery: number;
  kwhr?: number;
  lmbill?: number;
};

Response

type response = {
  [index: string]: {
    battery: [
      {
        address: string;
        offset: number;
        target: number;
        panels: number;
        kwh_estimate: number;
        batteries: number;
        local_utility_rate: number;
        location: {
          lat: number;
          lng: number;
        };
        pricing: [
          {
            type?: string;
            kWh_rate?: number;
            monthly_cost?: number;
            escalator?: number;
          }
        ];
      }
    ];
  };
};

AWS Resources

Dashboard

| Environment | URL | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | Production | prd-Quote-Dashboard | | Staging | majstg-Quote-Dashboard | | Development | devmaj-Quote-Dashboard |

Lambdas

N/A (These are cloudfront functions)

Disaster Recovery

Please read the disaster recovery plan.

Monitoring

Can be found in the infrastructure package. devmaj-alarm-board

Notes

Triggering New Image Deployment

When we use ecs.ContainerImage.fromAsset('./infra/quote') instead of ecs.ContainerImage.fromDockerImageAsset, the CDK will only build and push a new image if the files within the ./infra/quote directory have changed. If no change is detected, CDK doesn't see the need to push a new image.

Example curl for docker

curl 'http://localhost:80/' \
  -H 'Accept: application/json' \
  -H 'Accept-Language: en-US,en;q=0.9' \
  -H 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZGRyZXNzIjoiMTgwMCBXYXplZSBTdCwgRGVudmVyLCBDTyA4MDIwMiIsImlhdCI6MTcwNDIxNzUzNX0.CDh6AJQmT_JzaQ6pRovuSn9af8V9N22GVERP1n0t3N8' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Origin: https://devmaj-www.sunrundev.com' \
  -H 'Referer: https://devmaj-www.sunrundev.com/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-site' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  --data-raw $'{
    "address": "1077 E Granvia Valmonte, Palm Springs, CA 92262, USA",
    "battery": 1,
    "lmbill": 100,
    "offset": [1],
    "provider": "SCE",
    "marketType": "SHIFT_CA",
    "equipment": {
        "SHIFT_CA": {
            "battery": [
                {
                    "model": "RESU 10H Prime",
                    "manufacturer": "LG",
                    "tier": "Standard",
                    "max_count": 1,
                    "productOfferings": ["SOLAR", "RAD"],
                    "usableCapacity": {
                        "unitPrefix": "k",
                        "value": 8.1
                    }
                }
            ],
            "panel": [{
                "model": "LR4-60HPH-365M",
                "manufacturer": "LONGi Green Energy Technology Co Ltd",
                "tier": "Standard",
                "cecmodelid": "LONGi_Green_Energy_Technology_Co___Ltd__LR6_72BP_365M",
                "output": 365
            }],
            "inverter": [
                {
                    "model": "E4_BDI",
                    "manufacturer": "Delta Electronics",
                    "tier": "Standard",
                    "cecmodelid": "Delta_Electronics__M8_TL_US__240V_",
                    "battery_count": 1
                },
                {
                    "model": "E4_BDI",
                    "manufacturer": "Delta Electronics",
                    "tier": "Standard",
                    "cecmodelid": "Delta_Electronics__M8_TL_US__240V_",
                    "battery_count": 2
                },
                {
                    "model": "E4_BDI",
                    "manufacturer": "Delta Electronics",
                    "tier": "Standard",
                    "cecmodelid": "Delta_Electronics__M8_TL_US__240V_",
                    "battery_count": 3
                }
            ]
        }
    }
}' \
  --compressed