@narrative.io/data-collaboration-sdk-ts 2.65.0 → 2.67.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/README.md CHANGED
@@ -313,4 +313,140 @@ try {
313
313
 
314
314
  ## API Reference
315
315
 
316
- For detailed API documentation, please visit the [Narrative.io API Documentation](https://api.narrative.dev).
316
+ For detailed API documentation, please visit the [Narrative.io API Documentation](https://api.narrative.dev).
317
+
318
+ ## Local Development: Use This SDK Locally in a Consumer App (No Publish Needed)
319
+
320
+ You can link this SDK into another repo (e.g., a Nuxt 3 app) and iterate without publishing to npm each time. Two supported flows:
321
+
322
+ - **Linked mode (fastest)** — symlink your local SDK into the app
323
+ - **Tarball mode (exact publish parity)** — install from a local `npm pack` tarball
324
+
325
+ Both approaches use the SDK’s **built output** in `build/`, exactly like the published package.
326
+
327
+ ### Prerequisites
328
+
329
+ - Node & npm
330
+ - This repo builds TypeScript to `build/`
331
+ - This repo includes `scripts/ensureBuild.js` to verify artifacts exist
332
+
333
+ ```bash
334
+ # In the SDK repo (this one)
335
+ npm i
336
+ npm run build # one-time; emits build/**
337
+ node scripts/ensureBuild.js
338
+ ```
339
+
340
+ ---
341
+
342
+ ### Option A — Linked Mode (Fastest Dev Feedback)
343
+
344
+ 1. **Keep the SDK building on save**
345
+ In the SDK repo (leave this running):
346
+ ```bash
347
+ npm run dev # tsc -w → continuously updates build/**
348
+ ```
349
+
350
+ 2. **Register the SDK globally**
351
+ In the SDK repo (new terminal):
352
+ ```bash
353
+ npm run link:global # runs ensureBuild + npm link
354
+ ```
355
+
356
+ 3. **Link into your consumer app**
357
+ In your app repo (e.g., Nuxt project):
358
+ ```bash
359
+ # optional safety if a link exists
360
+ npm unlink @narrative.io/data-collaboration-sdk-ts --no-save || true
361
+
362
+ # link the globally-registered SDK into this app’s node_modules
363
+ npm link @narrative.io/data-collaboration-sdk-ts
364
+ ```
365
+
366
+ 4. **Verify the app resolves to your local SDK**
367
+ ```bash
368
+ node -e "console.log(require.resolve('@narrative.io/data-collaboration-sdk-ts/package.json'))"
369
+ ```
370
+ You should see a path inside your SDK repo (not a versioned folder under the app’s `node_modules`).
371
+
372
+ 5. **Run your app**
373
+ ```bash
374
+ npm run dev
375
+ ```
376
+ Edit files under `SDK/src/**` → the watcher writes to `build/**` → your app hot-reloads.
377
+
378
+ **Revert to the registry version (in the app):**
379
+ ```bash
380
+ npm unlink @narrative.io/data-collaboration-sdk-ts --no-save
381
+ npm i
382
+ ```
383
+
384
+ ---
385
+
386
+ ### Option B — Tarball Mode (Exact Publish Parity)
387
+
388
+ 1. **Pack the SDK (same artifact you would publish)**
389
+ ```bash
390
+ # in the SDK repo
391
+ npm run build
392
+ npm pack # creates ./<name>-<version>.tgz
393
+ ```
394
+
395
+ 2. **Install the tarball in the app**
396
+ ```bash
397
+ # in the app repo
398
+ npm i /ABS/PATH/TO/<name>-<version>.tgz
399
+ npm run dev
400
+ ```
401
+
402
+ **Revert to a registry version (in the app):**
403
+ ```bash
404
+ npm i @narrative.io/data-collaboration-sdk-ts@<semver>
405
+ ```
406
+
407
+ ---
408
+
409
+ ### Troubleshooting (Nuxt 3 / Vite / SSR)
410
+
411
+ - **“Cannot use import statement outside a module” (SSR):** Inline the SDK so Nitro bundles it.
412
+ ```ts
413
+ // nuxt.config.ts
414
+ export default defineNuxtConfig({
415
+ nitro: { externals: { inline: ['@narrative.io/data-collaboration-sdk-ts'] } }
416
+ })
417
+ ```
418
+
419
+ - **Build artifacts not updating:** Ensure `npm run dev` is running in the SDK repo (TypeScript watch), and that the app is linked (or reinstalled from a fresh tarball).
420
+
421
+ - **Accidental imports from `src/*`:** Consumers should import from the package root only. This SDK publishes `build/**` and defines `main`/`types` (and may include an `exports` map) to prevent `src/*` imports.
422
+
423
+ - **Type/version drift (e.g., Zod):** If your app and the SDK use different major versions of a library whose types appear in public APIs, align versions or declare that library as a `peerDependency` in the SDK.
424
+
425
+ ---
426
+
427
+ ### Quick Reference
428
+
429
+ ```bash
430
+ # SDK (this repo)
431
+ npm i
432
+ npm run build
433
+ npm run dev
434
+ npm run link:global
435
+
436
+ # App (consumer repo)
437
+ npm unlink @narrative.io/data-collaboration-sdk-ts --no-save || true
438
+ npm link @narrative.io/data-collaboration-sdk-ts
439
+ npm run dev
440
+ ```
441
+
442
+ Alternative (publish-parity):
443
+
444
+ ```bash
445
+ # SDK
446
+ npm run build
447
+ npm pack
448
+
449
+ # App
450
+ npm i /ABS/PATH/TO/*.tgz
451
+ npm run dev
452
+ ```
@@ -11,10 +11,14 @@ export function traversePolicy(policy, attributeByName, requiredAttributePaths,
11
11
  if (!attribute) {
12
12
  throw new Error(`Attribute "${attributeName}" referenced in policy but not provided.`);
13
13
  }
14
+ // Always mark the root attribute (without path) for SELECT clause
14
15
  markAttributePath(requiredAttributePaths, attribute, normalizePathValue(undefined));
15
16
  if (field.additional_required_properties) {
16
17
  for (const path of field.additional_required_properties) {
17
- markAttributePath(requiredAttributePaths, attribute, normalizePathValue(path));
18
+ // Add IS NOT NULL filter for each additional required property
19
+ const pathStr = normalizePathValue(path);
20
+ const expression = `company_data."${datasetName}"."_rosetta_stone"."${attribute.name}"."${pathStr}"`;
21
+ whereClauses.add(`(${expression} IS NOT NULL)`);
18
22
  }
19
23
  }
20
24
  if (node.filters) {
@@ -54,11 +58,10 @@ function traverseSatisfiedStructure(node, attributeByName, visitor) {
54
58
  return;
55
59
  }
56
60
  if ("anyOf" in node && Array.isArray(node.anyOf)) {
57
- // For anyOf, only traverse the FIRST satisfied branch
61
+ // For anyOf, traverse ALL satisfied branches
58
62
  for (const child of node.anyOf) {
59
63
  if (isBranchSatisfied(child, attributeByName)) {
60
64
  traverseSatisfiedStructure(child, attributeByName, visitor);
61
- return; // Only process the first satisfied branch
62
65
  }
63
66
  }
64
67
  return;
@@ -58,16 +58,16 @@ function buildPolicySqlUsingIndexes(policies, attributeByName, datasetName) {
58
58
  }
59
59
  }
60
60
  const selectClauses = new Set();
61
- for (const [attributeName, paths] of globalRequiredAttributePaths) {
61
+ for (const [attributeName, _paths] of globalRequiredAttributePaths) {
62
62
  const attribute = attributeByName.get(attributeName);
63
63
  if (!attribute) {
64
64
  continue;
65
65
  }
66
- for (const path of paths) {
67
- const expression = resolveAttributeExpression(attribute, path, datasetName);
68
- const alias = buildSelectAlias(attributeName, path);
69
- selectClauses.add(`${expression} AS ${alias}`);
70
- }
66
+ // Always select the root attribute (without path)
67
+ const expression = resolveAttributeExpression(attribute, "", // Empty path for root attribute
68
+ datasetName);
69
+ const alias = buildSelectAlias(attributeName, "");
70
+ selectClauses.add(`${expression} AS ${alias}`);
71
71
  }
72
72
  return {
73
73
  select: Array.from(selectClauses),
@@ -1,6 +1,9 @@
1
1
  export function markAttributePath(index, attribute, path) {
2
2
  const attributePaths = index.get(attribute.name) ?? new Set();
3
- const normalized = path || determineDefaultPath(attribute);
3
+ // Use the provided path, even if it's an empty string (which represents the root attribute)
4
+ const normalized = path !== undefined && path !== null
5
+ ? path
6
+ : determineDefaultPath(attribute);
4
7
  attributePaths.add(normalized);
5
8
  index.set(attribute.name, attributePaths);
6
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narrative.io/data-collaboration-sdk-ts",
3
- "version": "2.65.0",
3
+ "version": "2.67.0",
4
4
  "main": "build/index.js",
5
5
  "repository": "github:narrative-io/data-collaboration-sdk-ts",
6
6
  "source": "src/index.ts",
@@ -14,27 +14,31 @@
14
14
  "preversion": "npm run lint",
15
15
  "version": "npm run && git add -A src",
16
16
  "postversion": "git push && git push --tags",
17
- "test": "jest --coverage"
17
+ "test": "jest --coverage",
18
+ "dev": "tsc -w",
19
+ "check:built": "node scripts/ensureBuild.js",
20
+ "link:global": "npm run check:built && npm link",
21
+ "pack:dist": "npm run check:built && npm pack"
18
22
  },
19
23
  "keywords": [],
20
24
  "author": "",
21
25
  "license": "ISC",
22
26
  "devDependencies": {
23
- "@babel/core": "7.28.3",
27
+ "@babel/core": "7.28.4",
24
28
  "@babel/preset-env": "7.28.3",
25
29
  "@babel/preset-typescript": "7.27.1",
26
- "@biomejs/biome": "2.2.2",
27
- "@commitlint/cli": "20.0.0",
30
+ "@biomejs/biome": "2.2.5",
31
+ "@commitlint/cli": "20.1.0",
28
32
  "@commitlint/config-conventional": "20.0.0",
29
33
  "@types/jest": "30.0.0",
30
- "babel-jest": "30.1.0",
31
- "jest": "30.1.0",
32
- "lefthook": "1.12.3",
33
- "ts-jest": "29.4.1"
34
+ "babel-jest": "30.2.0",
35
+ "jest": "30.2.0",
36
+ "lefthook": "1.13.6",
37
+ "ts-jest": "29.4.4"
34
38
  },
35
39
  "dependencies": {
36
40
  "mande": "2.0.9",
37
- "zod": "4.1.3",
41
+ "zod": "4.1.11",
38
42
  "bignumber.js": "9.3.1"
39
43
  },
40
44
  "overrides": {