@seeka-labs/cli-apps 1.1.39 → 2.0.7-rc.1

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.
Files changed (95) hide show
  1. package/dist/index.js +31 -36
  2. package/dist/index.js.map +4 -4
  3. package/dist/init-template/.gitlab-ci.yml +47 -0
  4. package/dist/init-template/.yarnrc.yml +8 -0
  5. package/dist/init-template/README.md +7 -0
  6. package/dist/{init-templates → init-template/app}/browser/jest.config.js +11 -11
  7. package/dist/{init-templates → init-template/app}/browser/package.json +16 -12
  8. package/dist/{init-templates → init-template/app}/browser/scripts/esbuild/build-browser-plugin.mjs +110 -110
  9. package/dist/{init-templates → init-template/app}/browser/scripts/esbuild/plugins/importAsGlobals.mjs +38 -38
  10. package/dist/{init-templates → init-template/app}/browser/src/browser.ts +12 -12
  11. package/dist/{init-templates → init-template/app}/browser/src/plugin/index.test.ts +6 -6
  12. package/dist/{init-templates → init-template/app}/browser/src/plugin/index.ts +47 -49
  13. package/dist/{init-templates → init-template/app}/browser/tsconfig.json +34 -34
  14. package/dist/{init-templates/netlify-function → init-template/app/server-azure-function}/.eslintrc.cjs +2 -10
  15. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/.funcignore +12 -7
  16. package/dist/init-template/app/server-azure-function/.nvmrc +1 -0
  17. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/README.md +104 -107
  18. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/host.json +1 -10
  19. package/dist/init-template/app/server-azure-function/package.json +52 -0
  20. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/functions/seekaAppWebhook.ts +235 -236
  21. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/browser/index.ts +54 -54
  22. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/jobs/index.ts +1 -1
  23. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/logging/index.ts +92 -92
  24. package/dist/{init-templates/azure-function/src/lib/browser → init-template/app/server-azure-function/src/lib}/models/index.ts +6 -6
  25. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/state/redis/index.ts +96 -65
  26. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/state/seeka/installations.ts +64 -66
  27. package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/tsconfig.json +1 -1
  28. package/dist/init-template/package.json +28 -0
  29. package/dist/init-template/tsconfig.json +25 -0
  30. package/package.json +5 -4
  31. package/dist/init-templates/aws-lambda/.env.example +0 -15
  32. package/dist/init-templates/aws-lambda/.eslintrc.cjs +0 -19
  33. package/dist/init-templates/aws-lambda/.example.gitignore +0 -49
  34. package/dist/init-templates/aws-lambda/.gitlab-ci.yml +0 -39
  35. package/dist/init-templates/aws-lambda/.nvmrc +0 -1
  36. package/dist/init-templates/aws-lambda/.vscode/extensions.json +0 -5
  37. package/dist/init-templates/aws-lambda/.vscode/launch.json +0 -20
  38. package/dist/init-templates/aws-lambda/.vscode/settings.json +0 -3
  39. package/dist/init-templates/aws-lambda/.vscode/tasks.json +0 -12
  40. package/dist/init-templates/aws-lambda/README.md +0 -77
  41. package/dist/init-templates/aws-lambda/jest.config.js +0 -5
  42. package/dist/init-templates/aws-lambda/package.json +0 -53
  43. package/dist/init-templates/aws-lambda/scripts/ngrok.js +0 -28
  44. package/dist/init-templates/aws-lambda/src/index.test.ts +0 -7
  45. package/dist/init-templates/aws-lambda/src/index.ts +0 -33
  46. package/dist/init-templates/aws-lambda/src/lib/logging/index.ts +0 -88
  47. package/dist/init-templates/aws-lambda/src/lib/services/index.ts +0 -41
  48. package/dist/init-templates/aws-lambda/src/lib/state/redis/index.ts +0 -65
  49. package/dist/init-templates/aws-lambda/src/lib/state/seeka/installations.ts +0 -67
  50. package/dist/init-templates/aws-lambda/src/routes/seekaAppWebhook.ts +0 -194
  51. package/dist/init-templates/aws-lambda/tsconfig.json +0 -31
  52. package/dist/init-templates/aws-lambda/yarn.lock +0 -4392
  53. package/dist/init-templates/azure-function/.eslintrc.cjs +0 -19
  54. package/dist/init-templates/azure-function/.example.gitignore +0 -48
  55. package/dist/init-templates/azure-function/.gitlab-ci.yml +0 -48
  56. package/dist/init-templates/azure-function/.nvmrc +0 -1
  57. package/dist/init-templates/azure-function/.vscode/extensions.json +0 -7
  58. package/dist/init-templates/azure-function/.vscode/launch.json +0 -13
  59. package/dist/init-templates/azure-function/.vscode/settings.json +0 -9
  60. package/dist/init-templates/azure-function/.vscode/tasks.json +0 -39
  61. package/dist/init-templates/azure-function/jest.config.js +0 -5
  62. package/dist/init-templates/azure-function/package.json +0 -47
  63. package/dist/init-templates/azure-function/scripts/dev-queue-setup.js +0 -30
  64. package/dist/init-templates/azure-function/src/index.test.ts +0 -7
  65. package/dist/init-templates/azure-function/yarn.lock +0 -3772
  66. package/dist/init-templates/browser/.editorconfig +0 -14
  67. package/dist/init-templates/browser/.eslintrc.cjs +0 -1
  68. package/dist/init-templates/browser/.yarnrc +0 -1
  69. package/dist/init-templates/browser/yarn.lock +0 -3045
  70. package/dist/init-templates/netlify-function/.env.example +0 -18
  71. package/dist/init-templates/netlify-function/.example.gitignore +0 -36
  72. package/dist/init-templates/netlify-function/.nvmrc +0 -1
  73. package/dist/init-templates/netlify-function/.vscode/launch.json +0 -45
  74. package/dist/init-templates/netlify-function/README.md +0 -62
  75. package/dist/init-templates/netlify-function/jest.config.js +0 -5
  76. package/dist/init-templates/netlify-function/netlify.toml +0 -7
  77. package/dist/init-templates/netlify-function/package.json +0 -39
  78. package/dist/init-templates/netlify-function/src/api/example-job-background/index.ts +0 -52
  79. package/dist/init-templates/netlify-function/src/api/polling-example-job-scheduled/index.ts +0 -46
  80. package/dist/init-templates/netlify-function/src/api/seeka-app-webhook/index.ts +0 -217
  81. package/dist/init-templates/netlify-function/src/index.test.ts +0 -7
  82. package/dist/init-templates/netlify-function/src/lib/jobs/index.ts +0 -68
  83. package/dist/init-templates/netlify-function/src/lib/logging/index.ts +0 -91
  84. package/dist/init-templates/netlify-function/src/lib/services/index.ts +0 -41
  85. package/dist/init-templates/netlify-function/src/lib/state/redis/index.ts +0 -65
  86. package/dist/init-templates/netlify-function/src/lib/state/seeka/installations.ts +0 -67
  87. package/dist/init-templates/netlify-function/tsconfig.json +0 -25
  88. package/dist/init-templates/netlify-function/yarn.lock +0 -9337
  89. /package/dist/{init-templates → init-template/app}/browser/README.md +0 -0
  90. /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/local.settings.example.json +0 -0
  91. /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/scripts/ngrok.js +0 -0
  92. /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/functions/healthCheck.ts +0 -0
  93. /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/functions/pollingExample.ts +0 -0
  94. /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/functions/queueExample.ts +0 -0
  95. /package/dist/{init-templates/azure-function → init-template/app/server-azure-function}/src/lib/services/index.ts +0 -0
