@seeka-labs/cli-apps 2.2.6 → 3.2.5
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 +46922 -35
- package/dist/index.js.map +4 -4
- package/dist/init-template/.gitlab-ci.yml +29 -8
- package/dist/init-template/.nvmrc +1 -0
- package/dist/init-template/README.md +18 -3
- package/dist/init-template/app/{server-azure-function/.eslintrc.cjs → .eslintrc.cjs} +2 -0
- package/dist/init-template/app/browser/README.md +1 -1
- package/dist/init-template/app/browser/package.json +22 -24
- package/dist/init-template/app/browser/scripts/esbuild/build-browser-plugin.mjs +14 -6
- package/dist/init-template/app/browser/src/browser.ts +6 -6
- package/dist/init-template/app/browser/src/plugin/index.ts +57 -44
- package/dist/init-template/app/browser/tsconfig.json +1 -2
- package/dist/init-template/app/lib/package.json +46 -0
- package/dist/init-template/app/lib/src/index.ts +4 -0
- package/dist/init-template/app/lib/src/models/index.ts +29 -0
- package/dist/init-template/app/lib/src/validation/index.ts +14 -0
- package/dist/init-template/app/lib/tsconfig.json +22 -0
- package/dist/init-template/app/server-azurefunc/.eslintrc.cjs +4 -0
- package/dist/init-template/app/{server-azure-function → server-azurefunc}/.funcignore +0 -3
- package/dist/init-template/app/{server-azure-function → server-azurefunc}/README.md +3 -3
- package/dist/init-template/app/{server-azure-function → server-azurefunc}/host.json +11 -0
- package/dist/init-template/app/{server-azure-function/local.settings.example.json → server-azurefunc/local.settings.template.json} +18 -10
- package/dist/init-template/app/server-azurefunc/package.json +69 -0
- package/dist/init-template/app/server-azurefunc/scripts/dev-queue-setup.js +18 -0
- package/dist/init-template/app/{server-azure-function → server-azurefunc}/scripts/ngrok.js +4 -1
- package/dist/init-template/app/server-azurefunc/src/app/api/router.ts +14 -0
- package/dist/init-template/app/server-azurefunc/src/app/api/routes/getInstallationSettings.ts +13 -0
- package/dist/init-template/app/server-azurefunc/src/app/api/routes/setInstallationSettings.ts +35 -0
- package/dist/init-template/app/server-azurefunc/src/app/jobs/index.ts +61 -0
- package/dist/init-template/app/server-azurefunc/src/app/logging/index.ts +4 -0
- package/dist/init-template/app/server-azurefunc/src/app/models/index.ts +12 -0
- package/dist/init-template/app/server-azurefunc/src/app/services/activites.ts +8 -0
- package/dist/init-template/app/{server-azure-function → server-azurefunc}/src/functions/healthCheck.ts +7 -1
- package/dist/init-template/app/server-azurefunc/src/functions/seekaAppWebhook.ts +201 -0
- package/dist/init-template/app/server-azurefunc/src/functions/trackActivityQueueHandler.ts +48 -0
- package/dist/init-template/app/server-azurefunc/src/functions/ui.ts +46 -0
- package/dist/init-template/app/{server-azure-function → server-azurefunc}/tsconfig.json +8 -2
- package/dist/init-template/app/ui/README.md +40 -0
- package/dist/init-template/app/ui/index.html +21 -0
- package/dist/init-template/app/ui/package.json +72 -0
- package/dist/init-template/app/ui/public/favicon.ico +0 -0
- package/dist/init-template/app/ui/scripts/copy-output.mjs +30 -0
- package/dist/init-template/app/ui/src/App.tsx +72 -0
- package/dist/init-template/app/ui/src/assets/app-icon.svg +1 -0
- package/dist/init-template/app/ui/src/components/setup/steps/complete/index.tsx +32 -0
- package/dist/init-template/app/ui/src/components/setup/steps/first/index.tsx +27 -0
- package/dist/init-template/app/ui/src/components/setup/steps/index.tsx +22 -0
- package/dist/init-template/app/ui/src/components/setup/steps/second/index.tsx +29 -0
- package/dist/init-template/app/ui/src/index.tsx +45 -0
- package/dist/init-template/app/ui/src/routes/home/index.tsx +21 -0
- package/dist/init-template/app/ui/src/vite-env.d.ts +13 -0
- package/dist/init-template/app/ui/tsconfig.json +35 -0
- package/dist/init-template/app/ui/tsconfig.node.json +10 -0
- package/dist/init-template/app/ui/vite.config.mts +48 -0
- package/dist/init-template/package.json +19 -11
- package/dist/init-template/tsconfig.json +5 -6
- package/package.json +13 -4
- package/README.md +0 -1
- package/dist/init-template/app/browser/jest.config.js +0 -11
- package/dist/init-template/app/browser/src/plugin/index.test.ts +0 -6
- package/dist/init-template/app/server-azure-function/.nvmrc +0 -1
- package/dist/init-template/app/server-azure-function/package.json +0 -51
- package/dist/init-template/app/server-azure-function/src/functions/pollingExample.ts +0 -39
- package/dist/init-template/app/server-azure-function/src/functions/queueExample.ts +0 -67
- package/dist/init-template/app/server-azure-function/src/functions/seekaAppWebhook.ts +0 -236
- package/dist/init-template/app/server-azure-function/src/lib/browser/index.ts +0 -55
- package/dist/init-template/app/server-azure-function/src/lib/jobs/index.ts +0 -96
- package/dist/init-template/app/server-azure-function/src/lib/logging/index.ts +0 -93
- package/dist/init-template/app/server-azure-function/src/lib/models/index.ts +0 -7
- package/dist/init-template/app/server-azure-function/src/lib/services/index.ts +0 -41
- package/dist/init-template/app/server-azure-function/src/lib/state/redis/index.ts +0 -96
- package/dist/init-template/app/server-azure-function/src/lib/state/seeka/installations.ts +0 -65
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import winston, { Logger } from 'winston';
|
|
2
|
-
|
|
3
|
-
import { connect, disconnect, isConnected } from '../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,96 +0,0 @@
|
|
|
1
|
-
import { createClient } from 'redis';
|
|
2
|
-
|
|
3
|
-
import winston from 'winston';
|
|
4
|
-
import { logger } from '../../logging';
|
|
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
|
-
disableClientInfo: true,
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
.on('error', (err) => logger.error('Redis Client ', { ex: winston.exceptions.getAllInfo(err) }));
|
|
15
|
-
|
|
16
|
-
export const connect = async () => {
|
|
17
|
-
await redisClient.connect();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const isConnected = () => {
|
|
21
|
-
return redisClient.isOpen;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const disconnect = async () => {
|
|
25
|
-
await redisClient.destroy();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const getKeyPrefix = (stateType: string) => `seeka:app:${process.env.SEEKA_APP_ID}:${stateType}`
|
|
29
|
-
const getKey = (stateType: string, key: string) => `${getKeyPrefix(stateType)}:${key}`
|
|
30
|
-
|
|
31
|
-
export async function getOrCreate<TState>(stateType: string, key: string, toCreate: TState, mode: 'string' | 'json' = 'string'): Promise<TState> {
|
|
32
|
-
const fullKey = getKey(stateType, key);
|
|
33
|
-
const existingStr = await getString(redisClient, fullKey);
|
|
34
|
-
if (existingStr) return JSON.parse(existingStr);
|
|
35
|
-
|
|
36
|
-
if (mode === 'json') {
|
|
37
|
-
await redisClient.json.set(fullKey, '$', toCreate as never);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
await redisClient.set(fullKey, JSON.stringify(toCreate));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return toCreate;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function tryGet<TState>(stateType: string, key: string, mode: 'string' | 'json' = 'string'): Promise<TState | null> {
|
|
47
|
-
const fullKey = getKey(stateType, key);
|
|
48
|
-
|
|
49
|
-
if (mode === 'json') {
|
|
50
|
-
const existing = await redisClient.json.get(fullKey);
|
|
51
|
-
if (existing) return existing as TState;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
const existingStr = await getString(redisClient, fullKey);
|
|
55
|
-
if (existingStr) return JSON.parse(existingStr);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function getList<TState>(stateType: string): Promise<TState[]> {
|
|
62
|
-
const prefix = getKeyPrefix(stateType);
|
|
63
|
-
const allKeys = await redisClient.keys(`${prefix}:*`);
|
|
64
|
-
const listStr = await redisClient.mGet(allKeys);
|
|
65
|
-
|
|
66
|
-
if (listStr) return listStr.filter(e => Boolean(e)).map(e => JSON.parse(e as string));
|
|
67
|
-
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function set<TState>(stateType: string, key: string, toCreate: TState, mode: 'string' | 'json' = 'string'): Promise<void> {
|
|
72
|
-
const fullKey = getKey(stateType, key);
|
|
73
|
-
|
|
74
|
-
if (mode === 'json') {
|
|
75
|
-
await redisClient.json.set(fullKey, '$', toCreate as never);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
await redisClient.set(fullKey, JSON.stringify(toCreate));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function remove(stateType: string, key: string): Promise<void> {
|
|
83
|
-
const fullKey = getKey(stateType, key);
|
|
84
|
-
await redisClient.del(fullKey);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function getString(redisClient: any, key: string): Promise<string> {
|
|
88
|
-
const result = await redisClient.get(key);
|
|
89
|
-
if (typeof result === 'string') {
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
if (result) {
|
|
93
|
-
return result.toString();
|
|
94
|
-
}
|
|
95
|
-
return '';
|
|
96
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { Logger } from 'winston';
|
|
2
|
-
|
|
3
|
-
import { getList, remove, set, tryGet } from '../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
|
-
grantedPermissions?: string[]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type SampleAppInstallSettings = { [key: string]: any; } | {
|
|
26
|
-
myAppInstallSetting1: string | number | undefined;
|
|
27
|
-
myAppInstallSetting2: string | number | undefined;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const stateType = 'install'
|
|
31
|
-
|
|
32
|
-
export const tryGetInstallation = async (applicationInstallId: string, throwWhenNotFound: boolean, logger: Logger): Promise<SeekaAppInstallState | null> => {
|
|
33
|
-
const installation = await tryGet<SeekaAppInstallState>(stateType, applicationInstallId);
|
|
34
|
-
if (installation == null && throwWhenNotFound) {
|
|
35
|
-
throw new Error(`Seeka installation ${applicationInstallId} not found`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return installation;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const listInstallations = async (logger: Logger): Promise<SeekaAppInstallState[]> => {
|
|
42
|
-
const installations = await getList<SeekaAppInstallState>(stateType);
|
|
43
|
-
|
|
44
|
-
return installations;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export const createOrUpdateInstallation = async (state: SeekaAppInstallState, logger: Logger): Promise<SeekaAppInstallState> => {
|
|
49
|
-
if (!state.installationState) state.installationState = {};
|
|
50
|
-
if (!state.installedAt) state.installedAt = new Date().toISOString();
|
|
51
|
-
|
|
52
|
-
const creating = (await tryGetInstallation(state.applicationInstallId, false, logger)) === null;
|
|
53
|
-
|
|
54
|
-
await set(stateType, state.applicationInstallId, state);
|
|
55
|
-
|
|
56
|
-
logger.info(creating ? 'Created installation state' : 'Updated installation state', { applicationInstallId: state.applicationInstallId, organisationId: state.organisationId, organisationBrandId: state.organisationBrandId });
|
|
57
|
-
|
|
58
|
-
return state;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const deleteInstallation = async (applicationInstallId: string, logger: Logger): Promise<void> => {
|
|
62
|
-
await remove(stateType, applicationInstallId);
|
|
63
|
-
|
|
64
|
-
logger.info('Deleted installation state', { applicationInstallId });
|
|
65
|
-
}
|