@seeka-labs/cli-apps 1.1.18 → 1.1.23

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 (60) hide show
  1. package/LICENSE +19 -19
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/init-templates/aws-lambda/.example.gitignore +48 -48
  5. package/dist/init-templates/aws-lambda/.nvmrc +1 -0
  6. package/dist/init-templates/aws-lambda/README.md +76 -76
  7. package/dist/init-templates/aws-lambda/jest.config.js +4 -4
  8. package/dist/init-templates/aws-lambda/package.json +54 -54
  9. package/dist/init-templates/aws-lambda/src/index.test.ts +6 -6
  10. package/dist/init-templates/aws-lambda/src/lib/logging/index.ts +87 -87
  11. package/dist/init-templates/aws-lambda/src/lib/state/redis/index.ts +64 -64
  12. package/dist/init-templates/aws-lambda/src/lib/state/seeka/installations.ts +66 -66
  13. package/dist/init-templates/aws-lambda/src/routes/seekaAppWebhook.ts +193 -193
  14. package/dist/init-templates/azure-function/.example.gitignore +47 -47
  15. package/dist/init-templates/azure-function/.gitlab-ci.yml +24 -24
  16. package/dist/init-templates/azure-function/.nvmrc +1 -0
  17. package/dist/init-templates/azure-function/README.md +107 -107
  18. package/dist/init-templates/azure-function/jest.config.js +4 -4
  19. package/dist/init-templates/azure-function/package.json +48 -48
  20. package/dist/init-templates/azure-function/scripts/dev-queue-setup.js +29 -29
  21. package/dist/init-templates/azure-function/src/functions/healthCheck.ts +13 -13
  22. package/dist/init-templates/azure-function/src/functions/pollingExample.ts +39 -39
  23. package/dist/init-templates/azure-function/src/functions/queueExample.ts +66 -66
  24. package/dist/init-templates/azure-function/src/functions/seekaAppWebhook.ts +236 -236
  25. package/dist/init-templates/azure-function/src/index.test.ts +6 -6
  26. package/dist/init-templates/azure-function/src/lib/browser/index.ts +54 -54
  27. package/dist/init-templates/azure-function/src/lib/browser/models/index.ts +6 -6
  28. package/dist/init-templates/azure-function/src/lib/jobs/index.ts +95 -95
  29. package/dist/init-templates/azure-function/src/lib/logging/index.ts +92 -92
  30. package/dist/init-templates/azure-function/src/lib/state/redis/index.ts +64 -64
  31. package/dist/init-templates/azure-function/src/lib/state/seeka/installations.ts +66 -66
  32. package/dist/init-templates/azure-function/tsconfig.json +1 -1
  33. package/dist/init-templates/browser/.editorconfig +14 -14
  34. package/dist/init-templates/browser/.eslintrc.cjs +1 -1
  35. package/dist/init-templates/browser/.yarnrc +1 -1
  36. package/dist/init-templates/browser/jest.config.js +11 -11
  37. package/dist/init-templates/browser/package.json +11 -12
  38. package/dist/init-templates/browser/scripts/esbuild/build-browser-plugin.mjs +110 -110
  39. package/dist/init-templates/browser/scripts/esbuild/plugins/importAsGlobals.mjs +38 -38
  40. package/dist/init-templates/browser/src/browser.ts +12 -12
  41. package/dist/init-templates/browser/src/plugin/index.test.ts +6 -6
  42. package/dist/init-templates/browser/src/plugin/index.ts +49 -49
  43. package/dist/init-templates/browser/tsconfig.json +34 -34
  44. package/dist/init-templates/netlify-function/.env.example +17 -17
  45. package/dist/init-templates/netlify-function/.example.gitignore +36 -36
  46. package/dist/init-templates/netlify-function/.nvmrc +1 -0
  47. package/dist/init-templates/netlify-function/.vscode/launch.json +44 -44
  48. package/dist/init-templates/netlify-function/README.md +61 -61
  49. package/dist/init-templates/netlify-function/jest.config.js +4 -4
  50. package/dist/init-templates/netlify-function/netlify.toml +6 -6
  51. package/dist/init-templates/netlify-function/package.json +1 -1
  52. package/dist/init-templates/netlify-function/src/api/example-job-background/index.ts +51 -51
  53. package/dist/init-templates/netlify-function/src/api/polling-example-job-scheduled/index.ts +45 -45
  54. package/dist/init-templates/netlify-function/src/api/seeka-app-webhook/index.ts +216 -216
  55. package/dist/init-templates/netlify-function/src/index.test.ts +6 -6
  56. package/dist/init-templates/netlify-function/src/lib/jobs/index.ts +67 -67
  57. package/dist/init-templates/netlify-function/src/lib/logging/index.ts +90 -90
  58. package/dist/init-templates/netlify-function/src/lib/state/redis/index.ts +64 -64
  59. package/dist/init-templates/netlify-function/src/lib/state/seeka/installations.ts +66 -66
  60. package/package.json +5 -5
@@ -1,237 +1,237 @@
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
+ 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)
237
237
  }
@@ -1,7 +1,7 @@
1
- import { describe, expect, test } from '@jest/globals';
2
-
3
- describe('test example module', () => {
4
- test('should be false', () => {
5
- expect(false).toBeFalsy();
6
- });
1
+ import { describe, expect, test } from '@jest/globals';
2
+
3
+ describe('test example module', () => {
4
+ test('should be false', () => {
5
+ expect(false).toBeFalsy();
6
+ });
7
7
  });
@@ -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 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 }
55
55
  }
@@ -1,7 +1,7 @@
1
- export interface ISampleAppBrowserSdkPluginConfig {
2
- myAppInstallSetting1: string | number | undefined;
3
- myAppInstallSetting2: string | number | undefined;
4
- appId: string
5
- appInstallId: string
6
- appUrl: string
1
+ export interface ISampleAppBrowserSdkPluginConfig {
2
+ myAppInstallSetting1: string | number | undefined;
3
+ myAppInstallSetting2: string | number | undefined;
4
+ appId: string
5
+ appInstallId: string
6
+ appUrl: string
7
7
  }