remove sdk/types package and move it to main sdk package

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-02-28 11:09:51 +01:00
parent a898cfb14a
commit 43b2fbe7e4
28 changed files with 48 additions and 393 deletions

View File

@@ -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",

View File

@@ -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;

View File

@@ -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<{

View File

@@ -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 },
/**

View File

@@ -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",

View File

@@ -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());
}

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -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;

View File

@@ -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",

View File

@@ -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';

View File

@@ -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",

View File

@@ -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;

View File

@@ -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",

View File

@@ -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;

View File

@@ -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",

View File

@@ -1,13 +0,0 @@
# types
To install dependencies:
```bash
pnpm install
```
To run:
```bash
pnpm run index.ts
```

View File

@@ -1 +0,0 @@
export * from './src/sdk.types';

View File

@@ -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"
}

View File

@@ -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;
}

View File

@@ -1,6 +0,0 @@
{
"extends": "@mixan/tsconfig/sdk.json",
"compilerOptions": {
"outDir": "dist"
}
}

View File

@@ -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'],
});

View File

@@ -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",

63
pnpm-lock.yaml generated
View File

@@ -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

View File

@@ -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);
}