Skip to content

Commit

Permalink
Merge pull request #4115 from alkem-io/wingback
Browse files Browse the repository at this point in the history
* wip

* moved dir to adapters

* poc wingback create customer

* poc wingback create customer

* getEntitlements

* comment added

* renamed the two ways for assigning entitlements

* fix compilation:

* renaming; code setup

* simplify usage of wingback api setup

* added flag to be able to disable wingback

* fix build

* fix build

* fix build

* Fixed imports

* Update src/services/external/wingback/wingback.manager.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Auto stash before merge of "wingback" and "origin/wingback"

* Update src/platform/licensing/wingback-subscription/licensing.wingback.subscription.service.spec.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fixed comments / test issue

---------

Co-authored-by: Neil Smyth <[email protected]>
Co-authored-by: Neil Smyth <[email protected]>
Co-authored-by: Valentin Yanakiev <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 11, 2024
2 parents ae6d6db + dd79b2f commit 15c1951
Show file tree
Hide file tree
Showing 80 changed files with 640 additions and 202 deletions.
6 changes: 6 additions & 0 deletions alkemio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ search:
# The dash at the end is MANDATORY
index_pattern: ${ELASTIC_SEARCH_INDEX_PATTERN}:alkemio-data-

licensing:
wingback:
enabled: ${LICENSING_WINGBACK_ENABLED}:false
key: ${LICENSING_WINGBACK_API_KEY}
endpoint: ${LICENSING_WINGBACK_API_ENDPOINT}

## identity ##

# Defines all authentication and authorization configuration.
Expand Down
5 changes: 4 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
UnhandledExceptionFilter,
} from '@core/error-handling';
import { MeModule } from '@services/api/me';
import { ExcalidrawServerModule } from '@services/external/excalidraw-backend';
import { ChatGuidanceModule } from '@services/api/chat-guidance/chat.guidance.module';
import { LookupModule } from '@services/api/lookup';
import { AuthResetSubscriberModule } from '@services/auth-reset/subscriber/auth-reset.subscriber.module';
Expand All @@ -87,6 +86,8 @@ import { Cipher, EncryptionModule } from '@hedger/nestjs-encryption';
import { AdminUsersModule } from '@platform/admin/users/admin.users.module';
import { InAppNotificationReaderModule } from '@domain/in-app-notification-reader/in.app.notification.reader.module';
import { InAppNotificationReceiverModule } from '@domain/in-app-notification-receiver';
import { LicensingWingbackSubscriptionModule } from '@platform/licensing/wingback-subscription/licensing.wingback.subscription.module';
import { WingbackManagerModule } from '@services/external/wingback/wingback.manager.module';

