Skip to content

Commit 6e47419

Browse files
author
Shaun Persad
committed
publishing beta package
1 parent 94bc1ac commit 6e47419

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

.github/workflows/package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
env:
3030
NODE_AUTH_TOKEN: ${{ secrets.ENVOYBOT_PERSONAL_ACCESS_TOKEN }}
3131

32-
- run: npm publish --access public
32+
- run: npm publish --tag beta --access public
3333
env:
3434
NODE_AUTH_TOKEN: ${{ secrets.ENVOY_NPM_AUTOMATION_TOKEN }}
3535

@@ -38,6 +38,6 @@ jobs:
3838
with:
3939
registry-url: "https://npm.pkg.github.com"
4040

41-
- run: npm publish
41+
- run: npm publish --tag beta
4242
env:
4343
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@envoy/envoy-integrations-sdk",
3-
"version": "2.0.0",
3+
"version": "2.0.0-beta.0",
44
"description": "SDK for building Envoy integrations.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -42,10 +42,12 @@
4242
"factory.ts": "^0.5.2",
4343
"faker": "^5.5.3",
4444
"jsonwebtoken": "^8.5.1",
45+
"luxon": "^1.27.0",
4546
"qs": "^6.10.1"
4647
},
4748
"devDependencies": {
4849
"@types/express": "^4.17.12",
50+
"@types/luxon": "^1.27.0",
4951
"@typescript-eslint/eslint-plugin": "^4.26.0",
5052
"@typescript-eslint/parser": "^4.26.0",
5153
"chai": "^4.2.0",

src/payloads/EntryPayload.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import JSONAPIData from '../util/json-api/JSONAPIData';
23

34
/**
@@ -61,4 +62,24 @@ type EntryPayload = {
6162
}
6263
};
6364

65+
export function normalizeEntryPayload(payload : EntryPayload): EntryPayload {
66+
const {
67+
'signed-in-at': signedInAt,
68+
'signed-out-at': signedOutAt,
69+
'legal-docs': legalDocs,
70+
} = payload.attributes;
71+
const normalized = { ...payload };
72+
normalized.attributes['signed-in-at'] = DateTime.fromSQL(signedInAt, { zone: 'UTC' }).toISO();
73+
if (signedOutAt) {
74+
normalized.attributes['signed-out-at'] = DateTime.fromSQL(signedOutAt, { zone: 'UTC' }).toISO();
75+
}
76+
if (Array.isArray(legalDocs) && legalDocs.length) {
77+
normalized.attributes['legal-docs'] = legalDocs.map((doc) => ({
78+
...doc,
79+
'signed-at': DateTime.fromSQL(doc['signed-at'], { zone: 'UTC' }).toISO(),
80+
}));
81+
}
82+
return normalized;
83+
}
84+
6485
export default EntryPayload;

src/payloads/InvitePayload.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DateTime } from 'luxon';
12
import JSONAPIData from '../util/json-api/JSONAPIData';
23

34
/**
@@ -60,4 +61,16 @@ type InvitePayload = {
6061
}
6162
};
6263

64+
export function normalizeInvitePayload(payload: InvitePayload): InvitePayload {
65+
const { 'legal-docs': legalDocs } = payload.attributes;
66+
const normalized = { ...payload };
67+
if (Array.isArray(legalDocs) && legalDocs.length) {
68+
normalized.attributes['legal-docs'] = legalDocs.map((doc) => ({
69+
...doc,
70+
'signed-at': DateTime.fromSQL(doc['signed-at'], { zone: 'UTC' }).toISO(),
71+
}));
72+
}
73+
return normalized;
74+
}
75+
6376
export default InvitePayload;

src/sdk/EnvoyPluginSDK.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import EnvoyPluginJob from './EnvoyPluginJob';
44
import EnvoyJWT from '../util/EnvoyJWT';
55
import EnvoyUserAPI from './EnvoyUserAPI';
66
import EnvoyPluginAPI from './EnvoyPluginAPI';
7+
import JSONAPIData from '../util/json-api/JSONAPIData';
8+
import EntryPayload, { normalizeEntryPayload } from '../payloads/EntryPayload';
9+
import InvitePayload, { normalizeInvitePayload } from '../payloads/InvitePayload';
710

811
/**
912
* Every Envoy request has a `meta` and `payload`.
@@ -74,7 +77,15 @@ export default class EnvoyPluginSDK<Meta = unknown, Payload = unknown> {
7477
if (!this.isVerified) {
7578
throw new Error('Could not verify payload.');
7679
}
77-
return this.body.payload;
80+
const payload = this.body.payload as unknown as JSONAPIData;
81+
switch (payload.type) {
82+
case 'entries':
83+
return normalizeEntryPayload(payload as unknown as EntryPayload) as unknown as Payload;
84+
case 'invites':
85+
return normalizeInvitePayload(payload as unknown as InvitePayload) as unknown as Payload;
86+
default:
87+
return payload as unknown as Payload;
88+
}
7889
}
7990

8091
/**

0 commit comments

Comments
 (0)