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

Moving local serverless server into separate package #404

Merged
merged 13 commits into from
Dec 21, 2020

Conversation

miketalley
Copy link
Contributor

@miketalley miketalley commented Dec 17, 2020

Description and Context

Moving the local serverless testing logic out of the cms-cli command file into a separate lerna package.

This is currently still WIP, I would love any feedback on how this is being executed. Specifically...

  • Does it make sense to import this package as a dependency in cms-cli the way that it is and abstract the logic away
  • Does the signature of the main export(start) make sense -- it takes an options object shaped like
{
  accountId: <portalId/accountId>,
  path: <pathToLocalDotFunctionsFolder>,
  port: <customPortToRunServerOn>,
  contact: <booleanValueToSpecifyIfContactDataShouldBePassedToServerlessFunction> // defaults to true
}

Who to Notify

@gcorne

@miketalley miketalley requested a review from anthmatic December 17, 2020 18:07
Copy link
Contributor

@gcorne gcorne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a quick pass (not super deep).

@@ -0,0 +1,71 @@
# @hubspot/local-serverless-server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should come up with another name for the package. My suggestion would be something that doesn't have local in the name because I think it could be used for things like testing a serverless function in a CI situation and for it to forgo the pun. Perhaps we could use something along the lines of serverless-function-runner or serverless-runner. I think the model of this being about execution not a server is best. Could even use execute or executor. Naming is hard…

Copy link
Contributor Author

@miketalley miketalley Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted the name to focus on the fact that we need to run a server to test serverLESS functions 😂
There is an express server that allows the endpoints to be accessed locally

For more information on using these tools, see [Local Development Tooling: Getting Started](https://designers.hubspot.com/tutorials/getting-started-with-local-development)

### Installation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest some docs that state that this is intended for use with the CLI with a link to either the docs on developers.hubspot.com or the NPM package.

HUBSPOT_CONTACT_VID // default: 123
HUBSPOT_CONTACT_IS_LOGGED_IN // default: false
HUBSPOT_CONTACT_LIST_MEMBERSHIPS // default: []
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably be using either .env or a config file for this and be consider when these may be things that may make sense to live with the project in source control.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll move this out.

"HUBSPOT_CONTACT_VID": 456,
"HUBSPOT_CONTACT_IS_LOGGED_IN": true,
"HUBSPOT_CONTACT_LIST_MEMBERSHIPS": ["some", "memberships"]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this a bit more? I thought we were faking the way this works when executing in the HubSpot serverless infra?

Copy link
Contributor Author

@miketalley miketalley Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way production works is it grabs the cookie value for hubspotutk which is not an actual contact id. It's some sort of hashed value that the BE understands and can convert into a contact. AFAIK there is not an API endpoint to get the contact data using this value, and I'm not sure we want there to be an endpoint for this.

So instead, in order to facilitate testing around the contact prop that gets passed into the function, this allows for customization of the data that is passed in. By setting values for these environment variables, that mocked value will be passed into the function for testing.

@miketalley miketalley marked this pull request as ready for review December 21, 2020 15:04
@miketalley miketalley merged commit e6422d7 into serverless/local-testing Dec 21, 2020
@miketalley miketalley deleted the serverless/local-testing-package branch December 21, 2020 15:05
@miketalley
Copy link
Contributor Author

Going to merge this back into the serverless/local-testing branch as this branch has served it's purpose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants