@seeka-labs/cli-apps 1.1.39 → 2.0.7-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +31 -36
- package/dist/index.js.map +4 -4
- package/dist/init-template/.gitlab-ci.yml +47 -0
- package/dist/init-template/.yarnrc.yml +8 -0
- package/dist/init-template/README.md +7 -0
- package/dist/{init-templates → init-template/app}/browser/jest.config.js +11 -11
- package/dist/{init-templates → init-template/app}/browser/package.json +16 -12
- package/dist/{init-templates → init-template/app}/browser/scripts/esbuild/build-browser-plugin.mjs +110 -110
- package/dist/{init-templates → init-template/app}/browser/scripts/esbuild/plugins/importAsGlobals.mjs +38 -38
- package/dist/{init-templates → init-template/app}/browser/src/browser.ts +12 -12
- package/dist/{init-templates → init-template/app}/browser/src/plugin/index.test.ts +6 -6
- package/dist/{init-templates → init-template/app}/browser/src/plugin/index.ts +47 -49
- package/dist/{init-templates → init-template/app}/browser/tsconfig.json +34 -34
- package/dist/{init-templates/netlify-function → init-template/app/server-azure-function}/.eslintrc.cjs +2 -10
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/.funcignore +12 -7
- package/dist/init-template/app/server-azure-function/.nvmrc +1 -0
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/README.md +104 -107
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/host.json +1 -10
- package/dist/init-template/app/server-azure-function/package.json +52 -0
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/functions/seekaAppWebhook.ts +235 -236
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/browser/index.ts +54 -54
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/jobs/index.ts +1 -1
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/logging/index.ts +92 -92
- package/dist/{init-templates/azure-function/src/lib/browser → init-template/app/server-azure-function/src/lib}/models/index.ts +6 -6
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/state/redis/index.ts +96 -65
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/state/seeka/installations.ts +64 -66
- package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/tsconfig.json +1 -1
- package/dist/init-template/package.json +28 -0
- package/dist/init-template/tsconfig.json +25 -0
- package/package.json +5 -4
- package/dist/init-templates/aws-lambda/.env.example +0 -15
- package/dist/init-templates/aws-lambda/.eslintrc.cjs +0 -19
- package/dist/init-templates/aws-lambda/.example.gitignore +0 -49
- package/dist/init-templates/aws-lambda/.gitlab-ci.yml +0 -39
- package/dist/init-templates/aws-lambda/.nvmrc +0 -1
- package/dist/init-templates/aws-lambda/.vscode/extensions.json +0 -5
- package/dist/init-templates/aws-lambda/.vscode/launch.json +0 -20
- package/dist/init-templates/aws-lambda/.vscode/settings.json +0 -3
- package/dist/init-templates/aws-lambda/.vscode/tasks.json +0 -12
- package/dist/init-templates/aws-lambda/README.md +0 -77
- package/dist/init-templates/aws-lambda/jest.config.js +0 -5
- package/dist/init-templates/aws-lambda/package.json +0 -53
- package/dist/init-templates/aws-lambda/scripts/ngrok.js +0 -28
- package/dist/init-templates/aws-lambda/src/index.test.ts +0 -7
- package/dist/init-templates/aws-lambda/src/index.ts +0 -33
- package/dist/init-templates/aws-lambda/src/lib/logging/index.ts +0 -88
- package/dist/init-templates/aws-lambda/src/lib/services/index.ts +0 -41
- package/dist/init-templates/aws-lambda/src/lib/state/redis/index.ts +0 -65
- package/dist/init-templates/aws-lambda/src/lib/state/seeka/installations.ts +0 -67
- package/dist/init-templates/aws-lambda/src/routes/seekaAppWebhook.ts +0 -194
- package/dist/init-templates/aws-lambda/tsconfig.json +0 -31
- package/dist/init-templates/aws-lambda/yarn.lock +0 -4392
- package/dist/init-templates/azure-function/.eslintrc.cjs +0 -19
- package/dist/init-templates/azure-function/.example.gitignore +0 -48
- package/dist/init-templates/azure-function/.gitlab-ci.yml +0 -48
- package/dist/init-templates/azure-function/.nvmrc +0 -1
- package/dist/init-templates/azure-function/.vscode/extensions.json +0 -7
- package/dist/init-templates/azure-function/.vscode/launch.json +0 -13
- package/dist/init-templates/azure-function/.vscode/settings.json +0 -9
- package/dist/init-templates/azure-function/.vscode/tasks.json +0 -39
- package/dist/init-templates/azure-function/jest.config.js +0 -5
- package/dist/init-templates/azure-function/package.json +0 -47
- package/dist/init-templates/azure-function/scripts/dev-queue-setup.js +0 -30
- package/dist/init-templates/azure-function/src/index.test.ts +0 -7
- package/dist/init-templates/azure-function/yarn.lock +0 -3772
- package/dist/init-templates/browser/.editorconfig +0 -14
- package/dist/init-templates/browser/.eslintrc.cjs +0 -1
- package/dist/init-templates/browser/.yarnrc +0 -1
- package/dist/init-templates/browser/yarn.lock +0 -3045
- package/dist/init-templates/netlify-function/.env.example +0 -18
- package/dist/init-templates/netlify-function/.example.gitignore +0 -36
- package/dist/init-templates/netlify-function/.nvmrc +0 -1
- package/dist/init-templates/netlify-function/.vscode/launch.json +0 -45
- package/dist/init-templates/netlify-function/README.md +0 -62
- package/dist/init-templates/netlify-function/jest.config.js +0 -5
- package/dist/init-templates/netlify-function/netlify.toml +0 -7
- package/dist/init-templates/netlify-function/package.json +0 -39
- package/dist/init-templates/netlify-function/src/api/example-job-background/index.ts +0 -52
- package/dist/init-templates/netlify-function/src/api/polling-example-job-scheduled/index.ts +0 -46
- package/dist/init-templates/netlify-function/src/api/seeka-app-webhook/index.ts +0 -217
- package/dist/init-templates/netlify-function/src/index.test.ts +0 -7
- package/dist/init-templates/netlify-function/src/lib/jobs/index.ts +0 -68
- package/dist/init-templates/netlify-function/src/lib/logging/index.ts +0 -91
- package/dist/init-templates/netlify-function/src/lib/services/index.ts +0 -41
- package/dist/init-templates/netlify-function/src/lib/state/redis/index.ts +0 -65
- package/dist/init-templates/netlify-function/src/lib/state/seeka/installations.ts +0 -67
- package/dist/init-templates/netlify-function/tsconfig.json +0 -25
- package/dist/init-templates/netlify-function/yarn.lock +0 -9337
- /package/dist/{init-templates → init-template/app}/browser/README.md +0 -0
- /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/local.settings.example.json +0 -0
- /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/scripts/ngrok.js +0 -0
- /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/functions/healthCheck.ts +0 -0
- /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/functions/pollingExample.ts +0 -0
- /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/functions/queueExample.ts +0 -0
- /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/services/index.ts +0 -0
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import type { Logger } from 'winston';
|
|
2
|
-
|
|
3
|
-
import { Context } from 'aws-lambda';
|
|
4
|
-
import { Request, Response } from 'express';
|
|
5
|
-
import winston from 'winston';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
PersonIdentifiers, SeekaActivityAcceptedWebhookPayload, SeekaAppInstalledWebhookPayload,
|
|
9
|
-
SeekaAppInstallSettingsUpdatedWebhookPayload, SeekaAppUninstalledWebhookPayload,
|
|
10
|
-
SeekaIdentityChangedWebhookPayload, SeekaWebhookCallType, SeekaWebhookPayload,
|
|
11
|
-
throwOnInvalidWebhookSignature
|
|
12
|
-
} from '@seeka-labs/sdk-apps-server';
|
|
13
|
-
|
|
14
|
-
import { webhookLogger } from '../lib/logging';
|
|
15
|
-
import { startServices } from '../lib/services';
|
|
16
|
-
import {
|
|
17
|
-
createOrUpdateInstallation, deleteInstallation, SampleAppInstallSettings, SeekaAppInstallState, tryGetInstallation
|
|
18
|
-
} from '../lib/state/seeka/installations';
|
|
19
|
-
|
|
20
|
-
export async function seekaAppWebhook(req: Request, res: Response, context: Context): Promise<void> {
|
|
21
|
-
const bodyStr = req.body as string;
|
|
22
|
-
const body = JSON.parse(bodyStr) as SeekaWebhookPayload;
|
|
23
|
-
|
|
24
|
-
const logger = webhookLogger(body, context);
|
|
25
|
-
logger.profile('http.seeka.webhook.app')
|
|
26
|
-
logger.verbose('Received webhook from Seeka', { body });
|
|
27
|
-
|
|
28
|
-
// Handle probe
|
|
29
|
-
if (body.type === SeekaWebhookCallType.Probe) {
|
|
30
|
-
res.status(204).send();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Validate webhook
|
|
35
|
-
try {
|
|
36
|
-
throwOnInvalidWebhookSignature(process.env.SEEKA_APP_SECRET as string, req.headers, bodyStr);
|
|
37
|
-
logger.debug('Webhook signature validated', { body });
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
logger.warn('Webhook signature invalid', { body });
|
|
41
|
-
res.status(401).json({ error: "Webhook call invalid" }).send();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (body.isTest) {
|
|
46
|
-
// This is a test webhook call
|
|
47
|
-
res.status(204).send();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
await startServices(logger);
|
|
52
|
-
|
|
53
|
-
// Check if the webhook is for an app we have installed
|
|
54
|
-
let installation: SeekaAppInstallState | null = null;
|
|
55
|
-
if (body.type != SeekaWebhookCallType.AppInstalled) {
|
|
56
|
-
installation = await tryGetInstallation((body as SeekaAppInstalledWebhookPayload).context?.applicationInstallId as string, false, logger);
|
|
57
|
-
if (installation == null) {
|
|
58
|
-
logger.warn('Webhook call cannot be processed as the installation ID is not known by this app', { body });
|
|
59
|
-
|
|
60
|
-
res.status(422).json({ error: "App not installed" }).send();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Do something
|
|
66
|
-
try {
|
|
67
|
-
let errorMessage: string | null = null;
|
|
68
|
-
switch (body.type) {
|
|
69
|
-
case SeekaWebhookCallType.AppInstalled:
|
|
70
|
-
{
|
|
71
|
-
errorMessage = await onInstallation(body as SeekaAppInstalledWebhookPayload, logger);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case SeekaWebhookCallType.AppInstallSettingsUpdated:
|
|
75
|
-
{
|
|
76
|
-
errorMessage = await onInstallationSettingsUpdate(body as SeekaAppInstallSettingsUpdatedWebhookPayload, logger);
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case SeekaWebhookCallType.AppUninstalled:
|
|
80
|
-
{
|
|
81
|
-
if (!body.isTest) {
|
|
82
|
-
const payload = body as SeekaAppUninstalledWebhookPayload;
|
|
83
|
-
await deleteInstallation(payload.context?.applicationInstallId as string, logger)
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case SeekaWebhookCallType.ActivityAccepted:
|
|
88
|
-
{
|
|
89
|
-
const payload = body as SeekaActivityAcceptedWebhookPayload;
|
|
90
|
-
await handleSeekaActivity(payload, logger);
|
|
91
|
-
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case SeekaWebhookCallType.IdentityChanged:
|
|
95
|
-
{
|
|
96
|
-
const payload = body as SeekaIdentityChangedWebhookPayload;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (errorMessage) {
|
|
102
|
-
logger.warn('Webhook call failed', { errorMessage });
|
|
103
|
-
res.status(400).json({ error: { message: errorMessage } }).send();
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
res.status(204).send();
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
logger.error('Failed to handle webhook', { ex: winston.exceptions.getAllInfo(err) });
|
|
111
|
-
res.status(500).json({ error: "Request failed" }).send();
|
|
112
|
-
}
|
|
113
|
-
finally {
|
|
114
|
-
logger.profile('http.seeka.webhook.app')
|
|
115
|
-
logger.verbose('Seeka webhook handled');
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const validateInstallationSettings = async (installSettings: SampleAppInstallSettings, logger: Logger): Promise<string | null> => {
|
|
120
|
-
// Returning an error message string here will block the installation request or settings update request by the user installing the app
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const onInstallation = async (payload: SeekaAppInstalledWebhookPayload, logger: Logger): Promise<string | null> => {
|
|
127
|
-
if (payload.isTest) return null;
|
|
128
|
-
|
|
129
|
-
const errorMessage = await validateInstallationSettings(payload.content?.installationSettings || {}, logger);
|
|
130
|
-
if (errorMessage) return errorMessage;
|
|
131
|
-
|
|
132
|
-
const installation = await createOrUpdateInstallation({
|
|
133
|
-
...payload.context,
|
|
134
|
-
installationState: {
|
|
135
|
-
grantedPermissions: payload.content?.grantedPermissions || []
|
|
136
|
-
},
|
|
137
|
-
applicationInstallId: payload.context?.applicationInstallId as string,
|
|
138
|
-
organisationBrandId: payload.context?.organisationBrandId as string,
|
|
139
|
-
organisationId: payload.context?.organisationId as string,
|
|
140
|
-
installedAt: new Date().toISOString(),
|
|
141
|
-
installationSettings: payload.content?.installationSettings || {}
|
|
142
|
-
}, logger)
|
|
143
|
-
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const onInstallationSettingsUpdate = async (payload: SeekaAppInstallSettingsUpdatedWebhookPayload, logger: Logger): Promise<string | null> => {
|
|
148
|
-
if (payload.isTest) return null;
|
|
149
|
-
|
|
150
|
-
const errorMessage = await validateInstallationSettings(payload.content?.installationSettings || {}, logger);
|
|
151
|
-
if (errorMessage) return errorMessage;
|
|
152
|
-
|
|
153
|
-
const existingInstallation = await tryGetInstallation(payload.context?.applicationInstallId as string, true, logger) as SeekaAppInstallState;
|
|
154
|
-
const installation = await createOrUpdateInstallation({
|
|
155
|
-
...existingInstallation,
|
|
156
|
-
installationState: {
|
|
157
|
-
...existingInstallation.installationState,
|
|
158
|
-
grantedPermissions: payload.content?.grantedPermissions || []
|
|
159
|
-
},
|
|
160
|
-
installationSettings: payload.content?.installationSettings || {},
|
|
161
|
-
}, logger)
|
|
162
|
-
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const handleSeekaActivity = async (activity: SeekaActivityAcceptedWebhookPayload, logger: Logger) => {
|
|
167
|
-
// const context = activity.context as SeekaAppWebhookContext;
|
|
168
|
-
// const helper = SeekaAppHelper.create(process.env['SEEKA_APP_SECRET'] as string, {
|
|
169
|
-
// organisationId: context.organisationId as string,
|
|
170
|
-
// applicationInstallId: context.applicationInstallId as string,
|
|
171
|
-
// applicationId: process.env['SEEKA_APP_ID'] as string,
|
|
172
|
-
// }, { name, version }, logger);
|
|
173
|
-
|
|
174
|
-
// // Append a first name to the identity
|
|
175
|
-
// await helper.api.mergeIdentity({
|
|
176
|
-
// seekaPId: activity.content?.personId,
|
|
177
|
-
// firstName: [
|
|
178
|
-
// 'firstname_' + new Date().getTime()
|
|
179
|
-
// ]
|
|
180
|
-
// }, {
|
|
181
|
-
// method: 'toremove',
|
|
182
|
-
// origin: TrackingEventSourceOriginType.Server
|
|
183
|
-
// })
|
|
184
|
-
|
|
185
|
-
// // Fire off a tracking event
|
|
186
|
-
// await helper.api.trackActivity({
|
|
187
|
-
// activityName: TrackingActivityNames.Custom,
|
|
188
|
-
// activityNameCustom: 'seeka-app-activity-accepted',
|
|
189
|
-
// activityId: 'act' + new Date().getTime(),
|
|
190
|
-
// }, activity.content?.personId as string, {
|
|
191
|
-
// method: 'toremove',
|
|
192
|
-
// origin: TrackingEventSourceOriginType.Server
|
|
193
|
-
// })
|
|
194
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"allowJs": false,
|
|
4
|
-
"skipLibCheck": true,
|
|
5
|
-
"strict": true,
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"preserveConstEnums": true,
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"rootDir": ".",
|
|
10
|
-
"module": "commonjs",
|
|
11
|
-
"target": "es6",
|
|
12
|
-
"inlineSourceMap": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"isolatedModules": true,
|
|
15
|
-
"forceConsistentCasingInFileNames": true,
|
|
16
|
-
"typeRoots": [
|
|
17
|
-
"node_modules/@types"
|
|
18
|
-
],
|
|
19
|
-
"types": [
|
|
20
|
-
"node"
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
"include": [
|
|
24
|
-
"src/index.ts"
|
|
25
|
-
],
|
|
26
|
-
"exclude": [
|
|
27
|
-
"node_modules",
|
|
28
|
-
"dist",
|
|
29
|
-
"scripts"
|
|
30
|
-
]
|
|
31
|
-
}
|