@@ -1,237 +1,236 @@
1
- import winston from 'winston';
2
-
3
- import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';
4
- import {
5
- PersonIdentifiers, SeekaActivityAcceptedWebhookPayload, SeekaAppInstalledWebhookPayload,
6
- SeekaAppInstallSettingsUpdatedWebhookPayload, SeekaAppUninstalledWebhookPayload,
7
- SeekaIdentityChangedWebhookPayload, SeekaWebhookCallType, SeekaWebhookPayload,
8
- throwOnInvalidWebhookSignature
9
- } from '@seeka-labs/sdk-apps-server';
10
-
11
- import { queueNames, triggerBackgroundJob } from '../lib/jobs';
12
- // START: component:browser
13
- import { getSeekaBrowserPlugin } from '../lib/browser'
14
- // END: component:browser
15
-
16
- import { webhookLogger } from '../lib/logging';
17
- import { startServices } from '../lib/services';
18
- import {
19
- createOrUpdateInstallation, deleteInstallation, SampleAppInstallSettings, SeekaAppInstallState, tryGetInstallation
20
- } from '../lib/state/seeka/installations';
21
-
22
- import type { Logger } from 'winston';
23
- import { MyQueueItem } from './queueExample';
24
- app.http('seekaAppWebhook', {
25
- methods: ['POST'],
26
- authLevel: 'anonymous',
27
- route: 'webhook/seeka/app',
28
- handler: seekaAppWebhook
29
- });
30
-
31
- export async function seekaAppWebhook(req: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
32
- const bodyStr = (await req.text()) as string;
33
- if (!bodyStr) {
34
- return {
35
- status: 400,
36
- jsonBody: { error: "Body missing. Ensure body is present and either specify the Content-Length request header OR set Transfer-Encoding request header to 'chunked'" }
37
- }
38
- }
39
- const body = JSON.parse(bodyStr) as SeekaWebhookPayload;
40
-
41
- const logger = webhookLogger(body, context);
42
- logger.profile('http.seeka.webhook.app')
43
- logger.verbose('Received webhook from Seeka', { body });
44
-
45
- // Handle probe
46
- if (body.type === SeekaWebhookCallType.Probe) {
47
- return {
48
- status: 204
49
- }
50
- }
51
-
52
- // Validate webhook
53
- try {
54
- throwOnInvalidWebhookSignature(process.env.SEEKA_APP_SECRET as string, req.headers, bodyStr);
55
- logger.debug('Webhook signature validated', { body });
56
- }
57
- catch {
58
- logger.warn('Webhook signature invalid', { body });
59
- return {
60
- status: 401,
61
- jsonBody: { error: "Webhook call invalid" }
62
- }
63
- }
64
-
65
- if (body.isTest) {
66
- // This is a test webhook call
67
- return {
68
- status: 204
69
- }
70
- }
71
-
72
- await startServices(logger);
73
-
74
- // Check if the webhook is for an app we have installed
75
- let installation: SeekaAppInstallState | null = null;
76
- if (body.type != SeekaWebhookCallType.AppInstalled) {
77
- installation = await tryGetInstallation((body as SeekaAppInstalledWebhookPayload).context?.applicationInstallId as string, false, logger);
78
- if (installation == null) {
79
- logger.warn('Webhook call cannot be processed as the installation ID is not known by this app', { body });
80
-
81
- return {
82
- status: 422,
83
- jsonBody: { error: "App not installed" }
84
- }
85
- }
86
- }
87
-
88
- // Do something
89
- let errorMessage: string | null = null;
90
- try {
91
- switch (body.type) {
92
- case SeekaWebhookCallType.AppInstalled:
93
- {
94
- errorMessage = await onInstallation(body as SeekaAppInstalledWebhookPayload, logger);
95
- break;
96
- }
97
- case SeekaWebhookCallType.AppInstallSettingsUpdated:
98
- {
99
- errorMessage = await onInstallationSettingsUpdate(body as SeekaAppInstallSettingsUpdatedWebhookPayload, logger);
100
- break;
101
- }
102
- case SeekaWebhookCallType.AppUninstalled:
103
- {
104
- if (!body.isTest) {
105
- const payload = body as SeekaAppUninstalledWebhookPayload;
106
- await deleteInstallation(payload.context?.applicationInstallId as string, logger)
107
- }
108
- break;
109
- }
110
- case SeekaWebhookCallType.ActivityAccepted:
111
- {
112
- const payload = body as SeekaActivityAcceptedWebhookPayload;
113
- await handleSeekaActivity(payload, logger);
114
-
115
- break;
116
- }
117
- case SeekaWebhookCallType.IdentityChanged:
118
- {
119
- const payload = body as SeekaIdentityChangedWebhookPayload;
120
-
121
- break;
122
- }
123
- // START: component:browser
124
- case SeekaWebhookCallType.BrowserSdkPlugin: {
125
- const plugin = await getSeekaBrowserPlugin(installation as SeekaAppInstallState, logger);
126
-
127
- logger.profile('http.seeka.webhook.app')
128
- return {
129
- status: 200,
130
- body: JSON.stringify(plugin),
131
- headers: {
132
- 'Content-Type': 'application/json'
133
- }
134
- }
135
- }
136
- // END: component:browser
137
- }
138
- }
139
- catch (err) {
140
- logger.error('Failed to handle webhook', { ex: winston.exceptions.getAllInfo(err) });
141
- return {
142
- status: 500,
143
- jsonBody: { error: "Request failed" }
144
- }
145
- }
146
- finally {
147
- logger.profile('http.seeka.webhook.app')
148
- logger.verbose('Seeka webhook handled');
149
- }
150
-
151
- if (errorMessage) {
152
- logger.warn('Webhook call failed', { errorMessage });
153
- return {
154
- status: 400,
155
- jsonBody: { error: { message: errorMessage } }
156
- }
157
- }
158
-
159
- return {
160
- status: 204
161
- }
162
- }
163
-
164
- const validateInstallationSettings = async (installSettings: SampleAppInstallSettings, logger: Logger): Promise<string | null> => {
165
- // Returning an error message string here will block the installation request or settings update request by the user installing the app
166
-
167
-
168
- return null;
169
- }
170
-
171
- const onInstallation = async (payload: SeekaAppInstalledWebhookPayload, logger: Logger): Promise<string | null> => {
172
- if (payload.isTest) return null;
173
-
174
- const errorMessage = await validateInstallationSettings(payload.content?.installationSettings || {}, logger);
175
- if (errorMessage) return errorMessage;
176
-
177
- const installation = await createOrUpdateInstallation({
178
- ...payload.context,
179
- installationState: {
180
- grantedPermissions: payload.content?.grantedPermissions || []
181
- },
182
- applicationInstallId: payload.context?.applicationInstallId as string,
183
- organisationBrandId: payload.context?.organisationBrandId as string,
184
- organisationId: payload.context?.organisationId as string,
185
- installedAt: new Date().toISOString(),
186
- installationSettings: payload.content?.installationSettings || {}
187
- }, logger)
188
-
189
- try {
190
- await triggerBackgroundJob(queueNames.queueItemExampleQueueName, {
191
- ...payload.context,
192
- causationId: payload.causationId,
193
- correlationId: payload.requestId
194
- }, logger)
195
- }
196
- catch (err) {
197
- await deleteInstallation(installation.applicationInstallId, logger)
198
- return 'Failed to complete install';
199
- }
200
-
201
- return null;
202
- }
203
-
204
- const onInstallationSettingsUpdate = async (payload: SeekaAppInstallSettingsUpdatedWebhookPayload, logger: Logger): Promise<string | null> => {
205
- if (payload.isTest) return null;
206
-
207
- const errorMessage = await validateInstallationSettings(payload.content?.installationSettings || {}, logger);
208
- if (errorMessage) return errorMessage;
209
-
210
- const existingInstallation = await tryGetInstallation(payload.context?.applicationInstallId as string, true, logger) as SeekaAppInstallState;
211
- const installation = await createOrUpdateInstallation({
212
- ...existingInstallation,
213
- installationState: {
214
- ...existingInstallation.installationState,
215
- grantedPermissions: payload.content?.grantedPermissions || []
216
- },
217
- installationSettings: payload.content?.installationSettings || {},
218
- }, logger)
219
-
220
- await triggerBackgroundJob(queueNames.queueItemExampleQueueName, {
221
- ...payload.context,
222
- causationId: payload.causationId,
223
- correlationId: payload.requestId
224
- }, logger)
225
-
226
- return null;
227
- }
228
-
229
- const handleSeekaActivity = async (activity: SeekaActivityAcceptedWebhookPayload, logger: Logger) => {
230
- // Will be handled by queueExample
231
- await triggerBackgroundJob(queueNames.queueItemExampleQueueName, {
232
- ...activity.context,
233
- causationId: activity.causationId,
234
- correlationId: activity.requestId,
235
- items: [activity]
236
- } as MyQueueItem, logger)
1
+ import winston from 'winston';
2
+
3
+ import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';
4
+ import {
5
+ SeekaActivityAcceptedWebhookPayload, SeekaAppInstalledWebhookPayload,
6
+ SeekaAppInstallSettingsUpdatedWebhookPayload, SeekaAppUninstalledWebhookPayload,
7
+ SeekaIdentityChangedWebhookPayload, SeekaWebhookCallType, SeekaWebhookPayload,
8
+ throwOnInvalidWebhookSignature
9
+ } from '@seeka-labs/sdk-apps-server';
10
+
11
+ import type { Headers as UndiciHeaders } from 'undici';
12
+ import { getSeekaBrowserPlugin } from '../lib/browser';
13
+ import { queueNames, triggerBackgroundJob } from '../lib/jobs';
14
+
15
+ import { webhookLogger } from '../lib/logging';
16
+ import { startServices } from '../lib/services';
17
+ import {
18
+ createOrUpdateInstallation, deleteInstallation, SampleAppInstallSettings, SeekaAppInstallState, tryGetInstallation
19
+ } from '../lib/state/seeka/installations';
20
+
21
+ import type { Logger } from 'winston';
22
+ import { MyQueueItem } from './queueExample';
23
+ app.http('seekaAppWebhook', {
24
+ methods: ['POST'],
25
+ authLevel: 'anonymous',
26
+ route: 'webhook/seeka/app',
27
+ handler: seekaAppWebhook
28
+ });
29
+
30
+ export async function seekaAppWebhook(req: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
31
+ const bodyStr = (await req.text()) as string;
32
+ if (!bodyStr) {
33
+ return {
34
+ status: 400,
35
+ jsonBody: { error: "Body missing. Ensure body is present and either specify the Content-Length request header OR set Transfer-Encoding request header to 'chunked'" }
36
+ }
37
+ }
38
+ const body = JSON.parse(bodyStr) as SeekaWebhookPayload;
39
+
40
+ const logger = webhookLogger(body, context);
41
+ logger.profile('http.seeka.webhook.app')
42
+ logger.verbose('Received webhook from Seeka', { body });
43
+
44
+ // Handle probe
45
+ if (body.type === SeekaWebhookCallType.Probe) {
46
+ return {
47
+ status: 204
48
+ }
49
+ }
50
+
51
+ // Validate webhook
52
+ try {
53
+ throwOnInvalidWebhookSignature(process.env.SEEKA_APP_SECRET as string, req.headers as UndiciHeaders, bodyStr);
54
+ logger.debug('Webhook signature validated', { body });
55
+ }
56
+ catch {
57
+ logger.warn('Webhook signature invalid', { body });
58
+ return {
59
+ status: 401,
60
+ jsonBody: { error: "Webhook call invalid" }
61
+ }
62
+ }
63
+
64
+ if (body.isTest) {
65
+ // This is a test webhook call
66
+ return {
67
+ status: 204
68
+ }
69
+ }
70
+
71
+ await startServices(logger);
72
+
73
+ // Check if the webhook is for an app we have installed
74
+ let installation: SeekaAppInstallState | null = null;
75
+ if (body.type != SeekaWebhookCallType.AppInstalled) {
76
+ installation = await tryGetInstallation((body as SeekaAppInstalledWebhookPayload).context?.applicationInstallId as string, false, logger);
77
+ if (installation == null) {
78
+ logger.warn('Webhook call cannot be processed as the installation ID is not known by this app', { body });
79
+
80
+ return {
81
+ status: 422,
82
+ jsonBody: { error: "App not installed" }
83
+ }
84
+ }
85
+ }
86
+
87
+ // Do something
88
+ let errorMessage: string | null = null;
89
+ try {
90
+ switch (body.type) {
91
+ case SeekaWebhookCallType.AppInstalled:
92
+ {
93
+ errorMessage = await onInstallation(body as SeekaAppInstalledWebhookPayload, logger);
94
+ break;
95
+ }
96
+ case SeekaWebhookCallType.AppInstallSettingsUpdated:
97
+ {
98
+ errorMessage = await onInstallationSettingsUpdate(body as SeekaAppInstallSettingsUpdatedWebhookPayload, logger);
99
+ break;
100
+ }
101
+ case SeekaWebhookCallType.AppUninstalled:
102
+ {
103
+ if (!body.isTest) {
104
+ const payload = body as SeekaAppUninstalledWebhookPayload;
105
+ await deleteInstallation(payload.context?.applicationInstallId as string, logger)
106
+ }
107
+ break;
108
+ }
109
+ case SeekaWebhookCallType.ActivityAccepted:
110
+ {
111
+ const payload = body as SeekaActivityAcceptedWebhookPayload;
112
+ await handleSeekaActivity(payload, logger);
113
+
114
+ break;
115
+ }
116
+ case SeekaWebhookCallType.IdentityChanged:
117
+ {
118
+ const payload = body as SeekaIdentityChangedWebhookPayload;
119
+
120
+ break;
121
+ }
122
+ // START: component:browser
123
+ case SeekaWebhookCallType.BrowserSdkPlugin: {
124
+ const plugin = await getSeekaBrowserPlugin(installation as SeekaAppInstallState, logger);
125
+
126
+ logger.profile('http.seeka.webhook.app')
127
+ return {
128
+ status: 200,
129
+ body: JSON.stringify(plugin),
130
+ headers: {
131
+ 'Content-Type': 'application/json'
132
+ }
133
+ }
134
+ }
135
+ // END: component:browser
136
+ }
137
+ }
138
+ catch (err) {
139
+ logger.error('Failed to handle webhook', { ex: winston.exceptions.getAllInfo(err) });
140
+ return {
141
+ status: 500,
142
+ jsonBody: { error: "Request failed" }
143
+ }
144
+ }
145
+ finally {
146
+ logger.profile('http.seeka.webhook.app')
147
+ logger.verbose('Seeka webhook handled');
148
+ }
149
+
150
+ if (errorMessage) {
151
+ logger.warn('Webhook call failed', { errorMessage });
152
+ return {
153
+ status: 400,
154
+ jsonBody: { error: { message: errorMessage } }
155
+ }
156
+ }
157
+
158
+ return {
159
+ status: 204
160
+ }
161
+ }
162
+
163
+ const validateInstallationSettings = async (installSettings: SampleAppInstallSettings, logger: Logger): Promise<string | null> => {
164
+ // Returning an error message string here will block the installation request or settings update request by the user installing the app
165
+
166
+
167
+ return null;
168
+ }
169
+
170
+ const onInstallation = async (payload: SeekaAppInstalledWebhookPayload, logger: Logger): Promise<string | null> => {
171
+ if (payload.isTest) return null;
172
+
173
+ const errorMessage = await validateInstallationSettings(payload.content?.installationSettings || {}, logger);
174
+ if (errorMessage) return errorMessage;
175
+
176
+ const installation = await createOrUpdateInstallation({
177
+ ...payload.context,
178
+ installationState: {
179
+ grantedPermissions: payload.content?.grantedPermissions || []
180
+ },
181
+ applicationInstallId: payload.context?.applicationInstallId as string,
182
+ organisationBrandId: payload.context?.organisationBrandId as string,
183
+ organisationId: payload.context?.organisationId as string,
184
+ installedAt: new Date().toISOString(),
185
+ installationSettings: payload.content?.installationSettings || {}
186
+ }, logger)
187
+
188
+ try {
189
+ await triggerBackgroundJob(queueNames.queueItemExampleQueueName, {
190
+ ...payload.context,
191
+ causationId: payload.causationId,
192
+ correlationId: payload.requestId
193
+ }, logger)
194
+ }
195
+ catch (err) {
196
+ await deleteInstallation(installation.applicationInstallId, logger)
197
+ return 'Failed to complete install';
198
+ }
199
+
200
+ return null;
201
+ }
202
+
203
+ const onInstallationSettingsUpdate = async (payload: SeekaAppInstallSettingsUpdatedWebhookPayload, logger: Logger): Promise<string | null> => {
204
+ if (payload.isTest) return null;
205
+
206
+ const errorMessage = await validateInstallationSettings(payload.content?.installationSettings || {}, logger);
207
+ if (errorMessage) return errorMessage;
208
+
209
+ const existingInstallation = await tryGetInstallation(payload.context?.applicationInstallId as string, true, logger) as SeekaAppInstallState;
210
+ const installation = await createOrUpdateInstallation({
211
+ ...existingInstallation,
212
+ installationState: {
213
+ ...existingInstallation.installationState,
214
+ grantedPermissions: payload.content?.grantedPermissions || []
215
+ },
216
+ installationSettings: payload.content?.installationSettings || {},
217
+ }, logger)
218
+
219
+ await triggerBackgroundJob(queueNames.queueItemExampleQueueName, {
220
+ ...payload.context,
221
+ causationId: payload.causationId,
222
+ correlationId: payload.requestId
223
+ }, logger)
224
+
225
+ return null;
226
+ }
227
+
228
+ const handleSeekaActivity = async (activity: SeekaActivityAcceptedWebhookPayload, logger: Logger) => {
229
+ // Will be handled by queueExample
230
+ await triggerBackgroundJob(queueNames.queueItemExampleQueueName, {
231
+ ...activity.context,
232
+ causationId: activity.causationId,
233
+ correlationId: activity.requestId,
234
+ items: [activity]
235
+ } as MyQueueItem, logger)
237
236
  }
@@ -1,55 +1,55 @@
1
- import winston, { Logger } from 'winston';
2
- import fs from 'fs';
3
- import path from 'path';
4
- import util from 'util';
5
- import { SeekaBrowserSdkPluginWebhookResponse } from '@seeka-labs/sdk-apps-server'
6
- import {
7
- SeekaAppInstallState
8
- } from '../state/seeka/installations';
9
- import type { ISampleAppBrowserSdkPluginConfig } from './models';
10
-
11
- const fileExistsAsync = util.promisify(fs.exists);
12
- const readFileAsync = util.promisify(fs.readFile);
13
-
14
- export async function getSeekaBrowserPlugin(installation: SeekaAppInstallState, logger: Logger): Promise<SeekaBrowserSdkPluginWebhookResponse> {
15
- logger.profile('http.seeka.browser.plugin')
16
-
17
- let content: string | undefined;
18
- let init: string | undefined;
19
-
20
- try {
21
- logger.verbose('Handling request for browser plugin content');
22
- const browserPluginPath = path.resolve('./dist/src/browser/seeka-app-example-name.min.js');
23
- if (await fileExistsAsync(browserPluginPath)) {
24
- // Content of the script. This should not change per installation it should be the same for all installations
25
- content = await readFileAsync(browserPluginPath, 'utf8');
26
-
27
- // Configuration for the plugin. This can be different per installation.
28
- // Configuration is sent to the browser so NO SENSITIVE CONFIG / SERVER SECRETS SHOULD BE SPECIFIED HERE.
29
- const pluginConfig = {
30
- myAppInstallSetting1: installation.installationSettings.myAppInstallSetting1,
31
- myAppInstallSetting2: installation.installationSettings.myAppInstallSetting2,
32
- appId: process.env.SEEKA_APP_ID,
33
- appInstallId: installation.applicationInstallId,
34
- appUrl: process.env.SELF_HOST_BASEURL
35
- } as ISampleAppBrowserSdkPluginConfig;
36
- init = `SampleAppConvergeSdkPlugin(${JSON.stringify(pluginConfig)})`;
37
- }
38
- else {
39
- logger.error('Browser plugin content not found', { path: browserPluginPath });
40
- }
41
- }
42
- catch (err) {
43
- logger.error('Failed to handle request for browser plugin content', { ex: winston.exceptions.getAllInfo(err) });
44
- }
45
- finally {
46
- logger.profile('http.seeka.browser.plugin')
47
- logger.verbose('Request for browser plugin content handled');
48
- }
49
-
50
- if (!content || !init) {
51
- throw new Error('Failed to handle request for browser plugin content')
52
- }
53
-
54
- return { content, init: init }
1
+ import { SeekaBrowserSdkPluginWebhookResponse } from '@seeka-labs/sdk-apps-server';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import util from 'util';
5
+ import winston, { Logger } from 'winston';
6
+ import type { ISampleAppBrowserSdkPluginConfig } from '../models';
7
+ import {
8
+ SeekaAppInstallState
9
+ } from '../state/seeka/installations';
10
+
11
+ const fileExistsAsync = util.promisify(fs.exists);
12
+ const readFileAsync = util.promisify(fs.readFile);
13
+
14
+ export async function getSeekaBrowserPlugin(installation: SeekaAppInstallState, logger: Logger): Promise<SeekaBrowserSdkPluginWebhookResponse> {
15
+ logger.profile('http.seeka.browser.plugin')
16
+
17
+ let content: string | undefined;
18
+ let init: string | undefined;
19
+
20
+ try {
21
+ logger.verbose('Handling request for browser plugin content');
22
+ const browserPluginPath = path.resolve('./dist/src/browser/seeka-app-example-name.min.js');
23
+ if (await fileExistsAsync(browserPluginPath)) {
24
+ // Content of the script. This should not change per installation it should be the same for all installations
25
+ content = await readFileAsync(browserPluginPath, 'utf8');
26
+
27
+ // Configuration for the plugin. This can be different per installation.
28
+ // Configuration is sent to the browser so NO SENSITIVE CONFIG / SERVER SECRETS SHOULD BE SPECIFIED HERE.
29
+ const pluginConfig = {
30
+ myAppInstallSetting1: installation.installationSettings.myAppInstallSetting1,
31
+ myAppInstallSetting2: installation.installationSettings.myAppInstallSetting2,
32
+ appId: process.env.SEEKA_APP_ID,
33
+ appInstallId: installation.applicationInstallId,
34
+ appUrl: process.env.SELF_HOST_BASEURL
35
+ } as ISampleAppBrowserSdkPluginConfig;
36
+ init = `SampleAppConvergeSdkPlugin(${JSON.stringify(pluginConfig)})`;
37
+ }
38
+ else {
39
+ logger.error('Browser plugin content not found', { path: browserPluginPath });
40
+ }
41
+ }
42
+ catch (err) {
43
+ logger.error('Failed to handle request for browser plugin content', { ex: winston.exceptions.getAllInfo(err) });
44
+ }
45
+ finally {
46
+ logger.profile('http.seeka.browser.plugin')
47
+ logger.verbose('Request for browser plugin content handled');
48
+ }
49
+
50
+ if (!content || !init) {
51
+ throw new Error('Failed to handle request for browser plugin content')
52
+ }
53
+
54
+ return { content, init: init }
55
55
  }
@@ -1,6 +1,6 @@
1
- import type { Logger } from 'winston';
2
1
  import { QueueClient } from '@azure/storage-queue';
3
2
  import { isArray } from 'lodash';
3
+ import type { Logger } from 'winston';
4
4
  import winston from 'winston';
5
5
 
6
6
  export interface BackgroundJobRequestContext {