prepare sdk packages
This commit is contained in:
@@ -2,12 +2,21 @@ import Script from 'next/script';
|
||||
|
||||
import type {
|
||||
OpenpanelEventOptions,
|
||||
OpenpanelWebOptions,
|
||||
OpenpanelOptions,
|
||||
PostEventPayload,
|
||||
UpdateProfilePayload,
|
||||
} from '@openpanel/web';
|
||||
|
||||
const CDN_URL = 'http://localhost:3002/op.js';
|
||||
const CDN_URL = 'https://openpanel.dev/op.js';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
op: {
|
||||
q?: [string, ...any[]];
|
||||
(method: OpenpanelMethods, ...args: any[]): void;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
type OpenpanelMethods =
|
||||
| 'ctor'
|
||||
@@ -19,7 +28,7 @@ type OpenpanelMethods =
|
||||
| 'clear';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
interface window {
|
||||
op: {
|
||||
q?: [string, ...any[]];
|
||||
(method: OpenpanelMethods, ...args: any[]): void;
|
||||
@@ -27,7 +36,7 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
type OpenpanelProviderProps = OpenpanelWebOptions & {
|
||||
type OpenpanelProviderProps = OpenpanelOptions & {
|
||||
profileId?: string;
|
||||
cdnUrl?: string;
|
||||
};
|
||||
|
||||
@@ -4,13 +4,11 @@
|
||||
"module": "index.ts",
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && tsup",
|
||||
"build-for-openpanel": "pnpm build && cp dist/cdn.global.js ../../apps/public/public/op.js && cp dist/cdn.global.js ../../apps/test/public/op.js",
|
||||
"lint": "eslint .",
|
||||
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@openpanel/sdk": "workspace:*",
|
||||
"@openpanel/web": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
@@ -20,6 +18,7 @@
|
||||
"@openpanel/eslint-config": "workspace:*",
|
||||
"@openpanel/prettier-config": "workspace:*",
|
||||
"@openpanel/tsconfig": "workspace:*",
|
||||
"@types/react": "^18.2.20",
|
||||
"eslint": "^8.48.0",
|
||||
"prettier": "^3.0.3",
|
||||
"tsup": "^7.2.0",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@openpanel/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ import config from '@openpanel/tsconfig/tsup.config.json' assert { type: 'json'
|
||||
|
||||
export default defineConfig({
|
||||
...(config as any),
|
||||
entry: ['index.ts'],
|
||||
entry: ['index.tsx'],
|
||||
format: ['cjs', 'esm'],
|
||||
});
|
||||
|
||||
@@ -2,13 +2,13 @@ import { AppState, Platform } from 'react-native';
|
||||
import * as Application from 'expo-application';
|
||||
import Constants from 'expo-constants';
|
||||
|
||||
import type { OpenpanelOptions, PostEventPayload } from '@openpanel/sdk';
|
||||
import { Openpanel } from '@openpanel/sdk';
|
||||
import type { OpenpanelBaseOptions, PostEventPayload } from '@openpanel/sdk';
|
||||
import { Openpanel as OpenpanelBase } from '@openpanel/sdk';
|
||||
|
||||
type OpenpanelNativeOptions = OpenpanelOptions;
|
||||
export type OpenpanelOptions = OpenpanelBaseOptions;
|
||||
|
||||
export class OpenpanelNative extends Openpanel<OpenpanelNativeOptions> {
|
||||
constructor(options: OpenpanelNativeOptions) {
|
||||
export class OpenpanelRN extends OpenpanelBase<OpenpanelOptions> {
|
||||
constructor(options: OpenpanelOptions) {
|
||||
super(options);
|
||||
|
||||
this.api.headers['User-Agent'] = Constants.getWebViewUserAgentAsync();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@openpanel/tsconfig/sdk.json",
|
||||
"extends": "@openpanel/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// NEW
|
||||
|
||||
export interface OpenpanelEventOptions {
|
||||
profileId?: string;
|
||||
}
|
||||
@@ -33,7 +31,7 @@ export interface DecrementProfilePayload {
|
||||
value: number;
|
||||
}
|
||||
|
||||
export interface OpenpanelOptions {
|
||||
export interface OpenpanelBaseOptions {
|
||||
url: string;
|
||||
clientId: string;
|
||||
clientSecret?: string;
|
||||
@@ -127,7 +125,9 @@ function createApi(_url: string) {
|
||||
};
|
||||
}
|
||||
|
||||
export class Openpanel<Options extends OpenpanelOptions = OpenpanelOptions> {
|
||||
export class Openpanel<
|
||||
Options extends OpenpanelBaseOptions = OpenpanelBaseOptions,
|
||||
> {
|
||||
public options: Options;
|
||||
public api: ReturnType<typeof createApi>;
|
||||
private state: OpenpanelState = {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
f97a3167-8dc6-4bed-923b-3d118c544006
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@openpanel/tsconfig/sdk.json",
|
||||
"extends": "@openpanel/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { OpenpanelWeb as Openpanel } from './index';
|
||||
import { Openpanel } from './index';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { OpenpanelOptions, PostEventPayload } from '@openpanel/sdk';
|
||||
import { Openpanel } from '@openpanel/sdk';
|
||||
import type { OpenpanelBaseOptions, PostEventPayload } from '@openpanel/sdk';
|
||||
import { Openpanel as OpenpanelBase } from '@openpanel/sdk';
|
||||
|
||||
export * from '@openpanel/sdk';
|
||||
|
||||
export type OpenpanelWebOptions = OpenpanelOptions & {
|
||||
export type OpenpanelOptions = OpenpanelBaseOptions & {
|
||||
trackOutgoingLinks?: boolean;
|
||||
trackScreenViews?: boolean;
|
||||
trackAttributes?: boolean;
|
||||
@@ -16,10 +16,10 @@ function toCamelCase(str: string) {
|
||||
);
|
||||
}
|
||||
|
||||
export class OpenpanelWeb extends Openpanel<OpenpanelWebOptions> {
|
||||
export class Openpanel extends OpenpanelBase<OpenpanelOptions> {
|
||||
private lastPath = '';
|
||||
|
||||
constructor(options: OpenpanelWebOptions) {
|
||||
constructor(options: OpenpanelOptions) {
|
||||
super(options);
|
||||
|
||||
if (!this.isServer()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@openpanel/tsconfig/sdk.json",
|
||||
"extends": "@openpanel/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"incremental": false,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user