@seeka-labs/cli-apps 1.1.38 → 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,91 +0,0 @@
1
- import * as winston from 'winston';
2
-
3
- import { BackgroundJobRequestContext } from '@/lib/jobs';
4
- import { SeqTransport } from '@datalust/winston-seq';
5
- import { Context } from '@netlify/functions';
6
-
7
- import packageJson from '../../../package.json';
8
-
9
- import type {
10
- SeekaWebhookPayload, SeekaWebhookPayloadOfSeekaAppWebhookContext
11
- } from '@seeka-labs/sdk-apps-server';
12
-
13
- const loggerTransports: winston.transport[] = [
14
- new winston.transports.Console({
15
- level: process.env.LOGGING_LEVEL,
16
- format: winston.format.combine(
17
- winston.format.cli(),
18
- winston.format.errors({ stack: true }),
19
- winston.format.splat(),
20
- winston.format.cli()
21
- ),
22
- handleExceptions: true,
23
- handleRejections: true,
24
- }),
25
- ]
26
- if (process.env.LOGGING_SEQ_SERVERURL) {
27
- loggerTransports.push(
28
- new SeqTransport({
29
- level: process.env.LOGGING_LEVEL,
30
- serverUrl: process.env.LOGGING_SEQ_SERVERURL,
31
- apiKey: process.env.LOGGING_SEQ_APIKEY,
32
- onError: ((e: any) => { console.error('Failed to configure Seq logging transport', e) }),
33
- format: winston.format.combine(
34
- winston.format.errors({ stack: true }),
35
- winston.format.json(),
36
- ),
37
- handleExceptions: true,
38
- handleRejections: true,
39
- })
40
- )
41
- }
42
-
43
- export const logger = winston.createLogger({
44
- level: process.env.LOGGING_LEVEL,
45
- defaultMeta: {
46
- seekaAppId: process.env.SEEKA_APP_ID,
47
- seekaAppPackageName: packageJson.name,
48
- seekaAppPackageVersion: packageJson.version,
49
- Hosting_Provider: process.env.NETLIFY === 'true' ? 'netlify-aws' : undefined,
50
- Release_Version: process.env.COMMIT_REF ? `sha-${process.env.COMMIT_REF}` : undefined,
51
- Hosting_Region: process.env.AWS_REGION || undefined
52
- },
53
- transports: loggerTransports,
54
- exitOnError: false,
55
- });
56
-
57
- export const childLogger = (meta: Object) => logger.child(meta);
58
-
59
- export const webhookLogger = (payload: SeekaWebhookPayload, functionContext: Context) => {
60
- const meta: any = {
61
- seekaWebhookType: payload.type,
62
- seekaWebhookIsTest: payload.isTest,
63
- seekaWebhookRequestId: payload.requestId,
64
- seekaWebhookCausationId: payload.causationId,
65
- netlifyRequestId: functionContext.requestId,
66
- netlifyDeployId: functionContext.deploy.id
67
- }
68
-
69
- const context = (payload as SeekaWebhookPayloadOfSeekaAppWebhookContext).context;
70
- if (context) {
71
- meta.seekaAppInstallId = context.applicationInstallId;
72
- meta.seekaAppInstallOrganisationBrandId = context.organisationBrandId;
73
- meta.seekaAppInstallOrganisationId = context.organisationId;
74
- }
75
-
76
- return childLogger(meta)
77
- }
78
-
79
- export const backgroundJobLogger = (jobName: string, jobContext: BackgroundJobRequestContext | undefined, functionContext: Context) => {
80
- const meta: any = {
81
- jobContext,
82
- jobName,
83
- netlifyRequestId: functionContext.requestId,
84
- netlifyDeployId: functionContext.deploy.id,
85
- seekaAppInstallId: jobContext?.applicationInstallId,
86
- seekaAppInstallOrganisationBrandId: jobContext?.organisationBrandId,
87
- seekaAppInstallOrganisationId: jobContext?.organisationId
88
- }
89
-
90
- return childLogger(meta)
91
- }
@@ -1,41 +0,0 @@
1
- import winston, { Logger } from 'winston';
2
-
3
- import { connect, disconnect, isConnected } from '@/lib/state/redis';
4
-
5
- export const startServices = async (logger: Logger) => {
6
- logger.debug(`Trying to connect to Redis - ${process.env.REDIS_CONNECTION_HOST}`)
7
- try {
8
- if (isConnected()) {
9
- logger.verbose(`Redis already connected - ${process.env.REDIS_CONNECTION_HOST}`)
10
- }
11
- else {
12
- logger.profile('service.redis.connect')
13
- await connect();
14
- logger.profile('service.redis.connect')
15
- logger.debug(`Redis connected - ${process.env.REDIS_CONNECTION_HOST}`)
16
- }
17
- }
18
- catch (err) {
19
- logger.error(`Failed to connect to Redis - ${process.env.REDIS_CONNECTION_HOST}`, { ex: winston.exceptions.getAllInfo(err) })
20
- throw err;
21
- }
22
- }
23
-
24
- export const stopServices = async (logger: Logger) => {
25
- logger.debug(`Trying to disconnect from Redis - ${process.env.REDIS_CONNECTION_HOST}`)
26
- try {
27
- if (isConnected() === false) {
28
- logger.verbose(`Redis already disconnected - ${process.env.REDIS_CONNECTION_HOST}`)
29
- }
30
- else {
31
- logger.profile('service.redis.disconnect')
32
- await disconnect();
33
- logger.profile('service.redis.disconnect')
34
- logger.verbose(`Redis disconnected - ${process.env.REDIS_CONNECTION_HOST}`)
35
- }
36
- }
37
- catch (err) {
38
- logger.error(`Failed to disconnect from Redis - ${process.env.REDIS_CONNECTION_HOST}`, { ex: winston.exceptions.getAllInfo(err) })
39
- throw err;
40
- }
41
- }
@@ -1,65 +0,0 @@
1
- import { createClient } from 'redis';
2
-
3
- import { logger } from '@/lib/logging';
4
- import winston from 'winston';
5
-
6
- const redisProtocol = process.env.REDIS_CONNECTION_TLS === 'true' ? 'rediss://' : 'redis://';
7
- const redisConn = `${redisProtocol}${process.env.REDIS_CONNECTION_USER}:${process.env.REDIS_CONNECTION_PASSWORD}@${process.env.REDIS_CONNECTION_HOST}:${process.env.REDIS_CONNECTION_PORT}`;
8
-
9
- const redisClient = createClient({
10
- url: redisConn
11
- })
12
- .on('error', (err: any) => logger.error('Redis Client ', { ex: winston.exceptions.getAllInfo(err) }));
13
-
14
- export const connect = async () => {
15
- await redisClient.connect();
16
- }
17
-
18
- export const isConnected = () => {
19
- return redisClient.isOpen;
20
- }
21
-
22
- export const disconnect = async () => {
23
- await redisClient.disconnect();
24
- }
25
-
26
- const getKeyPrefix = (stateType: string) => `seeka:app:${process.env.SEEKA_APP_ID}:${stateType}`
27
- const getKey = (stateType: string, key: string) => `${getKeyPrefix(stateType)}:${key}`
28
-
29
- export async function getOrCreate<TState>(stateType: string, key: string, toCreate: TState): Promise<TState> {
30
- const fullKey = getKey(stateType, key);
31
- const existingStr = await redisClient.get(fullKey);
32
- if (existingStr) return JSON.parse(existingStr);
33
-
34
- await redisClient.set(fullKey, JSON.stringify(toCreate));
35
-
36
- return toCreate;
37
- }
38
-
39
- export async function tryGet<TState>(stateType: string, key: string): Promise<TState | null> {
40
- const fullKey = getKey(stateType, key);
41
- const existingStr = await redisClient.get(fullKey);
42
- if (existingStr) return JSON.parse(existingStr);
43
-
44
- return null;
45
- }
46
-
47
- export async function getList<TState>(stateType: string): Promise<TState[]> {
48
- const prefix = getKeyPrefix(stateType);
49
- const allKeys = await redisClient.keys(`${prefix}:*`);
50
- const listStr = await redisClient.mGet(allKeys);
51
-
52
- if (listStr) return listStr.filter(e => Boolean(e)).map(e => JSON.parse(e as string));
53
-
54
- return [];
55
- }
56
-
57
- export async function set<TState>(stateType: string, key: string, toCreate: TState): Promise<void> {
58
- const fullKey = getKey(stateType, key);
59
- await redisClient.set(fullKey, JSON.stringify(toCreate));
60
- }
61
-
62
- export async function remove(stateType: string, key: string): Promise<void> {
63
- const fullKey = getKey(stateType, key);
64
- await redisClient.del(fullKey);
65
- }
@@ -1,67 +0,0 @@
1
- import type { Logger } from 'winston';
2
-
3
- import { getList, remove, set, tryGet } from '@/lib/state/redis';
4
-
5
- export interface SeekaAppInstallState {
6
- /** ID of the organisation that installed the app */
7
- organisationId: string;
8
- /** ID of the brand that installed the app */
9
- organisationBrandId: string;
10
- /** ID of the installation of the app */
11
- applicationInstallId: string;
12
- // Installation settings provided by the user installing the app
13
- installationSettings: SampleAppInstallSettings;
14
- // State relating to the app and installation of the app
15
- installationState: SampleAppInstallState;
16
-
17
- // When the app was installed
18
- installedAt: string; // new Date().toISOString()
19
- }
20
-
21
- export interface SampleAppInstallState {
22
- stateItem1?: string
23
- stateItem2?: string
24
- grantedPermissions?: string[]
25
- }
26
-
27
- export type SampleAppInstallSettings = { [key: string]: any; } | {
28
- myAppInstallSetting1: string | number | undefined;
29
- myAppInstallSetting2: string | number | undefined;
30
- }
31
-
32
- const stateType = 'install'
33
-
34
- export const tryGetInstallation = async (applicationInstallId: string, throwWhenNotFound: boolean, logger: Logger): Promise<SeekaAppInstallState | null> => {
35
- const installation = await tryGet<SeekaAppInstallState>(stateType, applicationInstallId);
36
- if (installation == null && throwWhenNotFound) {
37
- throw new Error(`Seeka installation ${applicationInstallId} not found`);
38
- }
39
-
40
- return installation;
41
- }
42
-
43
- export const listInstallations = async (logger: Logger): Promise<SeekaAppInstallState[]> => {
44
- const installations = await getList<SeekaAppInstallState>(stateType);
45
-
46
- return installations;
47
- }
48
-
49
-
50
- export const createOrUpdateInstallation = async (state: SeekaAppInstallState, logger: Logger): Promise<SeekaAppInstallState> => {
51
- if (!state.installationState) state.installationState = {};
52
- if (!state.installedAt) state.installedAt = new Date().toISOString();
53
-
54
- const creating = (await tryGetInstallation(state.applicationInstallId, false, logger)) === null;
55
-
56
- await set(stateType, state.applicationInstallId, state);
57
-
58
- logger.info(creating ? 'Created installation state' : 'Updated installation state', { applicationInstallId: state.applicationInstallId, organisationId: state.organisationId, organisationBrandId: state.organisationBrandId });
59
-
60
- return state;
61
- }
62
-
63
- export const deleteInstallation = async (applicationInstallId: string, logger: Logger): Promise<void> => {
64
- await remove(stateType, applicationInstallId);
65
-
66
- logger.info('Deleted installation state', { applicationInstallId });
67
- }
@@ -1,25 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "skipLibCheck": true,
5
- "strict": true,
6
- "noEmit": true,
7
- "esModuleInterop": true,
8
- "module": "ESNext",
9
- "moduleResolution": "Bundler",
10
- "resolveJsonModule": true,
11
- "isolatedModules": true,
12
- "paths": {
13
- "@/*": [
14
- "./src/*"
15
- ]
16
- }
17
- },
18
- "include": [
19
- "**/*.ts",
20
- "**/*.mts",
21
- ],
22
- "exclude": [
23
- "node_modules"
24
- ]
25
- }