prepare sdk packages
This commit is contained in:
@@ -2,12 +2,21 @@ import Script from 'next/script';
|
|||||||
|
|
||||||
import type {
|
import type {
|
||||||
OpenpanelEventOptions,
|
OpenpanelEventOptions,
|
||||||
OpenpanelWebOptions,
|
OpenpanelOptions,
|
||||||
PostEventPayload,
|
PostEventPayload,
|
||||||
UpdateProfilePayload,
|
UpdateProfilePayload,
|
||||||
} from '@openpanel/web';
|
} 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 =
|
type OpenpanelMethods =
|
||||||
| 'ctor'
|
| 'ctor'
|
||||||
@@ -19,7 +28,7 @@ type OpenpanelMethods =
|
|||||||
| 'clear';
|
| 'clear';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface window {
|
||||||
op: {
|
op: {
|
||||||
q?: [string, ...any[]];
|
q?: [string, ...any[]];
|
||||||
(method: OpenpanelMethods, ...args: any[]): void;
|
(method: OpenpanelMethods, ...args: any[]): void;
|
||||||
@@ -27,7 +36,7 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenpanelProviderProps = OpenpanelWebOptions & {
|
type OpenpanelProviderProps = OpenpanelOptions & {
|
||||||
profileId?: string;
|
profileId?: string;
|
||||||
cdnUrl?: string;
|
cdnUrl?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,13 +4,11 @@
|
|||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf dist && tsup",
|
"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 .",
|
"lint": "eslint .",
|
||||||
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
|
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openpanel/sdk": "workspace:*",
|
|
||||||
"@openpanel/web": "workspace:*"
|
"@openpanel/web": "workspace:*"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
@@ -20,6 +18,7 @@
|
|||||||
"@openpanel/eslint-config": "workspace:*",
|
"@openpanel/eslint-config": "workspace:*",
|
||||||
"@openpanel/prettier-config": "workspace:*",
|
"@openpanel/prettier-config": "workspace:*",
|
||||||
"@openpanel/tsconfig": "workspace:*",
|
"@openpanel/tsconfig": "workspace:*",
|
||||||
|
"@types/react": "^18.2.20",
|
||||||
"eslint": "^8.48.0",
|
"eslint": "^8.48.0",
|
||||||
"prettier": "^3.0.3",
|
"prettier": "^3.0.3",
|
||||||
"tsup": "^7.2.0",
|
"tsup": "^7.2.0",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "@openpanel/tsconfig/base.json",
|
"extends": "@openpanel/tsconfig/base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"incremental": false,
|
||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ import config from '@openpanel/tsconfig/tsup.config.json' assert { type: 'json'
|
|||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
...(config as any),
|
...(config as any),
|
||||||
entry: ['index.ts'],
|
entry: ['index.tsx'],
|
||||||
format: ['cjs', 'esm'],
|
format: ['cjs', 'esm'],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import { AppState, Platform } from 'react-native';
|
|||||||
import * as Application from 'expo-application';
|
import * as Application from 'expo-application';
|
||||||
import Constants from 'expo-constants';
|
import Constants from 'expo-constants';
|
||||||
|
|
||||||
import type { OpenpanelOptions, PostEventPayload } from '@openpanel/sdk';
|
import type { OpenpanelBaseOptions, PostEventPayload } from '@openpanel/sdk';
|
||||||
import { Openpanel } from '@openpanel/sdk';
|
import { Openpanel as OpenpanelBase } from '@openpanel/sdk';
|
||||||
|
|
||||||
type OpenpanelNativeOptions = OpenpanelOptions;
|
export type OpenpanelOptions = OpenpanelBaseOptions;
|
||||||
|
|
||||||
export class OpenpanelNative extends Openpanel<OpenpanelNativeOptions> {
|
export class OpenpanelRN extends OpenpanelBase<OpenpanelOptions> {
|
||||||
constructor(options: OpenpanelNativeOptions) {
|
constructor(options: OpenpanelOptions) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
this.api.headers['User-Agent'] = Constants.getWebViewUserAgentAsync();
|
this.api.headers['User-Agent'] = Constants.getWebViewUserAgentAsync();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "@openpanel/tsconfig/sdk.json",
|
"extends": "@openpanel/tsconfig/base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"incremental": false,
|
||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// NEW
|
|
||||||
|
|
||||||
export interface OpenpanelEventOptions {
|
export interface OpenpanelEventOptions {
|
||||||
profileId?: string;
|
profileId?: string;
|
||||||
}
|
}
|
||||||
@@ -33,7 +31,7 @@ export interface DecrementProfilePayload {
|
|||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OpenpanelOptions {
|
export interface OpenpanelBaseOptions {
|
||||||
url: string;
|
url: string;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
clientSecret?: 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 options: Options;
|
||||||
public api: ReturnType<typeof createApi>;
|
public api: ReturnType<typeof createApi>;
|
||||||
private state: OpenpanelState = {
|
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": {
|
"compilerOptions": {
|
||||||
|
"incremental": false,
|
||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { OpenpanelWeb as Openpanel } from './index';
|
import { Openpanel } from './index';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { OpenpanelOptions, PostEventPayload } from '@openpanel/sdk';
|
import type { OpenpanelBaseOptions, PostEventPayload } from '@openpanel/sdk';
|
||||||
import { Openpanel } from '@openpanel/sdk';
|
import { Openpanel as OpenpanelBase } from '@openpanel/sdk';
|
||||||
|
|
||||||
export * from '@openpanel/sdk';
|
export * from '@openpanel/sdk';
|
||||||
|
|
||||||
export type OpenpanelWebOptions = OpenpanelOptions & {
|
export type OpenpanelOptions = OpenpanelBaseOptions & {
|
||||||
trackOutgoingLinks?: boolean;
|
trackOutgoingLinks?: boolean;
|
||||||
trackScreenViews?: boolean;
|
trackScreenViews?: boolean;
|
||||||
trackAttributes?: 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 = '';
|
private lastPath = '';
|
||||||
|
|
||||||
constructor(options: OpenpanelWebOptions) {
|
constructor(options: OpenpanelOptions) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
if (!this.isServer()) {
|
if (!this.isServer()) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "@openpanel/tsconfig/sdk.json",
|
"extends": "@openpanel/tsconfig/base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"incremental": false,
|
||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@@ -924,9 +924,6 @@ importers:
|
|||||||
|
|
||||||
packages/sdks/nextjs:
|
packages/sdks/nextjs:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@openpanel/sdk':
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../sdk
|
|
||||||
'@openpanel/web':
|
'@openpanel/web':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../web
|
version: link:../web
|
||||||
@@ -943,6 +940,9 @@ importers:
|
|||||||
'@openpanel/tsconfig':
|
'@openpanel/tsconfig':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../../tooling/typescript
|
version: link:../../../tooling/typescript
|
||||||
|
'@types/react':
|
||||||
|
specifier: ^18.2.20
|
||||||
|
version: 18.2.56
|
||||||
eslint:
|
eslint:
|
||||||
specifier: ^8.48.0
|
specifier: ^8.48.0
|
||||||
version: 8.56.0
|
version: 8.56.0
|
||||||
@@ -1152,6 +1152,9 @@ importers:
|
|||||||
|
|
||||||
tooling/publish:
|
tooling/publish:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
arg:
|
||||||
|
specifier: ^5.0.2
|
||||||
|
version: 5.0.2
|
||||||
semver:
|
semver:
|
||||||
specifier: ^7.5.4
|
specifier: ^7.5.4
|
||||||
version: 7.6.0
|
version: 7.6.0
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"arg": "^5.0.2",
|
||||||
"semver": "^7.5.4"
|
"semver": "^7.5.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
import { execSync } from 'node:child_process';
|
import { execSync } from 'node:child_process';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
import arg from 'arg';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
const sdkPackages = ['sdk', 'react-native', 'web', 'nextjs'];
|
const sdkPackages = ['sdk', 'react-native', 'web', 'nextjs'];
|
||||||
@@ -25,13 +25,18 @@ function exit(message: string, error?: unknown) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
const [version] = process.argv.slice(2);
|
const args = arg({
|
||||||
|
// Types
|
||||||
|
'--version': String,
|
||||||
|
'--test': Boolean,
|
||||||
|
// Aliases
|
||||||
|
'-v': '--version',
|
||||||
|
});
|
||||||
|
|
||||||
if (!version) {
|
const version = args['--version'];
|
||||||
return console.error('Missing version');
|
const test = args['--test'];
|
||||||
}
|
|
||||||
|
|
||||||
if (!semver.valid(version)) {
|
if (version && !semver.valid(version)) {
|
||||||
return console.error('Version is not valid');
|
return console.error('Version is not valid');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +56,10 @@ function main() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for (const name of sdkPackages) {
|
for (const name of sdkPackages) {
|
||||||
const pkgJson = require(workspacePath(`./packages/${name}/package.json`));
|
const pkgJson = require(
|
||||||
savePackageJson(workspacePath(`./packages/${name}/package.json`), {
|
workspacePath(`./packages/sdks/${name}/package.json`)
|
||||||
|
);
|
||||||
|
savePackageJson(workspacePath(`./packages/sdks/${name}/package.json`), {
|
||||||
...pkgJson,
|
...pkgJson,
|
||||||
...properties,
|
...properties,
|
||||||
dependencies: Object.entries(pkgJson.dependencies).reduce(
|
dependencies: Object.entries(pkgJson.dependencies).reduce(
|
||||||
@@ -82,14 +89,16 @@ function main() {
|
|||||||
|
|
||||||
console.log('✅ Built packages');
|
console.log('✅ Built packages');
|
||||||
|
|
||||||
try {
|
if (!test) {
|
||||||
for (const name of sdkPackages) {
|
try {
|
||||||
execSync('npm publish --access=public', {
|
for (const name of sdkPackages) {
|
||||||
cwd: workspacePath(`./packages/${name}`),
|
execSync('npm publish --access=public', {
|
||||||
});
|
cwd: workspacePath(`./packages/sdks/${name}`),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
exit('Failed publish packages', error);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
exit('Failed publish packages', error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('✅ All done!');
|
console.log('✅ All done!');
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://json.schemastore.org/tsconfig",
|
|
||||||
"compilerOptions": {
|
|
||||||
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
||||||
"module": "esnext",
|
|
||||||
"target": "esnext",
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"moduleDetection": "force",
|
|
||||||
"composite": false,
|
|
||||||
"strict": true,
|
|
||||||
"downlevelIteration": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"jsx": "react-jsx",
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"allowJs": true,
|
|
||||||
"allowImportingTsExtensions": false,
|
|
||||||
"noEmit": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user