datajam 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +44 -0
- package/dist/chunk-NASQ6YYH.js +68 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +12 -0
- package/package.json +37 -0
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
DataJam
|
|
4
|
+
} from "./chunk-NASQ6YYH.js";
|
|
5
|
+
|
|
6
|
+
// src/bin.ts
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
async function run() {
|
|
9
|
+
const program = new Command();
|
|
10
|
+
program.name("datajam").description("Local-first Stripe analytics SDK CLI");
|
|
11
|
+
program.command("init").description("Initialize datajam in this project").action(async () => {
|
|
12
|
+
const datajam = new DataJam();
|
|
13
|
+
await datajam.init();
|
|
14
|
+
console.info("DataJam initialized.");
|
|
15
|
+
});
|
|
16
|
+
program.command("sync").description("Run sync against Stripe").option("--full", "Run full sync").action(async (options) => {
|
|
17
|
+
const datajam = new DataJam();
|
|
18
|
+
const result = await datajam.sync({ full: options.full });
|
|
19
|
+
const fetchedTotal = result.resources.reduce((acc, item) => acc + item.fetched, 0);
|
|
20
|
+
console.info(
|
|
21
|
+
`Sync completed: ${result.mode} (${fetchedTotal} records fetched)`
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
program.command("dashboard").description("Start local dashboard server").option("--port <port>", "Dashboard port", "3210").action(async (options) => {
|
|
25
|
+
const datajam = new DataJam();
|
|
26
|
+
const dashboard = await datajam.dashboard({ port: Number(options.port) });
|
|
27
|
+
console.info(`Dashboard available at ${dashboard.url}`);
|
|
28
|
+
});
|
|
29
|
+
program.command("doctor").description("Run local diagnostics").action(async () => {
|
|
30
|
+
const datajam = new DataJam();
|
|
31
|
+
const report = await datajam.doctor();
|
|
32
|
+
const status = report.ok ? "OK" : "FAILED";
|
|
33
|
+
console.info(`Doctor status: ${status}`);
|
|
34
|
+
for (const check of report.checks) {
|
|
35
|
+
console.info(`- [${check.ok ? "ok" : "x"}] ${check.name}: ${check.message}`);
|
|
36
|
+
}
|
|
37
|
+
process.exitCode = report.ok ? 0 : 1;
|
|
38
|
+
});
|
|
39
|
+
await program.parseAsync(process.argv);
|
|
40
|
+
}
|
|
41
|
+
run().catch((error) => {
|
|
42
|
+
console.error(error);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { AnalyticsService } from "@datajam/analytics";
|
|
3
|
+
import { StripeConnector } from "@datajam/connector-stripe";
|
|
4
|
+
import {
|
|
5
|
+
DataJamCore,
|
|
6
|
+
ensureDataJamDirectory,
|
|
7
|
+
loadRuntimeConfig,
|
|
8
|
+
writeDefaultConfigFile
|
|
9
|
+
} from "@datajam/core";
|
|
10
|
+
import { startDashboardServer } from "@datajam/dashboard";
|
|
11
|
+
import { SqliteStorageAdapter } from "@datajam/storage-sqlite";
|
|
12
|
+
var DataJam = class {
|
|
13
|
+
options;
|
|
14
|
+
core = null;
|
|
15
|
+
storage = null;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
async init() {
|
|
20
|
+
const core = await this.getCore();
|
|
21
|
+
await core.init();
|
|
22
|
+
}
|
|
23
|
+
async sync(input = {}) {
|
|
24
|
+
const core = await this.getCore();
|
|
25
|
+
return core.sync(input);
|
|
26
|
+
}
|
|
27
|
+
async dashboard(input = {}) {
|
|
28
|
+
const core = await this.getCore();
|
|
29
|
+
return core.dashboard(input);
|
|
30
|
+
}
|
|
31
|
+
async start() {
|
|
32
|
+
const core = await this.getCore();
|
|
33
|
+
return core.start();
|
|
34
|
+
}
|
|
35
|
+
async doctor() {
|
|
36
|
+
const core = await this.getCore();
|
|
37
|
+
return core.doctor();
|
|
38
|
+
}
|
|
39
|
+
async getCore() {
|
|
40
|
+
if (this.core) {
|
|
41
|
+
return this.core;
|
|
42
|
+
}
|
|
43
|
+
const config = await loadRuntimeConfig(this.options);
|
|
44
|
+
await writeDefaultConfigFile(config.projectDir);
|
|
45
|
+
await ensureDataJamDirectory(config.projectDir);
|
|
46
|
+
this.storage = new SqliteStorageAdapter({
|
|
47
|
+
databasePath: config.storage.sqlitePath
|
|
48
|
+
});
|
|
49
|
+
const connector = new StripeConnector({
|
|
50
|
+
apiKey: config.stripeSecretKey ?? ""
|
|
51
|
+
});
|
|
52
|
+
const analytics = new AnalyticsService(this.storage);
|
|
53
|
+
this.core = new DataJamCore(config, {
|
|
54
|
+
connector,
|
|
55
|
+
storage: this.storage,
|
|
56
|
+
analytics,
|
|
57
|
+
dashboardStarter: startDashboardServer
|
|
58
|
+
});
|
|
59
|
+
return this.core;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
ensureDataJamDirectory,
|
|
65
|
+
loadRuntimeConfig,
|
|
66
|
+
writeDefaultConfigFile,
|
|
67
|
+
DataJam
|
|
68
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export { ensureDataJamDirectory, loadRuntimeConfig, writeDefaultConfigFile } from '@datajam/core';
|
|
2
|
+
|
|
3
|
+
interface DataJamOptions {
|
|
4
|
+
stripeSecretKey?: string;
|
|
5
|
+
projectDir?: string;
|
|
6
|
+
storage?: {
|
|
7
|
+
engine?: "sqlite";
|
|
8
|
+
sqlitePath?: string;
|
|
9
|
+
};
|
|
10
|
+
dashboard?: {
|
|
11
|
+
port?: number;
|
|
12
|
+
host?: string;
|
|
13
|
+
};
|
|
14
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
15
|
+
}
|
|
16
|
+
interface SyncSummary {
|
|
17
|
+
runId: string;
|
|
18
|
+
mode: "full" | "incremental";
|
|
19
|
+
startedAt: string;
|
|
20
|
+
completedAt: string;
|
|
21
|
+
resources: Array<{
|
|
22
|
+
resource: string;
|
|
23
|
+
fetched: number;
|
|
24
|
+
upserted: number;
|
|
25
|
+
skipped: number;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
interface DoctorReport {
|
|
29
|
+
ok: boolean;
|
|
30
|
+
checks: Array<{
|
|
31
|
+
name: string;
|
|
32
|
+
ok: boolean;
|
|
33
|
+
message: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
declare class DataJam {
|
|
37
|
+
private readonly options;
|
|
38
|
+
private core;
|
|
39
|
+
private storage;
|
|
40
|
+
constructor(options?: DataJamOptions);
|
|
41
|
+
init(): Promise<void>;
|
|
42
|
+
sync(input?: {
|
|
43
|
+
full?: boolean;
|
|
44
|
+
}): Promise<SyncSummary>;
|
|
45
|
+
dashboard(input?: {
|
|
46
|
+
port?: number;
|
|
47
|
+
}): Promise<{
|
|
48
|
+
url: string;
|
|
49
|
+
stop(): Promise<void>;
|
|
50
|
+
}>;
|
|
51
|
+
start(): Promise<{
|
|
52
|
+
sync: SyncSummary;
|
|
53
|
+
url: string;
|
|
54
|
+
stop(): Promise<void>;
|
|
55
|
+
}>;
|
|
56
|
+
doctor(): Promise<DoctorReport>;
|
|
57
|
+
private getCore;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { DataJam, type DataJamOptions, type DoctorReport, type SyncSummary };
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "datajam",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local-first analytics SDK for syncing Stripe data",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"datajam": "dist/bin.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts src/bin.ts --format esm --dts",
|
|
23
|
+
"dev": "tsup src/index.ts src/bin.ts --watch --format esm --dts",
|
|
24
|
+
"lint": "eslint src --ext .ts",
|
|
25
|
+
"test": "vitest run --passWithNoTests",
|
|
26
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@datajam/analytics": "workspace:*",
|
|
30
|
+
"@datajam/connector-stripe": "workspace:*",
|
|
31
|
+
"@datajam/core": "workspace:*",
|
|
32
|
+
"@datajam/dashboard": "workspace:*",
|
|
33
|
+
"@datajam/storage-sqlite": "workspace:*",
|
|
34
|
+
"@datajam/types": "workspace:*",
|
|
35
|
+
"commander": "^12.1.0"
|
|
36
|
+
}
|
|
37
|
+
}
|