OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
remove sdk/types package and move it to main sdk package
Carl-Gerhard Lindesvärd43b2fbe7e417
diff --git a/apps/sdk-api/package.json b/apps/sdk-api/package.jsonindex 21a5ef53b..22d5e6b51 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.tsindex 309049771..9677a6b49 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.tsindex 9fa6f459a..e4edd42a8 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.mjsindex 5d4c34bcc..dc8d3d3b9 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.jsonindex b58777d9a..4e877e612 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.tsdeleted file mode 100644index ce4e8c19e..000000000--- 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.jsonindex 02054a8d9..935d9ef52 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.jsonindex 10709439c..97e8c3ade 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.jsonindex 5afc0ae85..6e45d10fe 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.jsonindex 129d0aea8..9fd49c947 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.jsonindex 79d08091d..adfdf5ec0 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.tsindex 795e742b9..62c898056 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.jsonindex d061e9887..e10ec0ca9 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.tsxindex 2b3e9cf03..f2b396e45 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.jsonindex 4e8a64e50..c0d2b9b4d 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.tsindex 4e6a7b05a..360b62f6d 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.jsonindex 561995601..c13507fce 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.tsindex fa1209089..a8e39f4b1 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<string, unknown> & MixanEventOptions;+}++export interface UpdateProfilePayload {+ profileId: string;+ firstName?: string;+ lastName?: string;+ email?: string;+ avatar?: string;+ properties?: Record<string, unknown>;+}++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.jsonindex 11487d1fc..8761ab3b3 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.mddeleted file mode 100644index e86b59fbf..000000000--- 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.tsdeleted file mode 100644index d3856bf19..000000000--- 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.jsondeleted file mode 100644index 64eff20cb..000000000--- 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.tsdeleted file mode 100644index f228af92b..000000000--- a/packages/types/src/sdk.types.ts+++ /dev/null@@ -1,168 +0,0 @@-export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;-export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;--export type MixanJson = Record<string, any>;--// 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<T> {- result: T;- status: 'ok';-}--// NEW--export interface MixanEventOptions {- profileId?: string;-}--export interface PostEventPayload {- name: string;- timestamp: string;- deviceId?: string;- profileId?: string;- properties?: Record<string, unknown> & 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.jsondeleted file mode 100644index 257bf27ac..000000000--- 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.tsdeleted file mode 100644index f98b6b5be..000000000--- 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.jsonindex 438556327..3c646ce4c 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.yamlindex 1214c6e59..5832d87ee 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.6version: 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.21version: 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.0version: 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.0version: 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.0version: 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.0version: 18.19.17@@ -878,9 +860,6 @@ importers:'@mixan/tsconfig':specifier: workspace:*version: link:../../tooling/typescript- '@mixan/types':- specifier: workspace:*- version: link:../typeseslint:specifier: ^8.48.0version: 8.56.0@@ -918,9 +897,6 @@ importers:'@mixan/tsconfig':specifier: workspace:*version: link:../../tooling/typescript- '@mixan/types':- specifier: workspace:*- version: link:../typeseslint:specifier: ^8.48.0version: 8.56.0@@ -955,9 +931,6 @@ importers:'@mixan/tsconfig':specifier: workspace:*version: link:../../tooling/typescript- '@mixan/types':- specifier: workspace:*- version: link:../typeseslint:specifier: ^8.48.0version: 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([email protected])- 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.0version: 18.19.17diff --git a/tooling/publish/publish.ts b/tooling/publish/publish.tsindex 4d97e4299..b2f5a507e 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);}