Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit 33092fe

Browse files
authored
Merge pull request #59 from scale8/ingest-wizard
Ingest wizard
2 parents c68765a + ce275b3 commit 33092fe

File tree

59 files changed

+966
-771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+966
-771
lines changed

api/src/backends/configuration/abstractions/BaseConfig.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,18 @@ export default abstract class BaseConfig {
129129
}
130130

131131
public async getUiUrl(): Promise<string> {
132-
return await this.getConfigEntryOrElse(
133-
'S8_UI_SERVER',
134-
this.isProduction() ? 'https://ui.scale8.com' : 'https://ui-dev.scale8.com:8443',
135-
);
132+
const getDefaultUiUrl = () => {
133+
if (this.isCommercial()) {
134+
if (this.isProduction()) {
135+
return 'https://ui.scale8.com';
136+
} else {
137+
return 'https://ui-dev.scale8.com:8443';
138+
}
139+
} else {
140+
return 'http://127.0.0.1:3000';
141+
}
142+
};
143+
return await this.getConfigEntryOrElse('S8_UI_SERVER', getDefaultUiUrl());
136144
}
137145

138146
public async getDefaultAdminPassword(): Promise<string> {
@@ -242,6 +250,10 @@ export default abstract class BaseConfig {
242250
return await this.getConfigEntryThrows('SMTP_PASSWORD');
243251
}
244252

253+
public async trackDependencies(): Promise<boolean> {
254+
return (await this.getConfigEntryOrElse('TRACK_DEPENDENCIES', 'false')) === 'true';
255+
}
256+
245257
public async isCaptchaEnabled(): Promise<boolean> {
246258
return (await this.getConfigEntryOrElse('CAPTCHA_ENABLED', 'true')) === 'true';
247259
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum IngestSchemaWizard {
2+
USER_TRACKING = 'USER_TRACKING',
3+
ERROR_TRACKING = 'ERROR_TRACKING',
4+
}

api/src/gql/ResolverRegister.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import StripeProducts from '../payments/providers/StripeProducts';
2727
import Org from '../mongo/models/Org';
2828
import BaseConfig from '../backends/configuration/abstractions/BaseConfig';
2929
import { InputType } from '../../../common/enums/InputType';
30+
import { IngestSchemaWizard } from '../enums/IngestSchemaWizard';
3031

3132
type CoreElementDataMapDescription = {
3233
name: string;

api/src/gql/TypeDefRegister.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import { Mode } from '../enums/Mode';
3939
import { InputType } from '../../../common/enums/InputType';
4040
import { TypeIcon } from '../../../common/enums/TypeIcon';
41+
import { IngestSchemaWizard } from '../enums/IngestSchemaWizard';
4142

4243
@injectable()
4344
export default class TypeDefRegister {
@@ -232,6 +233,12 @@ export default class TypeDefRegister {
232233
value: String!
233234
}
234235
236+
"""
237+
A set of supported \`IngestSchemaWizard\` types.
238+
"""
239+
enum IngestSchemaWizard
240+
${TypeDefRegister.enumToGQL(IngestSchemaWizard)}
241+
235242
"""
236243
A set of supported \`Notification\` types.
237244
"""

api/src/managers/data/IngestEndpointEnvironmentManager.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export default class IngestEndpointEnvironmentManager extends Manager<IngestEndp
4141
"""
4242
name: String!
4343
"""
44+
\`IngestEndpointEnvironment\`'s install endpoint
45+
"""
46+
install_endpoint: String!
47+
"""
4448
A custom domain name associated with this \`IngestEndpointEnvironment\`
4549
"""
4650
custom_domain: String
@@ -332,8 +336,29 @@ export default class IngestEndpointEnvironmentManager extends Manager<IngestEndp
332336
* Custom Resolvers
333337
* @protected
334338
*/
339+
340+
private async getInstallDomain(environmentId: ObjectId, ctx: CTX): Promise<string> {
341+
const env = await this.repoFactory(IngestEndpointEnvironment).findByIdThrows(
342+
environmentId,
343+
userMessages.environmentFailed,
344+
);
345+
return await this.orgAuth.asUserWithViewAccess(ctx, env.orgId, async () =>
346+
getIngestEndpointInstallDomain(env),
347+
);
348+
}
349+
335350
protected gqlCustomResolvers = {
336351
IngestEndpointEnvironment: {
352+
install_endpoint: async (parent: any, args: any, ctx: CTX) => {
353+
if (this.config.isCommercial()) {
354+
return `https://${await this.getInstallDomain(new ObjectId(parent.id), ctx)}`;
355+
} else if (this.config.isDevelopment()) {
356+
//todo. remove hard coded port...
357+
return `http://localhost:6080/edge/${parent.id}`;
358+
} else {
359+
return `${await this.config.getUiUrl()}/edge/${parent.id}`;
360+
}
361+
},
337362
cname: async (parent: any) =>
338363
getCNAME(
339364
await this.repoFactory(IngestEndpointEnvironment).findByIdThrows(

api/src/managers/data/IngestEndpointManager.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ import {
1616
createUsageEndpointEnvironment,
1717
getCommercialStorageProvider,
1818
getCommercialStorageProviderConfig,
19-
getProviderConfigThrows,
2019
getProviderConfig,
20+
getProviderConfigThrows,
2121
updateIngestEndpointEnvironment,
2222
} from '../../utils/IngestEndpointEnvironmentUtils';
2323
import { VarType } from '../../enums/VarType';
2424
import TYPES from '../../container/IOC.types';
2525
import BaseDatabase from '../../backends/databases/abstractions/BaseDatabase';
2626
import { withUnManagedAccount } from '../../utils/DataManagerAccountUtils';
2727
import { StorageProvider } from '../../enums/StorageProvider';
28-
import { StorageProviderConfig } from '../../mongo/types/Types';
28+
import { IngestEndpointDataMapSchema, StorageProviderConfig } from '../../mongo/types/Types';
2929
import GenericError from '../../errors/GenericError';
3030
import { LogPriority } from '../../enums/LogPriority';
3131
import Hash from '../../core/Hash';
32+
import { createIngestEndpointDataMapFromSchemas } from '../../utils/IngestEndpointDataMapUtils';
33+
import { IngestSchemaWizard } from '../../enums/IngestSchemaWizard';
34+
import { errorTrackingSchema, userTrackingSchema } from '../../utils/AppUtils';
3235

3336
@injectable()
3437
export default class IngestEndpointManager extends Manager<IngestEndpoint> {
@@ -134,6 +137,10 @@ export default class IngestEndpointManager extends Manager<IngestEndpoint> {
134137
"""
135138
name: String!
136139
"""
140+
The wizard to be applied when creating the new endpoint
141+
"""
142+
ingest_schema_wizard: IngestSchemaWizard
143+
"""
137144
The storage provider to be used by the \`App\` to store analytics data
138145
"""
139146
storage_provider: StorageProvider
@@ -317,13 +324,26 @@ export default class IngestEndpointManager extends Manager<IngestEndpoint> {
317324
);
318325
};
319326

327+
const getSchemaForWizard = (
328+
wizard?: IngestSchemaWizard,
329+
): IngestEndpointDataMapSchema[] | undefined => {
330+
if (wizard === IngestSchemaWizard.USER_TRACKING) {
331+
return [...userTrackingSchema];
332+
} else if (wizard === IngestSchemaWizard.ERROR_TRACKING) {
333+
return [...userTrackingSchema, ...errorTrackingSchema];
334+
} else {
335+
return undefined;
336+
}
337+
};
338+
320339
const createIngestEndpoint = async (
321340
actor: User,
322341
dataManagerAccount: DataManagerAccount,
323342
name: string,
324343
provider: StorageProvider,
325344
providerConfig: StorageProviderConfig,
326345
analyticsEnabled: boolean,
346+
wizard?: IngestSchemaWizard,
327347
): Promise<IngestEndpoint> => {
328348
let ingestEndpoint = await this.repoFactory(IngestEndpoint).save(
329349
new IngestEndpoint(name, dataManagerAccount, analyticsEnabled, provider),
@@ -342,10 +362,22 @@ export default class IngestEndpointManager extends Manager<IngestEndpoint> {
342362
JSON.stringify(providerConfig),
343363
);
344364
ingestEndpoint = await this.repoFactory(IngestEndpoint).save(ingestEndpoint, actor);
345-
await this.repoFactory(IngestEndpointRevision).save(
365+
const ingestEndpointRevision = await this.repoFactory(IngestEndpointRevision).save(
346366
new IngestEndpointRevision('Revision 1', ingestEndpoint),
347367
actor,
348368
);
369+
370+
const schema = getSchemaForWizard(wizard);
371+
if (schema !== undefined) {
372+
ingestEndpointRevision.ingestEndpointDataMapIds = (
373+
await createIngestEndpointDataMapFromSchemas(
374+
actor,
375+
schema,
376+
ingestEndpointRevision,
377+
)
378+
).map((_) => _.id);
379+
}
380+
349381
return ingestEndpoint;
350382
};
351383

@@ -389,6 +421,7 @@ export default class IngestEndpointManager extends Manager<IngestEndpoint> {
389421
storageProvider,
390422
providerConfig,
391423
data.analytics_enabled,
424+
data.ingest_schema_wizard,
392425
)
393426
).toGQLType();
394427
},

api/src/managers/tag/ActionManager.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,26 +358,28 @@ export default class ActionManager extends Manager<Action> {
358358
};
359359

360360
private async registerAllDeps(actor: User, action: Action, checks: DataMapSchemaCheck[]) {
361-
const repoFactory = container.get<RepoFromModelFactory>(TYPES.RepoFromModelFactory);
362-
await Promise.all(
363-
checks
364-
.map((_) =>
365-
_.model_links?.map(
366-
async (modelLink) =>
367-
await repoFactory(Dependency).save(
368-
new Dependency(
369-
action.id,
370-
action.constructor.name,
371-
modelLink.id,
372-
modelLink.name,
361+
if (await this.config.trackDependencies()) {
362+
const repoFactory = container.get<RepoFromModelFactory>(TYPES.RepoFromModelFactory);
363+
await Promise.all(
364+
checks
365+
.map((_) =>
366+
_.model_links?.map(
367+
async (modelLink) =>
368+
await repoFactory(Dependency).save(
369+
new Dependency(
370+
action.id,
371+
action.constructor.name,
372+
modelLink.id,
373+
modelLink.name,
374+
),
375+
actor,
373376
),
374-
actor,
375-
),
376-
),
377-
)
378-
.filter((_): _ is Promise<Dependency>[] => _ !== undefined)
379-
.flat(),
380-
);
377+
),
378+
)
379+
.filter((_): _ is Promise<Dependency>[] => _ !== undefined)
380+
.flat(),
381+
);
382+
}
381383
}
382384

383385
private async removeAllDeps(actor: User, action: Action) {

api/src/managers/tag/EnvironmentManager.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export default class EnvironmentManager extends Manager<Environment> {
4343
"""
4444
url: String
4545
"""
46+
\`Environment\`'s install endpoint
47+
"""
48+
install_endpoint: String!
49+
"""
4650
\`Environment\`'s custom domain name if configured
4751
"""
4852
custom_domain: String
@@ -401,28 +405,42 @@ export default class EnvironmentManager extends Manager<Environment> {
401405
* Custom Resolvers
402406
* @protected
403407
*/
408+
409+
private async getInstallDomain(environmentId: ObjectId, ctx: CTX): Promise<string> {
410+
const env = await this.repoFactory(Environment).findByIdThrows(
411+
environmentId,
412+
userMessages.environmentFailed,
413+
);
414+
return await this.orgAuth.asUserWithViewAccess(ctx, env.orgId, async () => {
415+
if (env.customDomain === undefined) {
416+
return getCNAME(env);
417+
} else {
418+
return env.customDomain;
419+
}
420+
});
421+
}
422+
404423
protected gqlCustomResolvers = {
405424
Environment: {
425+
install_endpoint: async (parent: any, args: any, ctx: CTX) => {
426+
if (this.config.isCommercial()) {
427+
return `https://${await this.getInstallDomain(new ObjectId(parent.id), ctx)}`;
428+
} else if (this.config.isDevelopment()) {
429+
//todo. remove hard coded port...
430+
return `http://localhost:6080/edge/${parent.id}`;
431+
} else {
432+
return `${await this.config.getUiUrl()}/edge/${parent.id}`;
433+
}
434+
},
406435
cname: async (parent: any) =>
407436
getCNAME(
408437
await this.repoFactory(Environment).findByIdThrows(
409438
new ObjectId(parent.id),
410439
userMessages.environmentFailed,
411440
),
412441
),
413-
install_domain: async (parent: any, args: any, ctx: CTX) => {
414-
const env = await this.repoFactory(Environment).findByIdThrows(
415-
new ObjectId(parent.id),
416-
userMessages.environmentFailed,
417-
);
418-
return await this.orgAuth.asUserWithViewAccess(ctx, env.orgId, async () => {
419-
if (env.customDomain === undefined) {
420-
return getCNAME(env);
421-
} else {
422-
return env.customDomain;
423-
}
424-
});
425-
},
442+
install_domain: async (parent: any, args: any, ctx: CTX) =>
443+
this.getInstallDomain(new ObjectId(parent.id), ctx),
426444
revision: async (parent: any, args: any, ctx: CTX) => {
427445
const env = await this.repoFactory(Environment).findByIdThrows(
428446
new ObjectId(parent.id),

0 commit comments

Comments
 (0)