Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/proxy",
"version": "0.2.1",
"version": "0.2.2",
"description": "A CLI tool to run an Express server that proxies CRUD requests to a ZenStack backend",
"main": "index.js",
"publishConfig": {
Expand Down Expand Up @@ -33,7 +33,8 @@
"express": "^4.19.2",
"mixpanel": "^0.19.1",
"semver": "^7.7.3",
"tsx": "^4.20.6"
"tsx": "^4.20.6",
"uuid": "^13.0.0"
},
"devDependencies": {
"@types/cors": "^2.8.17",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'dotenv/config'
import { getVersion } from './utils/version-utils'
import { telemetry } from './telemetry'
import { CliError } from './cli-error'

export function createProgram() {
const program = new Command()

Expand All @@ -32,7 +31,7 @@ export function createProgram() {
: path.join(process.cwd(), options.schema)

if (!fs.existsSync(zmodelPath)) {
console.error(`Error: ZModel schema file not found: ${zmodelPath}`)
console.error(`ZModel schema file not found: ${zmodelPath}`)
console.error('Please provide a valid path using the -s option.')
process.exit(1)
}
Expand Down
9 changes: 8 additions & 1 deletion src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import isDocker from './utils/is-docker'
import { isWsl } from './utils/is-wsl'
import { getMachineId } from './utils/machine-id-utils'
import { getPrismaVersion, getVersion } from './utils/version-utils'
import { v5 as uuidv5 } from 'uuid'

/**
* Telemetry events
Expand All @@ -18,7 +19,7 @@ export type TelemetryEvents = 'proxy:start' | 'proxy:complete' | 'proxy:error'
*/
export class Telemetry {
private readonly mixpanel: Mixpanel | undefined
private readonly hostId = getMachineId()
private readonly hostId = this.getDeviceId()
private readonly sessionid = randomUUID()
private readonly _os_type = os.type()
private readonly _os_release = os.release()
Expand All @@ -40,6 +41,12 @@ export class Telemetry {
}
}

private getDeviceId() {
const hostId = getMachineId()
// namespace UUID for generating UUIDv5 from DNS 'zenstack.dev'
return uuidv5(hostId, '133cac15-3efb-50fa-b5fc-4b90e441e563')
}

get isTracking() {
return !!this.mixpanel
}
Expand Down
12 changes: 5 additions & 7 deletions src/utils/machine-id-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// modified from https://github.com/automation-stack/node-machine-id

import { execSync } from 'child_process'
import { createHash, randomUUID } from 'node:crypto'
import { createHash } from 'node:crypto'
import { v4 as uuid } from 'uuid'

const { platform } = process
const win32RegBinPath = {
Expand Down Expand Up @@ -31,7 +32,7 @@ function hash(guid: string): string {
return createHash('sha256').update(guid).digest('hex')
}

function expose(result: string): string | undefined {
function expose(result: string): string {
switch (platform) {
case 'darwin':
return result
Expand Down Expand Up @@ -62,16 +63,13 @@ function expose(result: string): string | undefined {

export function getMachineId() {
if (!(platform in guid)) {
return randomUUID()
return uuid()
}
try {
const value = execSync(guid[platform as keyof typeof guid])
const id = expose(value.toString())
if (!id) {
return randomUUID()
}
return hash(id)
} catch {
return randomUUID()
return uuid()
}
}
4 changes: 3 additions & 1 deletion src/zmodel-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ function parseGenerator(content: string): GeneratorConfig {
// Match generator block for prisma client
const generatorMatch = content.match(/generator\s+\w+\s*\{([^}]+)\}/s)
if (!generatorMatch) {
throw new CliError('No generator block found in zmodel schema')
throw new CliError(
'No generator block found in zmodel schema.\nZenStack V3 is not supported, V3 will have built-in proxy support soon.'
)
}

const generatorBlock = generatorMatch[1]
Expand Down
Loading