@rxap/nest-supabase 11.0.0-dev.1 → 11.0.1-dev.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/CHANGELOG.md CHANGED
@@ -1,8 +1,23 @@
1
+ ## 11.0.1-dev.0 (2026-06-19)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - **generators:** read package.json and node_modules from disk, not the virtual Tree
6
+ - **generators:** match package name with .some() in init devDependency coercion
7
+
8
+ ### ❤️ Thank You
9
+
10
+ - Merzough Münker
11
+
1
12
  # Change Log
2
13
 
3
14
  All notable changes to this project will be documented in this file.
4
15
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
16
 
17
+ # [11.0.0](https://gitlab.com/rxap/packages/compare/@rxap/nest-supabase@11.0.0-dev.1...@rxap/nest-supabase@11.0.0) (2026-01-23)
18
+
19
+ **Note:** Version bump only for package @rxap/nest-supabase
20
+
6
21
  # [11.0.0-dev.1](https://gitlab.com/rxap/packages/compare/@rxap/nest-supabase@10.0.13...@rxap/nest-supabase@11.0.0-dev.1) (2025-05-16)
7
22
 
8
23
  **Note:** Version bump only for package @rxap/nest-supabase
package/TODO.md ADDED
@@ -0,0 +1,78 @@
1
+ # TODO: nest-supabase Package Audit & Improvement Plan
2
+
3
+ This file lists the findings, architectural issues, and critical bugs identified during the project audit of the `@rxap/nest-supabase` package, along with recommended fixes.
4
+
5
+ ---
6
+
7
+ ## 🧪 Test Coverage
8
+
9
+ ### 1. Zero Test Coverage / Missing Tests
10
+ * **Description:** The package has completely missing test coverage. No unit or integration test files (`.spec.ts`) exist in the codebase.
11
+ * **Impact:** Any changes to module resolution, option loading, or client initialization are highly prone to regressions.
12
+ * **Recommended Fix:**
13
+ - Create a test suite using Jest (configured under `tsconfig.spec.json` and `jest.config.ts`).
14
+ - Add tests for `SupabaseService` to verify that the underling `SupabaseClient` is initialized correctly with injected URL and keys.
15
+ - Add tests for `SupabaseOptionsFactory` and `SupabaseModuleOptionsLoader`.
16
+ - Add tests for `SupabaseModule` registration (`register` and `registerAsync`).
17
+
18
+ ---
19
+
20
+ ## 🏛️ Architectural Debt & Coupling
21
+
22
+ ### 2. Hardcoded Environment Keys in `SupabaseModuleOptionsLoader`
23
+ * **File:** [supabase-module-options-loader.ts](file:///mnt/mmuenker/Projects/rxap/packages/packages/nest/supabase/src/lib/supabase-module-options-loader.ts#L17-L18)
24
+ * **Description:** `SupabaseModuleOptionsLoader` relies directly on the hardcoded environment keys `SUPABASE_URL` and `SUPABASE_KEY` from the `ConfigService`.
25
+ * **Impact:** Applications that use different environment naming conventions (e.g. `NEXT_PUBLIC_SUPABASE_URL` or `SUPABASE_API_URL`) cannot use the automatic options loader without modifying their global environment variable names.
26
+ * **Recommended Fix:** Allow custom environment key overrides to be supplied to the loader, or configure option loading with key mappings.
27
+
28
+ ### 3. Discarded `options` in `SupabaseModuleOptionsLoader`
29
+ * **File:** [supabase-module-options-loader.ts](file:///mnt/mmuenker/Projects/rxap/packages/packages/nest/supabase/src/lib/supabase-module-options-loader.ts#L15-L20)
30
+ * **Description:** The `create()` method only returns `supabaseUrl` and `supabaseKey`. It completely ignores/omits other client-specific configuration options (`SupabaseClientOptions` like `auth`, `db`, `global`, etc.).
31
+ * **Impact:** Consumers cannot supply extra configuration options dynamically when using the module options loader.
32
+ * **Recommended Fix:** Read additional `options` (e.g., from `ConfigService` under a sub-key like `SUPABASE_OPTIONS` or `SUPABASE_CLIENT_CONFIG`) inside the loader's `create()` method.
33
+
34
+ ### 4. Single-Instance Restriction (Strictly Global Module)
35
+ * **File:** [supabase.module.ts](file:///mnt/mmuenker/Projects/rxap/packages/packages/nest/supabase/src/lib/supabase.module.ts#L34)
36
+ * **Description:** `SupabaseModule` is statically marked as `@Global()` and uses a hardcoded, single `SUPABASE_OPTIONS` injection token.
37
+ * **Impact:** This design severely limits applications to a single global Supabase client instance. If an application needs to connect to multiple Supabase databases/projects, it cannot do so easily using this module.
38
+ * **Recommended Fix:** Allow the module to opt-out of global registration or support multi-client configurations by using a "connection name" or feature-key to register and inject distinct, named instances of the client.
39
+
40
+ ### 5. Extending `SupabaseClient` Directly in `SupabaseService`
41
+ * **File:** [supabase.service.ts](file:///mnt/mmuenker/Projects/rxap/packages/packages/nest/supabase/src/lib/supabase.service.ts#L27)
42
+ * **Description:** `SupabaseService` extends `SupabaseClient` directly.
43
+ * **Impact:** Tight coupling with the external library's class structure. This makes mock-testing or swapping the service's implementation difficult, as any consumer interacts with full raw class signatures from `@supabase/supabase-js`.
44
+ * **Recommended Fix:** Wrap `SupabaseClient` in a service that exposes a `client` property (or getter), or make `SupabaseService` implement a custom interface to improve testability and mockability.
45
+
46
+ ---
47
+
48
+ ## 🧹 Code Quality & Anti-Patterns
49
+
50
+ ### 6. Direct Mutation of Options in `SupabaseOptionsFactory`
51
+ * **File:** [supabase.module.ts](file:///mnt/mmuenker/Projects/rxap/packages/packages/nest/supabase/src/lib/supabase.module.ts#L64-L70)
52
+ * **Description:** `SupabaseOptionsFactory` mutates the input parameter object directly to set default values:
53
+ ```typescript
54
+ export function SupabaseOptionsFactory(options: SupabaseModuleOptions) {
55
+ options.options ??= {};
56
+ options.options.auth ??= {};
57
+ options.options.auth.autoRefreshToken ??= false;
58
+ options.options.auth.persistSession ??= false;
59
+ return options;
60
+ }
61
+ ```
62
+ * **Impact:** If the passed options object is frozen or shared across multiple contexts, direct mutation will throw runtime exceptions or cause unexpected side-effects.
63
+ * **Recommended Fix:** Deep clone or return a new merged options object instead of mutating the parameter directly:
64
+ ```typescript
65
+ export function SupabaseOptionsFactory(options: SupabaseModuleOptions): SupabaseModuleOptions {
66
+ return {
67
+ ...options,
68
+ options: {
69
+ ...options.options,
70
+ auth: {
71
+ autoRefreshToken: false,
72
+ persistSession: false,
73
+ ...options.options?.auth,
74
+ },
75
+ },
76
+ };
77
+ }
78
+ ```
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "11.0.0-dev.1",
2
+ "version": "11.0.1-dev.0",
3
3
  "name": "@rxap/nest-supabase",
4
4
  "description": "This package provides a NestJS module for integrating with Supabase. It offers a configurable module with options for setting the Supabase URL and key, and a service for interacting with the Supabase client. The module also includes an options loader for retrieving configuration from NestJS ConfigService.\n",
5
5
  "license": "GPL-3.0-or-later",
@@ -33,11 +33,11 @@
33
33
  "packageGroup": [
34
34
  {
35
35
  "package": "@nestjs/common",
36
- "version": "10.3.8"
36
+ "version": "11.1.1"
37
37
  },
38
38
  {
39
39
  "package": "@nestjs/config",
40
- "version": "3.2.2"
40
+ "version": "4.0.2"
41
41
  }
42
42
  ]
43
43
  },
@@ -52,7 +52,6 @@
52
52
  },
53
53
  "schematics": "./generators.json",
54
54
  "type": "commonjs",
55
- "gitHead": "d7af9475bea5bf9e79ec16df38c566451c99a105",
56
55
  "types": "./src/index.d.ts",
57
56
  "main": "./src/index.js"
58
57
  }
@@ -2,14 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initGenerator = initGenerator;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const fs_1 = require("fs");
5
6
  const path_1 = require("path");
6
7
  async function initGenerator(tree, options) {
7
- const packageJsonFilePath = (0, path_1.relative)(tree.root, (0, path_1.join)(__dirname, '..', '..', '..', 'package.json'));
8
- if (!tree.exists(packageJsonFilePath)) {
8
+ // The package's own package.json lives on disk next to the compiled generator
9
+ // (inside node_modules when installed), which the virtual Tree does not track.
10
+ // Read it directly from the physical filesystem.
11
+ const packageJsonFilePath = (0, path_1.join)(__dirname, '..', '..', '..', 'package.json');
12
+ if (!(0, fs_1.existsSync)(packageJsonFilePath)) {
9
13
  console.error('package.json not found in: ' + packageJsonFilePath);
10
14
  return;
11
15
  }
12
- const { peerDependencies, name: packageName } = JSON.parse(tree.read(packageJsonFilePath, 'utf-8'));
16
+ const { peerDependencies, name: packageName } = JSON.parse((0, fs_1.readFileSync)(packageJsonFilePath, 'utf-8'));
13
17
  console.log(`Coerce peer dependencies for package: ${packageName}`);
14
18
  if (!peerDependencies || !Object.keys(peerDependencies).length) {
15
19
  console.log('No peer dependencies found');
@@ -27,11 +31,12 @@ async function initGenerator(tree, options) {
27
31
  isDevDependency = false;
28
32
  tree.write('package.json', JSON.stringify(rootPackageJson, null, 2));
29
33
  }
30
- if (!isDevDependency && [
31
- /^@rxap\/plugin/,
32
- /^@rxap\/workspace/,
33
- /@rxap\/schematic/,
34
- ]) {
34
+ if (!isDevDependency &&
35
+ [
36
+ /^@rxap\/plugin/,
37
+ /^@rxap\/workspace/,
38
+ /@rxap\/schematic/,
39
+ ].some((rx) => rx.test(packageName))) {
35
40
  rootPackageJson.devDependencies ??= {};
36
41
  rootPackageJson.devDependencies[packageName] =
37
42
  rootPackageJson.dependencies[packageName];
@@ -57,35 +62,39 @@ async function initGenerator(tree, options) {
57
62
  (0, devkit_1.installPackagesTask)(tree);
58
63
  for (const peer of Object.keys(missingPeerDependencies)) {
59
64
  console.log(`Peer dependency ${peer} added to package.json`);
60
- const peerPackageJsonFilePath = (0, path_1.join)('node_modules', ...peer.split('/'), 'package.json');
61
- if (!tree.exists(peerPackageJsonFilePath)) {
65
+ // node_modules is physical and excluded from the virtual Tree, so resolve
66
+ // peer files from disk relative to the workspace root.
67
+ const peerPackageDir = (0, path_1.join)(tree.root, 'node_modules', ...peer.split('/'));
68
+ const peerPackageJsonFilePath = (0, path_1.join)(peerPackageDir, 'package.json');
69
+ if (!(0, fs_1.existsSync)(peerPackageJsonFilePath)) {
62
70
  console.log(`Peer dependency ${peer} has no package.json`);
63
71
  continue;
64
72
  }
65
- const { generators, schematics } = JSON.parse(tree.read(peerPackageJsonFilePath, 'utf-8'));
73
+ const { generators, schematics } = JSON.parse((0, fs_1.readFileSync)(peerPackageJsonFilePath, 'utf-8'));
66
74
  if (!generators && !schematics) {
67
75
  console.log(`Peer dependency ${peer} has no generators or schematics`);
68
76
  continue;
69
77
  }
70
78
  const configFile = generators || schematics;
71
- if (!tree.exists((0, path_1.join)('node_modules', ...peer.split('/'), configFile))) {
79
+ const configFilePath = (0, path_1.join)(peerPackageDir, configFile);
80
+ if (!(0, fs_1.existsSync)(configFilePath)) {
72
81
  console.log(`Peer dependency ${peer} has no generators or schematics file`);
73
82
  continue;
74
83
  }
75
- const config = JSON.parse(tree.read((0, path_1.join)('node_modules', ...peer.split('/'), configFile), 'utf-8'));
84
+ const config = JSON.parse((0, fs_1.readFileSync)(configFilePath, 'utf-8'));
76
85
  if (!config.generators?.init) {
77
86
  console.log(`Peer dependency ${peer} has no init generator`);
78
87
  continue;
79
88
  }
80
89
  const initGeneratorFilePath = config.generators.init.factory;
81
- const fullInitGeneratorFilePath = (0, path_1.join)('node_modules', ...peer.split('/'), initGeneratorFilePath) + '.js';
82
- if (!tree.exists(fullInitGeneratorFilePath)) {
90
+ const fullInitGeneratorFilePath = (0, path_1.join)(peerPackageDir, initGeneratorFilePath) + '.js';
91
+ if (!(0, fs_1.existsSync)(fullInitGeneratorFilePath)) {
83
92
  console.log(`Peer dependency ${peer} has no init generator file: ` +
84
93
  fullInitGeneratorFilePath);
85
94
  continue;
86
95
  }
87
96
  // eslint-disable-next-line @typescript-eslint/no-var-requires
88
- const initGenerator = require((0, path_1.join)('node_modules', ...peer.split('/'), initGeneratorFilePath))?.default;
97
+ const initGenerator = require((0, path_1.join)(peerPackageDir, initGeneratorFilePath))?.default;
89
98
  if (typeof initGenerator !== 'function') {
90
99
  console.log(`Peer dependency ${peer} has no init generator function`);
91
100
  continue;