@Module({
imports: [
Expand Down Expand Up @@ -267,6 +268,8 @@ import { InAppNotificationReceiverModule } from '@domain/in-app-notification-rec
AdminCommunicationModule,
AdminSearchIngestModule,
AdminLicensingModule,
LicensingWingbackSubscriptionModule,
WingbackManagerModule,
AgentModule,
MessageModule,
MessageReactionModule,
Expand Down
8 changes: 5 additions & 3 deletions src/common/enums/credential.type.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { registerEnumType } from '@nestjs/graphql';
import { LicenseCredential } from './license.credential';
import { LicensingCredentialBasedCredentialType } from './licensing.credential.based.credential.type';
import { AuthorizationCredential } from './authorization.credential';

export const CredentialType = {
...LicenseCredential,
...LicensingCredentialBasedCredentialType,
...AuthorizationCredential,
};

export type CredentialType = LicenseCredential | AuthorizationCredential;
export type CredentialType =
| LicensingCredentialBasedCredentialType
| AuthorizationCredential;

registerEnumType(CredentialType, {
name: 'CredentialType',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerEnumType } from '@nestjs/graphql';

// Credentials to be added later:
export enum LicenseCredential {
export enum LicensingCredentialBasedCredentialType {
SPACE_LICENSE_FREE = 'space-license-free',
SPACE_LICENSE_PLUS = 'space-license-plus',
SPACE_LICENSE_PREMIUM = 'space-license-premium',
Expand All @@ -12,6 +12,6 @@ export enum LicenseCredential {
ACCOUNT_LICENSE_PLUS = 'account-license-plus',
}

registerEnumType(LicenseCredential, {
name: 'LicenseCredential',
registerEnumType(LicensingCredentialBasedCredentialType, {
name: 'LicensingCredentialBasedCredentialType',
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { registerEnumType } from '@nestjs/graphql';

export enum LicensePlanType {
export enum LicensingCredentialBasedPlanType {
ACCOUNT_FEATURE_FLAG = 'account-feature-flag',
ACCOUNT_PLAN = 'account-plan',
SPACE_PLAN = 'space-plan',
SPACE_FEATURE_FLAG = 'space-feature-flag',
}

registerEnumType(LicensePlanType, {
name: 'LicensePlanType',
registerEnumType(LicensingCredentialBasedPlanType, {
name: 'LicensingCredentialBasedPlanType',
});
11 changes: 11 additions & 0 deletions src/common/enums/licensing.wingback.subscription.feature.name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { registerEnumType } from '@nestjs/graphql';

export enum LicensingWingbackSubscriptionFeatureName {
ACCOUNT_SPACE_FREE = 'account-space-free',
ACCOUNT_SPACE_PLUS = 'account-space-plus',
ACCOUNT_SPACE_PREMIUM = 'account-space-premium',
}

registerEnumType(LicensingWingbackSubscriptionFeatureName, {
name: 'LicensingWingbackSubscriptionFeatureName',
});
4 changes: 2 additions & 2 deletions src/core/bootstrap/bootstrap.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { TemplatesSetModule } from '@domain/template/templates-set/templates.set
import { TemplatesManagerModule } from '@domain/template/templates-manager/templates.manager.module';
import { TemplateDefaultModule } from '@domain/template/template-default/template.default.module';
import { LicenseModule } from '@domain/common/license/license.module';
import { LicensePlanModule } from '@platform/license-plan/license.plan.module';
import { LicensingFrameworkModule } from '@platform/licensing-framework/licensing.framework.module';
import { AiPersonaServiceModule } from '@services/ai-server/ai-persona-service/ai.persona.service.module';
import { LicensingFrameworkModule } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.module';
import { LicensePlanModule } from '@platform/licensing/credential-based/license-plan/license.plan.module';

@Module({
imports: [
Expand Down
4 changes: 2 additions & 2 deletions src/core/bootstrap/bootstrap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ import { bootstrapSpaceTutorialsCalloutGroups } from './platform-template-defini
import { bootstrapSpaceTutorialsCallouts } from './platform-template-definitions/space-tutorials/bootstrap.space.tutorials.callouts';
import { LicenseService } from '@domain/common/license/license.service';
import { AccountLicenseService } from '@domain/space/account/account.service.license';
import { LicensePlanService } from '@platform/license-plan/license.plan.service';
import { LicensingFrameworkService } from '@platform/licensing-framework/licensing.framework.service';
import { LicensePlanService } from '@platform/licensing/credential-based/license-plan/license.plan.service';
import { LicensingFrameworkService } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.service';
import { AiPersonaServiceService } from '@services/ai-server/ai-persona-service/ai.persona.service.service';
import { AiPersonaEngine } from '@common/enums/ai.persona.engine';
import { AiPersonaBodyOfKnowledgeType } from '@common/enums/ai.persona.body.of.knowledge.type';
Expand Down
1 change: 0 additions & 1 deletion src/core/license-engine/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/core/license-engine/license.engine.module.ts

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions src/core/license-engine/license.policy.rule.credential.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { ObjectType } from '@nestjs/graphql';
import {
InAppNotificationCommunityNewMemberPayload,
NotificationEventType,
InAppNotificationCategory,
} from '@alkemio/notifications-lib';
import { IContributor } from '@domain/community/contributor/contributor.interface';
import { CommunityContributorType } from '@common/enums/community.contributor.type';
import { ISpace } from '@domain/space/space/space.interface';
import { InAppNotificationState } from '@domain/in-app-notification/in.app.notification.state';
import { InAppNotification } from '../in.app.notification.interface';
import { InAppNotificationBase } from '@domain/in-app-notification-reader/dto/in.app.notification.base';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import { ObjectType } from '@nestjs/graphql';
import {
InAppNotificationContributorMentionedPayload,
NotificationEventType,
InAppNotificationCategory,
} from '@alkemio/notifications-lib';
import { CommunityContributorType } from '@common/enums/community.contributor.type';
import { IContributor } from '@domain/community/contributor/contributor.interface';
import { InAppNotification } from '../in.app.notification.interface';
import { InAppNotificationState } from '@domain/in-app-notification/in.app.notification.state';
import { InAppNotificationBase } from '@domain/in-app-notification-reader/dto/in.app.notification.base';

@ObjectType('InAppNotificationUserMentioned', {
Expand Down
4 changes: 2 additions & 2 deletions src/domain/space/account.host/account.host.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Module } from '@nestjs/common';
import { AccountHostService } from './account.host.service';
import { AgentModule } from '@domain/agent/agent/agent.module';
import { LicenseIssuerModule } from '@platform/license-issuer/license.issuer.module';
import { LicenseIssuerModule } from '@platform/licensing/credential-based/license-credential-issuer/license.issuer.module';
import { StorageAggregatorModule } from '@domain/storage/storage-aggregator/storage.aggregator.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Account } from '../account/account.entity';
import { LicenseModule } from '@domain/common/license/license.module';
import { LicensingFrameworkModule } from '@platform/licensing-framework/licensing.framework.module';
import { LicensingFrameworkModule } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.module';

@Module({
imports: [
Expand Down
6 changes: 3 additions & 3 deletions src/domain/space/account.host/account.host.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { ICredentialDefinition } from '@domain/agent/credential/credential.defin
import { User } from '@domain/community/user/user.entity';
import { Organization } from '@domain/community/organization';
import { AgentService } from '@domain/agent/agent/agent.service';
import { ILicensePlan } from '@platform/license-plan/license.plan.interface';
import { LicenseIssuerService } from '@platform/license-issuer/license.issuer.service';
import { ILicensePlan } from '@platform/licensing/credential-based/license-plan/license.plan.interface';
import { LicenseIssuerService } from '@platform/licensing/credential-based/license-credential-issuer/license.issuer.service';
import { Account } from '../account/account.entity';
import { AuthorizationPolicy } from '@domain/common/authorization-policy/authorization.policy.entity';
import { StorageAggregatorService } from '@domain/storage/storage-aggregator/storage.aggregator.service';
Expand All @@ -28,7 +28,7 @@ import { LicenseService } from '@domain/common/license/license.service';
import { LicenseType } from '@common/enums/license.type';
import { LicenseEntitlementType } from '@common/enums/license.entitlement.type';
import { LicenseEntitlementDataType } from '@common/enums/license.entitlement.data.type';
import { LicensingFrameworkService } from '@platform/licensing-framework/licensing.framework.service';
import { LicensingFrameworkService } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.service';

@Injectable()
export class AccountHostService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LicenseCredential } from '@common/enums/license.credential';
import { LicensingCredentialBasedCredentialType } from '@common/enums/licensing.credential.based.credential.type';
import { Field, ObjectType } from '@nestjs/graphql';

@ObjectType('AccountSubscription')
export abstract class IAccountSubscription {
@Field(() => LicenseCredential, {
@Field(() => LicensingCredentialBasedCredentialType, {
description: 'The name of the Subscription.',
})
name!: LicenseCredential;
name!: LicensingCredentialBasedCredentialType;

@Field(() => Date, {
nullable: true,
Expand Down
8 changes: 4 additions & 4 deletions src/domain/space/account/account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { NameReporterModule } from '@services/external/elasticsearch/name-report
import { AccountResolverQueries } from './account.resolver.queries';
import { ContributorModule } from '@domain/community/contributor/contributor.module';
import { VirtualContributorModule } from '@domain/community/virtual-contributor/virtual.contributor.module';
import { LicenseIssuerModule } from '@platform/license-issuer/license.issuer.module';
import { LicenseIssuerModule } from '@platform/licensing/credential-based/license-credential-issuer/license.issuer.module';
import { AccountHostModule } from '../account.host/account.host.module';
import { LicenseEngineModule } from '@core/license-engine/license.engine.module';
import { LicensingCredentialBasedModule } from '@platform/licensing/credential-based/licensing-credential-based-entitlements-engine/licensing.credential.based.module';
import { StorageAggregatorModule } from '@domain/storage/storage-aggregator/storage.aggregator.module';
import { NotificationAdapterModule } from '@services/adapters/notification-adapter/notification.adapter.module';
import { InnovationHubModule } from '@domain/innovation-hub/innovation.hub.module';
Expand All @@ -25,7 +25,7 @@ import { NamingModule } from '@services/infrastructure/naming/naming.module';
import { TemporaryStorageModule } from '@services/infrastructure/temporary-storage/temporary.storage.module';
import { LicenseModule } from '@domain/common/license/license.module';
import { AccountLicenseService } from './account.service.license';
import { LicensingFrameworkModule } from '@platform/licensing-framework/licensing.framework.module';
import { LicensingFrameworkModule } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.module';

@Module({
imports: [
Expand All @@ -39,7 +39,7 @@ import { LicensingFrameworkModule } from '@platform/licensing-framework/licensin
PlatformAuthorizationPolicyModule,
LicensingFrameworkModule,
LicenseIssuerModule,
LicenseEngineModule,
LicensingCredentialBasedModule,
LicenseModule,
SpaceModule,
InnovationHubModule,
Expand Down
4 changes: 2 additions & 2 deletions src/domain/space/account/account.service.license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { IAgent } from '@domain/agent/agent/agent.interface';
import { LicenseService } from '@domain/common/license/license.service';
import { ILicense } from '@domain/common/license/license.interface';
import { LicenseEngineService } from '@core/license-engine/license.engine.service';
import { LicensingCredentialBasedService } from '@platform/licensing/credential-based/licensing-credential-based-entitlements-engine/licensing.credential.based.service';
import { LicenseEntitlementType } from '@common/enums/license.entitlement.type';
import { IAccount } from './account.interface';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
Expand All @@ -19,7 +19,7 @@ export class AccountLicenseService {
constructor(
private licenseService: LicenseService,
private accountService: AccountService,
private licenseEngineService: LicenseEngineService,
private licenseEngineService: LicensingCredentialBasedService,
private spaceLicenseService: SpaceLicenseService,
@Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService
) {}
Expand Down
8 changes: 4 additions & 4 deletions src/domain/space/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { AuthorizationPolicyService } from '@domain/common/authorization-policy/
import { AccountHostService } from '../account.host/account.host.service';
import { IAgent } from '@domain/agent/agent/agent.interface';
import { IAccountSubscription } from './account.license.subscription.interface';
import { LicenseCredential } from '@common/enums/license.credential';
import { LicensingCredentialBasedCredentialType } from '@common/enums/licensing.credential.based.credential.type';
import { LicenseService } from '@domain/common/license/license.service';

@Injectable()
Expand Down Expand Up @@ -367,12 +367,12 @@ export class AccountService {
const subscriptions: IAccountSubscription[] = [];
for (const credential of account.agent.credentials) {
if (
Object.values(LicenseCredential).includes(
credential.type as LicenseCredential
Object.values(LicensingCredentialBasedCredentialType).includes(
credential.type as LicensingCredentialBasedCredentialType
)
) {
subscriptions.push({
name: credential.type as LicenseCredential,
name: credential.type as LicensingCredentialBasedCredentialType,
expires: credential.expires,
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LicenseCredential } from '@common/enums/license.credential';
import { LicensingCredentialBasedCredentialType } from '@common/enums/licensing.credential.based.credential.type';
import { Field, ObjectType } from '@nestjs/graphql';

@ObjectType('SpaceSubscription')
export abstract class ISpaceSubscription {
@Field(() => LicenseCredential, {
@Field(() => LicensingCredentialBasedCredentialType, {
description: 'The name of the Subscription.',
})
name!: LicenseCredential;
name!: LicensingCredentialBasedCredentialType;

@Field(() => Date, {
nullable: true,
Expand Down
8 changes: 4 additions & 4 deletions src/domain/space/space/space.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import { PlatformAuthorizationPolicyModule } from '@platform/authorization/platf
import { NamingModule } from '@services/infrastructure/naming/naming.module';
import { SpaceSettingsModule } from '../space.settings/space.settings.module';
import { AccountHostModule } from '../account.host/account.host.module';
import { LicenseEngineModule } from '@core/license-engine/license.engine.module';
import { LicenseIssuerModule } from '@platform/license-issuer/license.issuer.module';
import { LicensingCredentialBasedModule } from '@platform/licensing/credential-based/licensing-credential-based-entitlements-engine/licensing.credential.based.module';
import { LicenseIssuerModule } from '@platform/licensing/credential-based/license-credential-issuer/license.issuer.module';
import { InputCreatorModule } from '@services/api/input-creator/input.creator.module';
import { RoleSetModule } from '@domain/access/role-set/role.set.module';
import { TemplatesManagerModule } from '@domain/template/templates-manager/templates.manager.module';
import { SpaceDefaultsModule } from '../space.defaults/space.defaults.module';
import { LicensingFrameworkModule } from '@platform/licensing-framework/licensing.framework.module';
import { LicensingFrameworkModule } from '@platform/licensing/credential-based/licensing-framework/licensing.framework.module';
import { LicenseModule } from '@domain/common/license/license.module';
import { SpaceLicenseService } from './space.service.license';

Expand All @@ -44,7 +44,7 @@ import { SpaceLicenseService } from './space.service.license';
ProfileModule,
LicensingFrameworkModule,
LicenseIssuerModule,
LicenseEngineModule,
LicensingCredentialBasedModule,
NamingModule,
PlatformAuthorizationPolicyModule,
TemplatesManagerModule,
Expand Down
4 changes: 2 additions & 2 deletions src/domain/space/space/space.service.license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { IAgent } from '@domain/agent/agent/agent.interface';
import { LicenseService } from '@domain/common/license/license.service';
import { ILicense } from '@domain/common/license/license.interface';
import { LicenseEngineService } from '@core/license-engine/license.engine.service';
import { LicensingCredentialBasedService } from '@platform/licensing/credential-based/licensing-credential-based-entitlements-engine/licensing.credential.based.service';
import { LicenseEntitlementType } from '@common/enums/license.entitlement.type';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
import { SpaceService } from './space.service';
Expand All @@ -19,7 +19,7 @@ export class SpaceLicenseService {
constructor(
private licenseService: LicenseService,
private spaceService: SpaceService,
private licenseEngineService: LicenseEngineService,
private licenseEngineService: LicensingCredentialBasedService,
private roleSetLicenseService: RoleSetLicenseService,
private collaborationLicenseService: CollaborationLicenseService,
@Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService
Expand Down
Loading

0 comments on commit 15c1951

Please sign in to comment.