Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tenant-management): integrate multiple idps #53

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,588 changes: 857 additions & 731 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion services/subscription-service/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typings/
.node_repl_history

# Output of 'npm pack'
*.tgz
# *.tgz

# Yarn Integrity file
.yarn-integrity
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

let dbm;
let type;
let seed;
let fs = require('fs');
let path = require('path');
let Promise;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function (db) {
let filePath = path.join(
__dirname,
'sqls',
'20240209122448-add-customer-table-up.sql',
);
return new Promise(function (resolve, reject) {
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) {
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
}).then(function (data) {
return db.runSql(data);
});
};

exports.down = function (db) {
let filePath = path.join(
__dirname,
'sqls',
'20240209122448-add-customer-table-down.sql',
);
return new Promise(function (resolve, reject) {
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) {
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
}).then(function (data) {
return db.runSql(data);
});
};

exports._meta = {
version: 1,
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ CREATE TABLE plans (
CONSTRAINT pk_plans_id PRIMARY KEY ( id )
);



CREATE TABLE subscriptions (
id uuid DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid NOT NULL ,
created_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL ,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
drop table main.billing_customer;
drop table main.invoice;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

CREATE TABLE main.billing_customer (
id uuid DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid NOT NULL,
tenant_id varchar(255) NOT NULL,
customer_id varchar(255) NOT NULL,
payment_source_id varchar(255),
created_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
modified_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
deleted boolean DEFAULT false NOT NULL,
deleted_on timestamptz,
deleted_by uuid,
created_by uuid NOT NULL,
modified_by uuid,
CONSTRAINT pk_billing_customer_id PRIMARY KEY (id),
CONSTRAINT uq_billing_customer_customer_id UNIQUE (customer_id)
);



CREATE TABLE main.invoice (
id UUID DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid NOT NULL,
invoice_id VARCHAR(255) NOT NULL,
invoice_status VARCHAR(255),
billing_customer_id uuid NOT NULL,
-- subscription_id uuid,
created_on TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
modified_on TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
deleted BOOLEAN DEFAULT false NOT NULL,
deleted_on TIMESTAMPTZ,
deleted_by UUID,
created_by UUID NOT NULL,
modified_by UUID,
CONSTRAINT pk_invoice_id PRIMARY KEY (id),
CONSTRAINT fk_invoice_customer FOREIGN KEY (billing_customer_id) REFERENCES main.billing_customer(id)

-- CONSTRAINT fk_invoice_subscription FOREIGN KEY (subscription_id) REFERENCES main.subscriptions(id) -- Add this constraint
);

ALTER TABLE main.subscriptions
ADD COLUMN invoice_id uuid NOT NULL,
ADD CONSTRAINT fk_subscriptions_invoice FOREIGN KEY (invoice_id) REFERENCES main.invoice(id);
3 changes: 2 additions & 1 deletion services/subscription-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@loopback/context": "^7.0.2",
"@loopback/core": "^6.0.2",
"@loopback/openapi-v3": "^10.0.2",
"@loopback/repository": "^7.0.2",
"@loopback/repository": "^7.0.4",
"@loopback/rest": "^14.0.2",
"@loopback/rest-explorer": "^7.0.2",
"@loopback/service-proxy": "^7.0.2",
Expand All @@ -84,6 +84,7 @@
"@types/jsonwebtoken": "^9.0.5",
"dotenv": "^16.0.3",
"dotenv-extended": "^2.9.0",
"loopback4-billing": "file:loopback4-billing-0.0.1.tgz",
"loopback-connector-postgresql": "^7.1.1",
"loopback4-authentication": "^12.0.2",
"loopback4-authorization": "^7.0.2",
Expand Down
83 changes: 56 additions & 27 deletions services/subscription-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,83 @@
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

import {inject, Binding} from '@loopback/context';
import {
Binding,
Component,
ControllerClass,
CoreBindings,
inject,
ProviderMap,
ServiceOrProviderClass,
ControllerClass,
} from '@loopback/core';
import {Class, Model, Repository} from '@loopback/repository';
import {Class, Repository, Model} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {
BearerVerifierBindings,
BearerVerifierComponent,
BearerVerifierConfig,
BearerVerifierType,
CoreComponent,
SECURITY_SCHEME_SPEC,
ServiceSequence,
BearerVerifierBindings,
BearerVerifierType,
BearerVerifierConfig,
BearerVerifierComponent,
} from '@sourceloop/core';
import {
FeatureToggleBindings,
FeatureToggleServiceComponent,
} from '@sourceloop/feature-toggle-service';
import {BillingComponent} from 'loopback4-billing';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizationComponent,
} from 'loopback4-authorization';
import {SubscriptionServiceBindings} from './keys';
import {ISubscriptionServiceConfig} from './types';
import {
BillingCycleRepository,
CurrencyRepository,
PlanRepository,
PlanSizesRepository,
ResourceRepository,
ServiceRepository,
SubscriptionRepository,
} from './repositories';
import {
BillinCycleController,
CurrencyController,
HomePageController,
PingController,
CurrencyController,
PlanController,
PlanFeaturesController,
PlanSizesController,
PlanSubscriptionController,
ResourceController,
ServiceController,
SubscriptionController,
PlanSubscriptionController,
PlanSizesController,
PlanFeaturesController,
} from './controllers';
import {
SubscriptionServiceBindings,
SYSTEM_USER,
WEBHOOK_VERIFIER,
} from './keys';
import {
BillingCycle,
Currency,
Plan,
PlanSizes,
Resource,
BillingCustomer,
Invoice,
Service,
Subscription,
PlanSizes,
} from './models';
import {
FeatureToggleBindings,
FeatureToggleServiceComponent,
} from '@sourceloop/feature-toggle-service';
BillingCycleRepository,
CurrencyRepository,
PlanRepository,
ResourceRepository,
ServiceRepository,
SubscriptionRepository,
PlanSizesRepository,
BillingCustomerRepository,
InvoiceRepository,
} from './repositories';
import {ISubscriptionServiceConfig} from './types';
import {WebhookVerifierProvider} from './interceptors/webhook-verifier.interceptor';
import {SystemUserProvider} from './providers';
import {BillingCustomerController} from './controllers/billing-customer.controller';
import {BillingInvoiceController} from './controllers/billing-invoice.controller';
import {BillingPaymentSourceController} from './controllers/billing-payment-source.controller';
import {WebhookController} from './controllers/webhook.controller';

