@nzila/sdk 0.1.0 → 0.1.3
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/README.md +27 -1
- package/dist/cli/constants.d.ts +13 -0
- package/dist/cli/constants.d.ts.map +1 -0
- package/dist/cli/constants.js +20 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +223 -0
- package/dist/cli/open-browser.d.ts +2 -0
- package/dist/cli/open-browser.d.ts.map +1 -0
- package/dist/cli/open-browser.js +26 -0
- package/examples/COMPLEX-USAGE.md +113 -0
- package/examples/INDEX.md +27 -0
- package/examples/README.md +94 -0
- package/examples/RUNTIME-TRACE.md +222 -0
- package/examples/TRACING-FAILURES.md +186 -0
- package/examples/backend/error-tracing.test.ts +44 -0
- package/examples/backend/order-pricing.test.ts +54 -0
- package/examples/backend/order-pricing.ts +27 -0
- package/examples/backend/runtime-trace.example.ts +31 -0
- package/examples/backend/sample-payload.json +62 -0
- package/examples/backend/sample-tracing-payload.json +90 -0
- package/examples/complex/api-services.demo.ts +72 -0
- package/examples/complex/full-platform.demo.test.ts +46 -0
- package/examples/frontend/checkout-form.test.ts +54 -0
- package/examples/frontend/checkout-form.ts +29 -0
- package/examples/frontend/error-tracing.test.ts +59 -0
- package/examples/frontend/sample-payload.json +62 -0
- package/examples/frontend/sample-tracing-payload.json +73 -0
- package/examples/frontend-webhook-client.ts +32 -0
- package/examples/jest.config.example.cjs +18 -0
- package/examples/mocharc.nzila.example.cjs +21 -0
- package/examples/react/checkout-feature.example.tsx +41 -0
- package/examples/send-run-manual.mjs +16 -0
- package/examples/shared/feature-map.ts +24 -0
- package/examples/shared/load-env.mjs +24 -0
- package/examples/shared/send-webhook.mjs +43 -0
- package/examples/vitest.config.example.ts +20 -0
- package/package.json +9 -4
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POST a sample payload to Nzila (backend or frontend JSON under examples/).
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* node examples/shared/send-webhook.mjs examples/backend/sample-payload.json
|
|
6
|
+
* node examples/shared/send-webhook.mjs examples/frontend/sample-payload.json
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { resolve } from "node:path";
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import { getWebhookEnv } from "./load-env.mjs";
|
|
12
|
+
|
|
13
|
+
const payloadArg = process.argv[2];
|
|
14
|
+
if (!payloadArg) {
|
|
15
|
+
console.error("Usage: node examples/shared/send-webhook.mjs <path-to-payload.json>");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const { apiKey, webhookUrl, projectRoot } = getWebhookEnv();
|
|
20
|
+
const payloadPath = resolve(projectRoot, payloadArg);
|
|
21
|
+
const payload = JSON.parse(readFileSync(payloadPath, "utf8"));
|
|
22
|
+
payload.runId = `${payload.appName ?? "example"}-${Date.now()}`;
|
|
23
|
+
|
|
24
|
+
const res = await axios.post(webhookUrl, payload, {
|
|
25
|
+
headers: {
|
|
26
|
+
Authorization: `Bearer ${apiKey}`,
|
|
27
|
+
"Content-Type": "application/json",
|
|
28
|
+
},
|
|
29
|
+
validateStatus: () => true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log("Payload:", payloadPath);
|
|
33
|
+
console.log("Status:", res.status);
|
|
34
|
+
console.log("Body:", JSON.stringify(res.data, null, 2));
|
|
35
|
+
|
|
36
|
+
if (res.status === 403 && res.data?.code === "API_KEY_EXPIRED") {
|
|
37
|
+
console.error("\nAPI key expired — create a new one at /en/keys");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (res.status === 202 || res.status === 200) {
|
|
42
|
+
console.log("\nView the run: http://localhost:3000/en");
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy into your app or merge the reporters block into your vitest.config.ts.
|
|
3
|
+
* Nzila repo uses examples/vitest.config.ts (and backend/frontend-specific configs).
|
|
4
|
+
*/
|
|
5
|
+
import { defineConfig } from "vitest/config";
|
|
6
|
+
import NzilaVitestReporter from "@nzila/sdk/vitest";
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
test: {
|
|
10
|
+
reporters: [
|
|
11
|
+
"default",
|
|
12
|
+
new NzilaVitestReporter({
|
|
13
|
+
webhookUrl: process.env.NZILA_WEBHOOK_URL ?? "http://localhost:3000/api/webhooks/tests",
|
|
14
|
+
apiKey: process.env.NZILA_API_KEY!,
|
|
15
|
+
appName: process.env.NZILA_APP_NAME ?? "my-app",
|
|
16
|
+
maxRetries: 3,
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nzila/sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Send test runs to Nzila
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Send test runs to Nzila, trace live feature errors, and onboard via npx @nzila/sdk.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -14,10 +14,14 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"README.md"
|
|
17
|
+
"README.md",
|
|
18
|
+
"examples"
|
|
18
19
|
],
|
|
19
20
|
"main": "./dist/index.js",
|
|
20
21
|
"types": "./dist/index.d.ts",
|
|
22
|
+
"bin": {
|
|
23
|
+
"nzila": "dist/cli/main.js"
|
|
24
|
+
},
|
|
21
25
|
"exports": {
|
|
22
26
|
".": {
|
|
23
27
|
"types": "./dist/index.d.ts",
|
|
@@ -46,7 +50,8 @@
|
|
|
46
50
|
},
|
|
47
51
|
"scripts": {
|
|
48
52
|
"build": "tsc -p tsconfig.build.json",
|
|
49
|
-
"
|
|
53
|
+
"prepare-examples": "node scripts/sync-examples.mjs",
|
|
54
|
+
"prepublishOnly": "npm run prepare-examples && npm run build"
|
|
50
55
|
},
|
|
51
56
|
"peerDependencies": {
|
|
52
57
|
"react": ">=18.0.0",
|