Skip to content

Commit

Permalink
chore: remove rust-utils package (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulkr authored Aug 21, 2024
1 parent 8eba440 commit a6ac2e3
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WORKDIR /app
COPY . .

# Install dependencies
RUN --mount=type=secret,id=NPM_TOKEN NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN) npm i --ignore-scripts && npm i @integrationos/rust-utils
RUN --mount=type=secret,id=NPM_TOKEN NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN) npm i --ignore-scripts

# Build
RUN npm run build
Expand Down
10 changes: 6 additions & 4 deletions libs-private/service-logic/generators/embedTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import {
EmbedTokenRecord,
EmbedTokensPayload,
} from '@event-inc/types/embed-tokens';
import { generateId } from '@integrationos/rust-utils';
import { generateId } from '../service-helper';

export const generateEmbedTokensRecord = ({
export const generateEmbedTokensRecord = async ({
label,
group,
ttl,
linkSettings,
environment,
features,
}: EmbedTokensPayload): EmbedTokenRecord => {
}: EmbedTokensPayload): Promise<EmbedTokenRecord> => {
const sessionId = await generateId('session_id');

return {
label,
group,
Expand All @@ -20,7 +22,7 @@ export const generateEmbedTokensRecord = ({
createdDate: new Date(),
expiresAt: new Date().getTime() + ttl,
environment,
sessionId: generateId('session_id'),
sessionId,
features,
};
};
10 changes: 6 additions & 4 deletions libs-private/service-logic/generators/events/eventLink.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CreateEventLinkPayload, EventLink } from '@event-inc/types';
import { Ownership } from '@event-inc/types/generic';
import { generateId } from '@integrationos/rust-utils';
import { generateId } from '@libs-private/utils';

export const generateEventLinkRecord = ({
export const generateEventLinkRecord = async ({
version = '1.0.0_04.44_18-04-2023T10-33-00',
label,
group,
Expand All @@ -12,14 +12,16 @@ export const generateEventLinkRecord = ({
usageSource,
}: CreateEventLinkPayload & {
ownership: Ownership;
}): EventLink => {
}): Promise<EventLink> => {
const tokenId = await generateId('ln_tk');

return {
_type: 'event-link',
version,
ownership,
label,
group,
token: generateId('ln_tk'),
token: tokenId,
createdAt: Date.now(),
createdDate: new Date(),
expiresAt: new Date().getTime() + ttl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Event, EventCreateInitialPayload } from '@libs-private/data-models';
import { getTopicDetails } from '../../../utils/events';
import {
generateId,
generatePrivateKey,
getWalletFromPrivateKey,
hashMessage,
} from '../../service-helper';
import { generateId } from '@integrationos/rust-utils';

export const generateExternalEvent = async ({
environment,
Expand All @@ -30,9 +30,12 @@ export const generateExternalEvent = async ({
body: _body,
});

const eventId = await generateId('evt');
const eventKeyId = await generateId('evt_k');

const event: Event = {
_id: generateId('evt'),
key: generateId('evt_k'),
_id: eventId,
key: eventKeyId,
topic,
environment,
body: _body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@event-inc/utils';
import { identity } from 'ramda';
import { EmbedTokenRecord } from '@event-inc/types/embed-tokens';
import { generateId } from '@integrationos/rust-utils';
import { generateId } from '@libs-private/utils';

export const createEventLinkTokenApi = async (
headers: Record<string, string>,
Expand Down Expand Up @@ -75,6 +75,8 @@ export const createEventLinkTokenApi = async (
: platform?.environment === 'test' || !platform?.environment
);

const sessionId = await generateId('session_id');

const tokenPayload = {
linkSettings: {
connectedPlatforms: connectedPlatformsFiltered ?? [],
Expand All @@ -84,7 +86,7 @@ export const createEventLinkTokenApi = async (
label: linkData?.label,
environment: isLiveSecret ? 'live' : 'test',
expiresAt: new Date().getTime() + 5 * 1000 * 60,
sessionId: generateId('session_id'),
sessionId,
features: data?.features
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { useEventAccessService } from '../events/useEventAccessService';
import _ from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { generateEmbedTokensRecord } from '@libs-private/service-logic/generators/embedTokens';
import { generateId } from '@integrationos/rust-utils';
import { generateId } from '@libs-private/utils';

const GET_EVENT_ACCESS_RECORD_URL = process.env.CONNECTIONS_API_BASE_URL + 'v1/event-access';
const CREATE_CONNECTION_URL = process.env.CONNECTIONS_API_BASE_URL + 'v1/connections';
Expand Down Expand Up @@ -55,7 +55,7 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
}: CreateEventLinkPayload): Promise<
BResult<EventLink, 'service', unknown>
> {
const link = generateEventLinkRecord({
const link = await generateEventLinkRecord({
label,
group,
ttl,
Expand Down Expand Up @@ -310,7 +310,7 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
);

// Generate a link record
const link = generateEventLinkRecord({
const link = await generateEventLinkRecord({
label: 'My Connection',
group: `connection-${uuidv4().replace(/-/g, '').substring(0, 10)}`,
ttl: 2 * 1000 * 60 * 60,
Expand Down Expand Up @@ -358,6 +358,8 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
}
);

const sessionId = await generateId('session_id');

const tokenPayload = {
linkSettings: {
connectedPlatforms: connectedPlatforms ?? [],
Expand All @@ -370,10 +372,10 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
? 'test'
: 'live',
features: settings?.features,
sessionId: generateId('session_id'),
sessionId
};

const embedToken = generateEmbedTokensRecord(tokenPayload);
const embedToken = await generateEmbedTokensRecord(tokenPayload);

const { create: createEmbedToken } = useGenericCRUDService(
ctx,
Expand Down Expand Up @@ -429,7 +431,7 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
);

// Generate a link record
const link = generateEventLinkRecord({
const link = await generateEventLinkRecord({
label: 'My Connection',
group: `connection-${uuidv4().replace(/-/g, '').substring(0, 10)}`,
ttl: 2 * 1000 * 60 * 60,
Expand Down Expand Up @@ -475,6 +477,8 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
}
);

const sessionId = await generateId('session_id');

const tokenPayload = {
linkSettings: {
connectedPlatforms: connectedPlatforms ?? [],
Expand All @@ -485,10 +489,10 @@ export const useEventLinksService = (ctx: Context, ownership: Ownership) => {
ttl: 5 * 60 * 1000,
environment: 'test',
features: settings?.features,
sessionId: generateId('session_id'),
sessionId,
};

const embedToken = generateEmbedTokensRecord(tokenPayload);
const embedToken = await generateEmbedTokensRecord(tokenPayload);

const { create: createEmbedToken } = useGenericCRUDService(
ctx,
Expand Down
11 changes: 5 additions & 6 deletions libs-private/service-logic/services/genericCRUD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
} from '@libs-private/data-models';
import { Rename } from '@event-inc/types';
import { Context } from 'moleculer';
import { getCreatedFields, getUpdatedFields } from '../../utils';
import { generateId } from '@integrationos/rust-utils';
import { generateId, getCreatedFields, getUpdatedFields } from '../../utils';
import {
UpdateManyModel,
DeleteManyModel,
Expand All @@ -33,9 +32,9 @@ const addOwnershipToQuery = (
) =>
enabled
? {
...query,
'ownership.buildableId': ownership.buildableId,
}
...query,
'ownership.buildableId': ownership.buildableId,
}
: query;

const handleReturningOnDuplicate = async <T>(
Expand Down Expand Up @@ -158,7 +157,7 @@ export const useGenericCRUDService = (
data: Omit<T, keyof WithCreate | keyof WithId | 'ownership'>,
meta?: unknown
): Promise<BResult<T & WithCreate & WithId & Ownership, 'service'>> {
const _id = generateId(prefix);
const _id = await generateId(prefix);
const fullActionName = `${service}.create`;
const createFields = getCreatedFields();
try {
Expand Down
19 changes: 19 additions & 0 deletions libs-private/utils/ids.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from 'axios';
import { get } from 'lodash';

export const cleanIdPath = (idPath: string) => idPath.replace('_.', '');
Expand Down Expand Up @@ -66,3 +67,21 @@ export const generateKey = ({

return finalizedKeyComponents.join(separator);
};

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

try {
const response = await axios.get<{
id: string
}>(
`${apiBaseUrl}/public/generate-id/${prefix}`
);

const id = response?.data?.id;

return id;
} catch (error) {
throw new Error('Failed to generate id from api');
}
}
62 changes: 1 addition & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/keccak256": "^5.7.0",
"@ethersproject/strings": "^5.7.0",
"@integrationos/rust-utils": "^1.1.3",
"@kubernetes/client-node": "^0.18.1",
"@types/ws": "^8.5.4",
"analytics-node": "^6.2.0",
Expand Down Expand Up @@ -107,4 +106,4 @@
"workspaces": [
"packages/*"
]
}
}
7 changes: 3 additions & 4 deletions packages/connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
"dependencies": {
"@types/ramda": "^0.28.22",
"axios": "^0.26.1",
"jsonwebtoken": "^9.0.1",
"jwt-decode": "^3.1.2",
"lodash.ismatch": "^4.4.0",
"lodash.memoize": "^4.1.2",
"ramda": "^0.28.0",
"tslib": "^2.4.1",
"jsonwebtoken": "^9.0.1",
"jwt-decode": "^3.1.2",
"@integrationos/rust-utils": "^1.1.3"
"tslib": "^2.4.1"
},
"devDependencies": {
"@babel/core": "^7.17.9",
Expand Down
Loading

0 comments on commit a6ac2e3

Please sign in to comment.