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

save-order-datastore

v2.1244.0

Published

## What is it

Downloads

469

Readme

Cloud function Save order raw data to datastore

What is it

This cloud function is here to register raw data from microservices and the api inside datastore.

Dependencies

Install

  1. Install node dependencies
yarn lerna bootstrap
  1. Authenticate with Google Default Credential
gcloud auth application-default login

Your user will be used to deploy the serverless stack, you must have at least the following roles on the targeted project:

  • Deployment Manager Editor
  • Storage Admin
  • Logging Admin
  • Cloud Functions Developer
  1. copy .env.exemple

Development workflow

In your local machine, functions are run individually in tests. They are never run in a local stack.

Working on an existing function

  1. Write your code changes

  2. Test it with unit tests

  3. Trigger the function locally in integration with the dev stack (cf local invocation)

  4. Deploy the stack: yarn sls deploy

  5. Test in integration with the dev stack

    You can use

    yarn sls invoke -f <functionName> -p <path/to/an/event/mock>

    to trigger your function with a mocked payload

    or trigger the service which will trigger the function with a real payload

Create a new function

  1. Write an empty handler which log the event

  2. Configure the triggers of the function

  3. Deploy the stack: yarn sls deploy

  4. Trigger the function with the trigger

  5. Get the logged event and put it in a mock.json to mock the event to help the local development

  6. Write a test per possible trigger event

  7. Write your code changes

  8. Test it with unit tests

  9. Trigger the function locally in integration with the dev stack (cf local invocation)

  10. Deploy the stack: yarn sls deploy

  11. Test in the dev stack

    You can use

    yarn sls invoke -f <functionName> -p <path/to/an/event/mock>

    to trigger your function with a mocked payload

    or trigger the service which will trigger the function with a real payload

Local invocation

🚧 WIP: this will be simplified 🚧

Functions Framework is used to locally invoke the functions. It starts a development server which handles the http request as CGP handle it and trigger the local cloud function in the closest way of the reality. Functions Framework only handle compiled JS.

  1. Compile and start the function in the development server
FUNCTION_NAME=<functionName> TYPE=<event|http> yarn local

invoke-local

This will build the code and start it in an express server

  1. Request the development server with a http request

You can use Curl or PostMan for example

curl --location --request POST 'http://localhost:8080/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "orderId": "77b787d4-e9eb-4797-b78f-53da679a831c",
    "restaurantId": 623
}'

Good to know:

  • To invoke a http triggered function with json body, you need to provide the header Content-Type with application/json
  • To invoke an event triggered function, call the server with a json body composed of two attributes:
    • data (required): the event
    • context (optional): the context
  • You will really interact with the real stack. Never set production variables in your .env
  • The GCP libraries will authenticate them self with the Google Default Credential
    • credentials from GOOGLE_APPLICATION_CREDENTIALS if exist
    • credentials created by gcloud auth application-default login otherwise (recommended)
  • You need to rebuild (yarn local) between each code modifications. There is currently no watch.

Next steps

Automate this in serverless-google-cloudfunctions to run it in one command

sls invoke local -f $FUNCTION_NAME -p $PAYLOAD_PATH