diff --git a/apps/sdk-api/package.json b/apps/sdk-api/package.json index 21a5ef53..22d5e6b5 100644 --- a/apps/sdk-api/package.json +++ b/apps/sdk-api/package.json @@ -29,7 +29,7 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", + "@mixan/sdk": "workspace:*", "@types/ramda": "^0.29.6", "@types/ua-parser-js": "^0.7.39", "@types/uuid": "^9.0.8", diff --git a/apps/sdk-api/src/controllers/event.controller.ts b/apps/sdk-api/src/controllers/event.controller.ts index 30904977..9677a6b4 100644 --- a/apps/sdk-api/src/controllers/event.controller.ts +++ b/apps/sdk-api/src/controllers/event.controller.ts @@ -11,7 +11,7 @@ import type { IServiceCreateEventPayload } from '@mixan/db'; import { createBotEvent, createEvent, getEvents, getSalts } from '@mixan/db'; import type { JobsOptions } from '@mixan/queue'; import { eventsQueue, findJobByPrefix } from '@mixan/queue'; -import type { PostEventPayload } from '@mixan/types'; +import type { PostEventPayload } from '@mixan/sdk'; const SESSION_TIMEOUT = 1000 * 60 * 30; const SESSION_END_TIMEOUT = SESSION_TIMEOUT + 1000; diff --git a/apps/sdk-api/src/controllers/profile.controller.ts b/apps/sdk-api/src/controllers/profile.controller.ts index 9fa6f459..e4edd42a 100644 --- a/apps/sdk-api/src/controllers/profile.controller.ts +++ b/apps/sdk-api/src/controllers/profile.controller.ts @@ -4,10 +4,7 @@ import type { FastifyReply, FastifyRequest } from 'fastify'; import { assocPath, pathOr } from 'ramda'; import { getProfileById, upsertProfile } from '@mixan/db'; -import type { - IncrementProfilePayload, - UpdateProfilePayload, -} from '@mixan/types'; +import type { IncrementProfilePayload, UpdateProfilePayload } from '@mixan/sdk'; export async function updateProfile( request: FastifyRequest<{ diff --git a/apps/test/next.config.mjs b/apps/test/next.config.mjs index 5d4c34bc..dc8d3d3b 100644 --- a/apps/test/next.config.mjs +++ b/apps/test/next.config.mjs @@ -6,12 +6,7 @@ /** @type {import("next").NextConfig} */ const config = { reactStrictMode: false, - transpilePackages: [ - '@mixan/types', - '@mixan/sdk', - '@mixan/web-sdk', - '@mixan/next', - ], + transpilePackages: ['@mixan/sdk', '@mixan/web-sdk', '@mixan/next'], eslint: { ignoreDuringBuilds: true }, typescript: { ignoreBuildErrors: true }, /** diff --git a/apps/web/package.json b/apps/web/package.json index b58777d9..4e877e61 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -20,7 +20,6 @@ "@mixan/constants": "workspace:^", "@mixan/db": "workspace:^", "@mixan/queue": "workspace:^", - "@mixan/types": "workspace:*", "@mixan/validation": "workspace:^", "@radix-ui/react-accordion": "^1.1.2", "@radix-ui/react-alert-dialog": "^1.0.5", diff --git a/apps/web/src/server/exceptions.ts b/apps/web/src/server/exceptions.ts deleted file mode 100644 index ce4e8c19..00000000 --- a/apps/web/src/server/exceptions.ts +++ /dev/null @@ -1,57 +0,0 @@ -import type { NextApiResponse } from 'next'; - -import type { MixanErrorResponse, MixanIssue } from '@mixan/types'; - -export class HttpError extends Error { - public status: number; - public message: string; - public issues: MixanIssue[]; - - constructor(status: number, message: string | Error, issues?: MixanIssue[]) { - super(message instanceof Error ? message.message : message); - this.status = status; - this.message = message instanceof Error ? message.message : message; - this.issues = issues ?? []; - } - - toJson(): MixanErrorResponse { - return { - code: this.status, - status: 'error', - message: this.message, - issues: this.issues.length ? this.issues : undefined, - stack: process.env.NODE_ENV !== 'production' ? this.stack : undefined, - }; - } -} - -export function createIssues(arr: MixanIssue[]) { - throw new HttpError(400, 'Issues', arr); -} - -export function createError(status = 500, error: unknown) { - if (error instanceof Error || typeof error === 'string') { - return new HttpError(status, error); - } - - return new HttpError(500, 'Unexpected error occured'); -} - -export function handleError(res: NextApiResponse, error: unknown) { - console.log('-----------------'); - console.log('ERROR'); - console.log(error); - console.log('-----------------'); - - if (error instanceof HttpError) { - return res.status(error.status).json(error.toJson()); - } - - if (error instanceof Error) { - const httpError = createError(500, error); - return res.status(httpError.status).json(httpError.toJson()); - } - - const httpError = createError(500, error); - return res.status(httpError.status).json(httpError.toJson()); -} diff --git a/apps/worker/package.json b/apps/worker/package.json index 02054a8d..935d9ef5 100644 --- a/apps/worker/package.json +++ b/apps/worker/package.json @@ -25,7 +25,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "@types/express": "^4.17.21", "@types/ramda": "^0.29.6", "eslint": "^8.48.0", diff --git a/packages/common/package.json b/packages/common/package.json index 10709439..97e8c3ad 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -15,7 +15,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "@types/node": "^18.16.0", "@types/ramda": "^0.29.6", "eslint": "^8.48.0", diff --git a/packages/db/package.json b/packages/db/package.json index 5afc0ae8..6e45d10f 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -26,7 +26,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "@types/node": "^18.16.0", "@types/ramda": "^0.29.6", "@types/uuid": "^9.0.8", diff --git a/packages/queue/package.json b/packages/queue/package.json index 129d0aea..9fd49c94 100644 --- a/packages/queue/package.json +++ b/packages/queue/package.json @@ -15,7 +15,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "@types/node": "^18.16.0", "eslint": "^8.48.0", "prettier": "^3.0.3", diff --git a/packages/redis/package.json b/packages/redis/package.json index 79d08091..adfdf5ec 100644 --- a/packages/redis/package.json +++ b/packages/redis/package.json @@ -15,7 +15,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "@types/node": "^18.16.0", "eslint": "^8.48.0", "prettier": "^3.0.3", diff --git a/packages/sdk-native/index.ts b/packages/sdk-native/index.ts index 795e742b..62c89805 100644 --- a/packages/sdk-native/index.ts +++ b/packages/sdk-native/index.ts @@ -2,9 +2,8 @@ import { AppState, Platform } from 'react-native'; import * as Application from 'expo-application'; import Constants from 'expo-constants'; -import type { MixanOptions } from '@mixan/sdk'; +import type { MixanOptions, PostEventPayload } from '@mixan/sdk'; import { Mixan } from '@mixan/sdk'; -import type { PostEventPayload } from '@mixan/types'; type MixanNativeOptions = MixanOptions; diff --git a/packages/sdk-native/package.json b/packages/sdk-native/package.json index d061e988..e10ec0ca 100644 --- a/packages/sdk-native/package.json +++ b/packages/sdk-native/package.json @@ -15,7 +15,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "eslint": "^8.48.0", "prettier": "^3.0.3", "tsup": "^7.2.0", diff --git a/packages/sdk-next/index.tsx b/packages/sdk-next/index.tsx index 2b3e9cf0..f2b396e4 100644 --- a/packages/sdk-next/index.tsx +++ b/packages/sdk-next/index.tsx @@ -1,11 +1,11 @@ import Script from 'next/script'; -import type { MixanWebOptions } from '@mixan/sdk-web'; import type { MixanEventOptions, + MixanWebOptions, PostEventPayload, UpdateProfilePayload, -} from '@mixan/types'; +} from '@mixan/sdk-web'; const CDN_URL = 'http://localhost:3002/op.js'; diff --git a/packages/sdk-next/package.json b/packages/sdk-next/package.json index 4e8a64e5..c0d2b9b4 100644 --- a/packages/sdk-next/package.json +++ b/packages/sdk-next/package.json @@ -20,7 +20,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "eslint": "^8.48.0", "prettier": "^3.0.3", "tsup": "^7.2.0", diff --git a/packages/sdk-web/index.ts b/packages/sdk-web/index.ts index 4e6a7b05..360b62f6 100644 --- a/packages/sdk-web/index.ts +++ b/packages/sdk-web/index.ts @@ -1,6 +1,7 @@ -import type { MixanOptions } from '@mixan/sdk'; +import type { MixanOptions, PostEventPayload } from '@mixan/sdk'; import { Mixan } from '@mixan/sdk'; -import type { PostEventPayload } from '@mixan/types'; + +export * from '@mixan/sdk'; export type MixanWebOptions = MixanOptions & { trackOutgoingLinks?: boolean; diff --git a/packages/sdk-web/package.json b/packages/sdk-web/package.json index 56199560..c13507fc 100644 --- a/packages/sdk-web/package.json +++ b/packages/sdk-web/package.json @@ -16,7 +16,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "eslint": "^8.48.0", "prettier": "^3.0.3", "tsup": "^7.2.0", diff --git a/packages/sdk/index.ts b/packages/sdk/index.ts index fa120908..a8e39f4b 100644 --- a/packages/sdk/index.ts +++ b/packages/sdk/index.ts @@ -1,10 +1,37 @@ -import type { - DecrementProfilePayload, - IncrementProfilePayload, - MixanEventOptions, - PostEventPayload, - UpdateProfilePayload, -} from '@mixan/types'; +// NEW + +export interface MixanEventOptions { + profileId?: string; +} + +export interface PostEventPayload { + name: string; + timestamp: string; + deviceId?: string; + profileId?: string; + properties?: Record & MixanEventOptions; +} + +export interface UpdateProfilePayload { + profileId: string; + firstName?: string; + lastName?: string; + email?: string; + avatar?: string; + properties?: Record; +} + +export interface IncrementProfilePayload { + profileId: string; + property: string; + value: number; +} + +export interface DecrementProfilePayload { + profileId?: string; + property: string; + value: number; +} export interface MixanOptions { url: string; diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 11487d1f..8761ab3b 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -13,7 +13,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "eslint": "^8.48.0", "prettier": "^3.0.3", "tsup": "^7.2.0", diff --git a/packages/types/README.md b/packages/types/README.md deleted file mode 100644 index e86b59fb..00000000 --- a/packages/types/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# types - -To install dependencies: - -```bash -pnpm install -``` - -To run: - -```bash -pnpm run index.ts -``` diff --git a/packages/types/index.ts b/packages/types/index.ts deleted file mode 100644 index d3856bf1..00000000 --- a/packages/types/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './src/sdk.types'; diff --git a/packages/types/package.json b/packages/types/package.json deleted file mode 100644 index 64eff20c..00000000 --- a/packages/types/package.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "@mixan/types", - "version": "0.0.1", - "module": "index.ts", - "scripts": { - "build": "rm -rf dist && tsup", - "lint": "eslint .", - "format": "prettier --check \"**/*.{mjs,ts,md,json}\"", - "typecheck": "tsc --noEmit" - }, - "devDependencies": { - "@mixan/eslint-config": "workspace:*", - "@mixan/prettier-config": "workspace:*", - "@mixan/tsconfig": "workspace:*", - "eslint": "^8.48.0", - "prettier": "^3.0.3", - "tsup": "^7.2.0", - "typescript": "^5.2.2" - }, - "eslintConfig": { - "root": true, - "extends": [ - "@mixan/eslint-config/base" - ] - }, - "prettier": "@mixan/prettier-config" -} diff --git a/packages/types/src/sdk.types.ts b/packages/types/src/sdk.types.ts deleted file mode 100644 index f228af92..00000000 --- a/packages/types/src/sdk.types.ts +++ /dev/null @@ -1,168 +0,0 @@ -export type Omit = Pick>; -export type PartialBy = Omit & Partial>; - -export type MixanJson = Record; - -// Deprecated -export interface EventPayload { - name: string; - time: string; - profileId: string | null; - properties: MixanJson; -} - -// Deprecated -export interface ProfilePayload { - first_name?: string; - last_name?: string; - email?: string; - avatar?: string; - id?: string; - properties?: MixanJson; -} - -export type BatchPayload = - | { - type: 'increment'; - payload: BatchProfileIncrementPayload; - } - | { - type: 'decrement'; - payload: BatchProfileDecrementPayload; - } - | { - type: 'event'; - payload: BatchEventPayload; - } - | { - type: 'create_profile'; - payload: BatchCreateProfilePayload; - } - | { - type: 'update_profile'; - payload: BatchUpdateProfilePayload; - } - | { - type: 'update_session'; - payload: BatchUpdateSessionPayload; - } - | { - type: 'set_profile_property'; - payload: BatchSetProfilePropertyPayload; - }; - -export interface BatchSetProfilePropertyPayload { - profileId: string; - name: string; - value: any; - update: boolean; -} - -export interface CreateProfileResponse { - id: string; -} - -export interface BatchCreateProfilePayload { - profileId: string; - properties?: MixanJson; -} - -export interface BatchUpdateSessionPayload { - profileId: string; - properties?: MixanJson; -} - -export interface BatchEventPayload { - name: string; - time: string; - profileId: string; - properties: MixanJson; -} - -export interface BatchUpdateProfilePayload { - first_name?: string; - last_name?: string; - email?: string; - avatar?: string; - id?: string; - properties?: MixanJson; - profileId: string; -} - -export interface ProfileIncrementPayload { - name: string; - value: number; - profileId: string; -} - -export interface ProfileDecrementPayload { - name: string; - value: number; - profileId: string; -} - -export interface BatchProfileIncrementPayload { - name: string; - value: number; - profileId: string; -} - -export interface BatchProfileDecrementPayload { - name: string; - value: number; - profileId: string; -} - -export interface MixanIssue { - field: string; - message: string; - value: any; -} - -export interface MixanErrorResponse { - status: 'error'; - code: number; - message: string; - issues?: MixanIssue[] | undefined; - stack?: string | undefined; -} - -export interface MixanResponse { - result: T; - status: 'ok'; -} - -// NEW - -export interface MixanEventOptions { - profileId?: string; -} - -export interface PostEventPayload { - name: string; - timestamp: string; - deviceId?: string; - profileId?: string; - properties?: Record & MixanEventOptions; -} - -export interface UpdateProfilePayload { - profileId: string; - firstName?: string; - lastName?: string; - email?: string; - avatar?: string; - properties?: MixanJson; -} - -export interface IncrementProfilePayload { - profileId: string; - property: string; - value: number; -} - -export interface DecrementProfilePayload { - profileId?: string; - property: string; - value: number; -} diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json deleted file mode 100644 index 257bf27a..00000000 --- a/packages/types/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "@mixan/tsconfig/sdk.json", - "compilerOptions": { - "outDir": "dist" - } -} diff --git a/packages/types/tsup.config.ts b/packages/types/tsup.config.ts deleted file mode 100644 index f98b6b5b..00000000 --- a/packages/types/tsup.config.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { defineConfig } from 'tsup'; - -import config from '@mixan/tsconfig/tsup.config.json' assert { type: 'json' }; - -export default defineConfig({ - ...(config as any), - entry: ['index.ts', 'cdn.ts'], - format: ['cjs', 'esm', 'iife'], -}); diff --git a/packages/validation/package.json b/packages/validation/package.json index 43855632..3c646ce4 100644 --- a/packages/validation/package.json +++ b/packages/validation/package.json @@ -15,7 +15,6 @@ "@mixan/eslint-config": "workspace:*", "@mixan/prettier-config": "workspace:*", "@mixan/tsconfig": "workspace:*", - "@mixan/types": "workspace:*", "@types/node": "^18.16.0", "eslint": "^8.48.0", "prettier": "^3.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1214c6e5..5832d87e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -211,12 +211,12 @@ importers: '@mixan/prettier-config': specifier: workspace:* version: link:../../tooling/prettier + '@mixan/sdk': + specifier: workspace:* + version: link:../../packages/sdk '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../../packages/types '@types/ramda': specifier: ^0.29.6 version: 0.29.10 @@ -332,9 +332,6 @@ importers: '@mixan/queue': specifier: workspace:^ version: link:../../packages/queue - '@mixan/types': - specifier: workspace:* - version: link:../../packages/types '@mixan/validation': specifier: workspace:^ version: link:../../packages/validation @@ -646,9 +643,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../../packages/types '@types/express': specifier: ^4.17.21 version: 4.17.21 @@ -686,9 +680,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types '@types/node': specifier: ^18.16.0 version: 18.19.17 @@ -774,9 +765,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types '@types/node': specifier: ^18.16.0 version: 18.19.17 @@ -817,9 +805,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types '@types/node': specifier: ^18.16.0 version: 18.19.17 @@ -848,9 +833,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types '@types/node': specifier: ^18.16.0 version: 18.19.17 @@ -878,9 +860,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types eslint: specifier: ^8.48.0 version: 8.56.0 @@ -918,9 +897,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types eslint: specifier: ^8.48.0 version: 8.56.0 @@ -955,9 +931,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types eslint: specifier: ^8.48.0 version: 8.56.0 @@ -976,33 +949,6 @@ importers: '@mixan/sdk': specifier: workspace:* version: link:../sdk - devDependencies: - '@mixan/eslint-config': - specifier: workspace:* - version: link:../../tooling/eslint - '@mixan/prettier-config': - specifier: workspace:* - version: link:../../tooling/prettier - '@mixan/tsconfig': - specifier: workspace:* - version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types - eslint: - specifier: ^8.48.0 - version: 8.56.0 - prettier: - specifier: ^3.0.3 - version: 3.2.5 - tsup: - specifier: ^7.2.0 - version: 7.3.0(typescript@5.3.3) - typescript: - specifier: ^5.2.2 - version: 5.3.3 - - packages/types: devDependencies: '@mixan/eslint-config': specifier: workspace:* @@ -1044,9 +990,6 @@ importers: '@mixan/tsconfig': specifier: workspace:* version: link:../../tooling/typescript - '@mixan/types': - specifier: workspace:* - version: link:../types '@types/node': specifier: ^18.16.0 version: 18.19.17 diff --git a/tooling/publish/publish.ts b/tooling/publish/publish.ts index 4d97e429..b2f5a507 100644 --- a/tooling/publish/publish.ts +++ b/tooling/publish/publish.ts @@ -4,9 +4,7 @@ import fs from 'node:fs'; import path from 'node:path'; import semver from 'semver'; -import typesPkg from '../../packages/types/package.json'; - -const sdkPackages = ['sdk', 'sdk-native', 'sdk-web']; +const sdkPackages = ['sdk', 'sdk-native', 'sdk-web', 'sdk-next']; // const sdkPackages = ['sdk']; const workspacePath = (relativePath: string) => @@ -53,11 +51,6 @@ function main() { }; try { - savePackageJson(workspacePath('./packages/types/package.json'), { - ...typesPkg, - ...properties, - }); - for (const name of sdkPackages) { const pkgJson = require(workspacePath(`./packages/${name}/package.json`)); savePackageJson(workspacePath(`./packages/${name}/package.json`), { @@ -79,10 +72,6 @@ function main() { console.log('✅ Update JSON files'); try { - execSync('pnpm build', { - cwd: workspacePath(`./packages/types`), - }); - for (const name of sdkPackages) { execSync('pnpm build', { cwd: workspacePath(`./packages/${name}`), @@ -100,10 +89,6 @@ function main() { cwd: workspacePath(`./packages/${name}`), }); } - - execSync('npm publish --access=public', { - cwd: workspacePath('./packages/types'), - }); } catch (error) { exit('Failed publish packages', error); }