Skip to content
Merged
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
26 changes: 26 additions & 0 deletions .github/workflows/publish-authkit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish AuthKit Package to NPM

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/connections
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# docker build --secret id=NPM_TOKEN .
#
# This keeps the NPM token out of the image history
# NPM_TOKEN needs access to the @integrationos organization in NPM
# NPM_TOKEN needs access to the @picahq organization in NPM

FROM node:16.13.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ The Typescript Service is a MoleculerJS based monorepo that contains all the ser

## License

IntegrationOS's Typescript Services is released under the [**GPL-3.0 license**](LICENSE).
Pica's Typescript Services is released under the [**GPL-3.0 license**](LICENSE).
6 changes: 6 additions & 0 deletions apps/event-system/services/api/routes/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const internalRoute = () => ({
'v1.clients.get',
'v1.clients.update',
'v1.onboarding.public.init',

'v1.early-access.public.create',

],
aliases: {
'POST v3/users/get': 'v3.users.getUserFromToken',
Expand Down Expand Up @@ -65,6 +68,9 @@ export const internalRoute = () => ({
// Onboarding
'POST v1/onboarding/init': 'v1.onboarding.public.init',

// Early Access
'POST v1/early-access/create': 'v1.early-access.public.create',

},
cors: {
origin: '*', //corsOk,
Expand Down
28 changes: 28 additions & 0 deletions apps/event-system/services/early-access/early-access.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { GenericServiceProvider, makeOwnershipFromContextMeta } from '@libs-private/service-logic/services/genericService';
import { ServiceBroker, Context } from 'moleculer';
import { createEarlyAccessSchema } from './schema/create.schema';
import { useEarlyAccessService } from '@libs-private/service-logic/services/early-access/useEarlyAccessService';
import { CreateEarlyAccessPayload } from '@event-inc/types/early-access';
import { ServiceContextMeta } from '@libs-private/data-models/types/genericService';
const MongoDBAdapter = require('moleculer-db-adapter-mongo');

export default class EarlyAccess extends GenericServiceProvider {
public constructor(public broker: ServiceBroker) {
super(broker, {
name: 'early-access',
adapter: new MongoDBAdapter(process.env.MONGO_URI),
version: 1,
hooks: {},
collection: 'early-access',
publicActions: {
create: [createEarlyAccessSchema, publicCreate]
}
});
}
}

const publicCreate = async (ctx: Context<unknown, ServiceContextMeta>) => {
const { create } = useEarlyAccessService(ctx, makeOwnershipFromContextMeta(ctx));
return (await create(ctx.params as CreateEarlyAccessPayload)).unwrap();
}

20 changes: 20 additions & 0 deletions apps/event-system/services/early-access/schema/create.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createSchema } from '@libs-private/generic-schema/create.schema';

export const createEarlyAccessSchema = {
...createSchema,
companyName: {
type: 'string'
},
companyLinkedInUrl: {
type: 'string'
},
userLinkedInUrl: {
type: 'string'
},
useCase: {
type: 'string'
},
type: {
type: 'string'
}
}
16 changes: 0 additions & 16 deletions apps/event-system/services/stripe/stripe-webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,10 @@ export default {
function analyzeSubscription(subscriptionData: Stripe.SubscriptionItem[]): string {
const priceIds = new Set(subscriptionData.map((item) => item.price.id));

if (priceIds.has(process.env.STRIPE_PRO_PLAN_PRICE_ID) && priceIds.has(process.env.STRIPE_SUPPORT_PLAN_PRICE_ID)) {
return 'sub::pro_support';
}

if (priceIds.has(process.env.STRIPE_PRO_PLAN_PRICE_ID)) {
return 'sub::pro';
}

if (priceIds.has(process.env.STRIPE_SUPPORT_PLAN_PRICE_ID)) {
return 'sub::support';
}

if (priceIds.has(process.env.STRIPE_GROWTH_PLAN_PRICE_ID)) {
return 'sub::growth';
}

if (priceIds.has(process.env.STRIPE_RIDICULOUSLY_CHEAP_PLAN_PRICE_ID)) {
return 'sub::ridiculous';
}

if (priceIds.has(process.env.STRIPE_FREE_PLAN_PRICE_ID)) {
return 'sub::free';
}
Expand Down
4 changes: 4 additions & 0 deletions apps/event-system/services/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ module.exports = {
'username',
'userKey',
'billing',
'accessList',
],

actions: {
Expand Down Expand Up @@ -868,6 +869,7 @@ module.exports = {
}: any) {
const updateUser = async (_user: any) => {
const profile = get(_user, 'profile');
const accessList = get(_user, 'accessList');
const _firstName = get(_user, 'firstName')
? get(_user, 'firstName')
: firstName;
Expand Down Expand Up @@ -907,6 +909,7 @@ module.exports = {
id: _user._id,
firstName: _firstName,
lastName: _lastName,
accessList,
username: _user.username ? _user.username : username,
userKey: _user.userKey
? _user.userKey
Expand Down Expand Up @@ -988,6 +991,7 @@ module.exports = {
_user = await ctx.broker.call('v3.users.create', {
email,
username,
accessList: [],
userKey: `${username || email.substring(0, email.indexOf('@'))
}${randomCode(6)}`,
providers: {
Expand Down
2 changes: 1 addition & 1 deletion libs-private/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const MAXIMUM_SECRET_KEYS_LIMIT = 1000;
export const INTEGRATIONOS_VERSION = 'v1';
export const PICA_VERSION = 'v1';
1 change: 1 addition & 0 deletions libs-private/data-models/types/ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const idPrefixes = {
linkToken: 'ln_tk',
setting: 'st',
token: 'embed_tk',
earlyAccess: 'ea',
} as const;

export type IdPrefix = (typeof idPrefixes)[keyof typeof idPrefixes];
Expand Down
1 change: 1 addition & 0 deletions libs-private/data-models/types/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const Services = {
ConnectionTesting: 'v1.connection-testing',
PlatformsOauth: 'v1.platforms-oauth',
Onboarding: 'v1.onboarding',
EarlyAccess: 'v1.early-access',
} as const;

type keys = keyof typeof Services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class EmbedToken {
return this.configs.baseUrl;
}

return 'https://api.integrationos.com/internal';
return 'https://api.picaos.com/internal';
}

async create(payload: {
Expand All @@ -46,7 +46,7 @@ export class EmbedToken {

export const getHeaders = (secret: string) => {
return {
'X-Buildable-Secret': secret,
'X-Pica-Secret': secret,
'Content-Type': 'application/json',
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const createEventLinkTokenApi = async (

const { data: linkData } = matchResultAndHandleHttpError(link, identity);

const apiBaseUrl = process.env.INTEGRATIONOS_API_BASE_URL || "https://api.integrationos.com/v1";
const apiBaseUrl = process.env.PICA_API_BASE_URL || "https://api.picaos.com/v1";
const connectionDefinitionUrl = `${apiBaseUrl}/public/connection-definitions`;

const connectionDefinitions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const testConnectionModelDefinition = async (
url: `${url}/${connectionModelDefinitionId}`,
method: 'POST',
headers: {
'x-integrationos-secret': process.env
'x-pica-secret': process.env
.QA_ACCOUNT_EVENT_ACCESS_KEY as string,
},
data: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Context } from 'moleculer';
import { Ownership, Services } from '@libs-private/data-models';
import { useGenericCRUDService } from '@libs-private/service-logic/service-helper';
import { CreateEarlyAccessPayload } from '@event-inc/types/early-access';
import jwt from 'jsonwebtoken';

export const useEarlyAccessService = (ctx: Context, ownership: Ownership) => {

const SERVICE_NAME = Services.EarlyAccess;

const {
create: _create,
} = useGenericCRUDService(ctx, SERVICE_NAME, ownership, {
DISABLE_ADDING_OWNERSHIP_CHECK: true,
});

return {
async create(payload: CreateEarlyAccessPayload) {

const authorization = (ctx.meta as any).request.headers['authorization'];
const authToken = authorization.split(' ')[1];
const decoded: any = jwt.decode(authToken, { complete: true });

const userId = decoded?.payload?._id;;
const email = decoded?.payload?.email;

const finalPayload = {
...payload,
userId,
email
}

return await _create("ea", finalPayload);

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
url: CREATE_CONNECTION_URL,
method: 'POST',
headers: {
'x-integrationos-secret':
headers['x-integrationos-secret'] ??
'x-pica-secret':
headers['x-pica-secret'] ??
recordsList?.rows?.[0]?.accessKey,
},
data: {
Expand Down Expand Up @@ -225,7 +225,7 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
identity
);

let secret = headers['x-integrationos-secret'];
let secret = headers['x-pica-secret'];

if (!secret || secret === 'redacted') {
secret = recordsList?.rows?.[0]?.accessKey;
Expand All @@ -235,7 +235,7 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
url: `${CREATE_OAUTH_CONNECTION_URL}/${type}`,
method: 'POST',
headers: {
'x-integrationos-secret': secret,
'x-pica-secret': secret,
},
data: {
__isEngineeringAccount__:
Expand Down Expand Up @@ -292,11 +292,11 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
url: GET_EVENT_ACCESS_RECORD_URL,
method: 'GET',
headers: {
'x-integrationos-secret': headers['x-integrationos-secret'],
'x-integrationos-redaction': false,
'x-pica-secret': headers['x-pica-secret'],
'x-pica-redaction': false,
},
params: {
accessKey: headers['x-integrationos-secret'],
accessKey: headers['x-pica-secret'],
},
});

Expand All @@ -309,7 +309,7 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
const link = await generateEventLinkRecord({
ttl: 2 * 1000 * 60 * 60,
ownership: records?.rows?.[0]?.ownership,
environment: headers['x-integrationos-secret'].startsWith('sk_test')
environment: headers['x-pica-secret'].startsWith('sk_test')
? 'test'
: 'live',
usageSource: 'user-dashboard',
Expand Down Expand Up @@ -352,15 +352,23 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
}
);

// Filter the connected platforms based on the environment
const connectedPlatformsFiltered = connectedPlatforms?.filter(
(platform) =>
headers['x-pica-secret'].startsWith('sk_test')
? platform?.environment === 'test'
: platform?.environment === 'live'
);

const sessionId = await generateId('session_id');

const tokenPayload = {
linkSettings: {
connectedPlatforms: connectedPlatforms ?? [],
connectedPlatforms: connectedPlatformsFiltered ?? [],
eventIncToken: linkToken?.token,
},
ttl: 5 * 60 * 1000,
environment: headers['x-integrationos-secret'].startsWith('sk_test')
environment: headers['x-pica-secret'].startsWith('sk_test')
? 'test'
: 'live',
features: settings?.features,
Expand Down Expand Up @@ -408,8 +416,8 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
method: 'GET',
headers: {
// @ts-ignore
'x-integrationos-secret': `sk_test${decoded?.payload?.pointers?.[0]}`,
'x-integrationos-redaction': false,
'x-pica-secret': `sk_test${decoded?.payload?.pointers?.[0]}`,
'x-pica-redaction': false,
},
params: {
// @ts-ignore
Expand Down
4 changes: 2 additions & 2 deletions libs-private/service-logic/services/events/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INTEGRATIONOS_VERSION } from '@libs-private/constants';
import { PICA_VERSION } from '@libs-private/constants';
import { ListResponse } from '@libs-private/data-models';
import {
EventAccessKeyData,
Expand Down Expand Up @@ -84,7 +84,7 @@ export const producePartialTopicFromEventAccessKeyData = (
const type = eventAccessKeyData[1][2];
const group = eventAccessKeyData[1][3];

return `${INTEGRATIONOS_VERSION}/${buildableId}.${namespace}.${environment}.${type}.${group}`;
return `${PICA_VERSION}/${buildableId}.${namespace}.${environment}.${type}.${group}`;
};

export const getPathsFromEventAccessKeyData = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const useSettingsService = (ctx: Context, ownership: Ownership) => {
const eventAccessRecordResult = await findEventAccess<EventAccess>({
query: {
"ownership.buildableId": ownership.buildableId,
"key": `event_access::custom::${platform.environment || "test"}::default::event-inc::internal-ui`
"key": `event_access::custom::${platform?.environment || "test"}::default::event-inc::internal-ui`
},
});

Expand Down
2 changes: 1 addition & 1 deletion libs-private/utils/ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const generateKey = ({
};

export const generateId = async (prefix: string) => {
const apiBaseUrl = process.env.INTEGRATIONOS_API_BASE_URL || "https://api.integrationos.com/v1";
const apiBaseUrl = process.env.PICA_API_BASE_URL || "https://api.picaos.com/v1";

try {
const response = await axios.get<{
Expand Down
Loading
Loading