generated from sellersindustry/SherpaJS-template-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b382ab
commit d6d07d8
Showing
12 changed files
with
382 additions
and
1,139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | ||
|
||
name: Node.js Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- run: npm ci | ||
- run: npm test | ||
|
||
publish-npm: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: reedyuk/[email protected] | ||
with: | ||
version: ${{github.event.release.tag_name}} | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
registry-url: https://registry.npmjs.org/ | ||
- run: npm ci | ||
- run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,118 @@ | ||
# SherpaJS Module Template | ||
SherpaJS empowers developers to effortlessly construct modular and reusable microservices. This template provides a quick way to build custom SherpaJS Modules. | ||
|
||
### See [SherpaJS Documentation](https://github.com/sellersindustry/SherpaJS) for more information. | ||
# SherpaJS Events | ||
![NPM Version](https://img.shields.io/npm/v/sherpajs-events) | ||
|
||
Connect to event tracking platforms like PostHog | ||
using [Metadapter Event](https://github.com/sellersindustry/metadapter-event) and create event tracking endpoints for | ||
[SherpaJS](https://github.com/sellersindustry/SherpaJS) an agnostic and | ||
modular serverless platform. | ||
|
||
|
||
|
||
## Features | ||
- ✅ [SherpaJS](https://github.com/sellersindustry/SherpaJS) Module, an Agnostic and Modular Serverless Platform | ||
- ✅ Log event using [Metadapter Event](https://github.com/sellersindustry/metadapter-event) | ||
- ✅ Supports PostHog | ||
|
||
## Installation | ||
``` | ||
npm install sherpajs-events | ||
``` | ||
|
||
## Example Usage | ||
Services are loaded using [Metadapter Event](https://github.com/sellersindustry/metadapter-event). The `id` is the eventID that is logged with your event platform. The `schema` is optional, but uses [AJV schema](https://ajv.js.org/). | ||
```typescript | ||
// sherpa.server.ts | ||
import { SherpaJS } from "sherpa-core"; | ||
import { ContextSchema, Service, ServiceType } from "sherpajs-events"; | ||
|
||
export default SherpaJS.Load.module<ContextSchema>({ | ||
entry: "sherpajs-events", | ||
context: { | ||
service: Service(ServiceType.Skeleton, undefined), | ||
events: { | ||
"test": { | ||
id: "test", | ||
schema: { | ||
type: "object", | ||
properties: { | ||
foo: {type: "integer"}, | ||
bar: {type: "string"} | ||
}, | ||
required: ["foo"], | ||
additionalProperties: false | ||
} | ||
}, | ||
"test2": { | ||
id: "test2" | ||
} | ||
} | ||
} | ||
}); | ||
|
||
``` | ||
|
||
### Endpoint `POST:/test` | ||
**Body** | ||
```json | ||
{ | ||
"foo": true | ||
} | ||
``` | ||
**Response** | ||
``` | ||
400 Bad Request | ||
Property 'foo': must be integer | ||
``` | ||
|
||
### Endpoint `POST:/test` | ||
**Body** | ||
```json | ||
Hello World | ||
``` | ||
**Response** | ||
``` | ||
400 Bad Request | ||
Request body must be in JSON format. | ||
``` | ||
|
||
### Endpoint `POST:/test` | ||
**Body** | ||
```json | ||
{ | ||
"foo": 3, | ||
"bar": "hello world" | ||
} | ||
``` | ||
**Response** | ||
``` | ||
201 Created | ||
Successfully Logged Event | ||
``` | ||
|
||
|
||
### Endpoint `POST:/test2` | ||
**Body** | ||
```json | ||
{ | ||
"test": "hello world", | ||
} | ||
``` | ||
**Response** | ||
``` | ||
201 Created | ||
Successfully Logged Event | ||
``` | ||
|
||
### Endpoint `POST:/test2` | ||
**Body** | ||
```json | ||
{ | ||
"test": true, | ||
} | ||
``` | ||
**Response** | ||
``` | ||
201 Created | ||
Successfully Logged Event | ||
``` |
Oops, something went wrong.