export class SubscriptionServiceComponent implements Component {
constructor(
Expand All @@ -82,6 +97,7 @@ export class SubscriptionServiceComponent implements Component {
.bind(FeatureToggleBindings.Config)
.to({bindControllers: true, useCustomSequence: true});
this.application.component(FeatureToggleServiceComponent);
this.application.component(BillingComponent);

this.application.api({
openapi: '3.0.0',
Expand Down Expand Up @@ -109,17 +125,26 @@ export class SubscriptionServiceComponent implements Component {
ServiceRepository,
SubscriptionRepository,
PlanSizesRepository,
BillingCustomerRepository,
InvoiceRepository,
];

this.models = [
BillingCycle,
Currency,
Plan,
Resource,
BillingCustomer,
Invoice,
Service,
Subscription,
PlanSizes,
];
this.bindings = [
Binding.bind(WEBHOOK_VERIFIER).toProvider(WebhookVerifierProvider),

Binding.bind(SYSTEM_USER).toProvider(SystemUserProvider),
];

this.controllers = [
BillinCycleController,
Expand All @@ -133,6 +158,10 @@ export class SubscriptionServiceComponent implements Component {
PlanSubscriptionController,
PlanSizesController,
PlanFeaturesController,
BillingCustomerController,
BillingInvoiceController,
BillingPaymentSourceController,
WebhookController,
];
}

Expand Down
Loading
Loading