@socialgouv/matomo-postgres 2.3.1 → 2.3.2

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/bin/index.js CHANGED
@@ -1,9 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // DIAGNOSTIC: Log environment state at entry point
4
+ console.log('🔍 [DIAGNOSTIC] bin/index.js starting...')
5
+ console.log('🔍 [DIAGNOSTIC] PGDATABASE env var:', process.env.PGDATABASE ? `SET (length: ${process.env.PGDATABASE.length})` : 'NOT SET OR EMPTY')
6
+ console.log('🔍 [DIAGNOSTIC] NODE_ENV:', process.env.NODE_ENV || 'NOT SET')
7
+ console.log('🔍 [DIAGNOSTIC] Current working directory:', process.cwd())
8
+ console.log('🔍 [DIAGNOSTIC] About to import db module...\n')
9
+
3
10
  import { db } from '../dist/db.js'
4
11
  import run from '../dist/index.js'
5
12
  import { startMigration } from '../dist/migrate-latest.js'
6
13
 
14
+ console.log('🔍 [DIAGNOSTIC] Modules imported successfully\n')
15
+
7
16
  async function start(date) {
8
17
  console.log(`\nRunning migrations\n`)
9
18
  await startMigration()
package/dist/config.js CHANGED
@@ -1,3 +1,10 @@
1
+ // DIAGNOSTIC: Log when config is being loaded
2
+ console.log('🔍 [DIAGNOSTIC] config.ts module loading...');
3
+ console.log('🔍 [DIAGNOSTIC] Reading environment variables:');
4
+ console.log(' - PGDATABASE:', process.env.PGDATABASE ? `SET (length: ${process.env.PGDATABASE.length})` : 'NOT SET OR EMPTY');
5
+ console.log(' - MATOMO_URL:', process.env.MATOMO_URL ? 'SET' : 'NOT SET (will use default)');
6
+ console.log(' - MATOMO_SITE:', process.env.MATOMO_SITE ? 'SET' : 'NOT SET (will use default)');
7
+ console.log(' - MATOMO_KEY:', process.env.MATOMO_KEY ? 'SET' : 'NOT SET');
1
8
  export const MATOMO_KEY = process.env.MATOMO_KEY || '';
2
9
  export const MATOMO_URL = process.env.MATOMO_URL || 'https://matomo.fabrique.social.gouv.fr/';
3
10
  export const MATOMO_SITE = process.env.MATOMO_SITE || 0;
@@ -5,6 +12,7 @@ export const PGDATABASE = process.env.PGDATABASE || '';
5
12
  export const INITIAL_OFFSET = process.env.INITIAL_OFFSET || '3';
6
13
  export const RESULTPERPAGE = process.env.RESULTPERPAGE || '500';
7
14
  export const FORCE_STARTDATE = process.env.FORCE_STARTDATE === 'true';
15
+ console.log('🔍 [DIAGNOSTIC] config.ts module loaded\n');
8
16
  // We will create both a normal and a partitioned table (MATOMO_TABLE_NAME and PARTITIONED_MATOMO_TABLE_NAME)
9
17
  // and use DESTINATION_TABLE to determine which one to write to.
10
18
  export const DESTINATION_TABLE = process.env.DESTINATION_TABLE || 'matomo';
package/dist/db.js CHANGED
@@ -4,20 +4,30 @@ import pkg from 'pg';
4
4
  const { Pool } = pkg;
5
5
  import { PGDATABASE } from './config.js';
6
6
  startDebug('db');
7
+ // DIAGNOSTIC: Log environment state at module load time
8
+ console.log('🔍 [DIAGNOSTIC] db.ts module loading...');
9
+ console.log('🔍 [DIAGNOSTIC] PGDATABASE value:', PGDATABASE ? `SET (length: ${PGDATABASE.length})` : 'NOT SET OR EMPTY');
10
+ console.log('🔍 [DIAGNOSTIC] Pool constructor type:', typeof Pool);
7
11
  export const pool = new Pool({
8
12
  connectionString: PGDATABASE,
9
13
  ssl: {
10
14
  rejectUnauthorized: false
11
15
  }
12
16
  });
17
+ // DIAGNOSTIC: Log pool creation details
18
+ console.log('🔍 [DIAGNOSTIC] Pool created:', pool ? 'YES' : 'NO');
19
+ console.log('🔍 [DIAGNOSTIC] Pool has connect method:', pool && typeof pool.connect === 'function' ? 'YES' : 'NO');
20
+ console.log('🔍 [DIAGNOSTIC] Pool object keys:', pool ? Object.keys(pool).join(', ') : 'N/A');
13
21
  // Validate pool is properly initialized
14
22
  if (!pool || typeof pool.connect !== 'function') {
15
23
  throw new Error('Failed to initialize PostgreSQL connection pool');
16
24
  }
25
+ // DIAGNOSTIC: Log dialect creation
26
+ console.log('🔍 [DIAGNOSTIC] Creating PostgresDialect with pool...');
27
+ const dialect = new PostgresDialect({ pool: pool });
28
+ console.log('🔍 [DIAGNOSTIC] PostgresDialect created:', dialect ? 'YES' : 'NO');
17
29
  export const db = new Kysely({
18
- dialect: new PostgresDialect({
19
- pool: pool
20
- }),
30
+ dialect: dialect,
21
31
  log(event) {
22
32
  if (event.level === 'query') {
23
33
  // debug(event.query.sql)
@@ -25,6 +35,9 @@ export const db = new Kysely({
25
35
  }
26
36
  }
27
37
  });
38
+ // DIAGNOSTIC: Log final db instance
39
+ console.log('🔍 [DIAGNOSTIC] Kysely db instance created:', db ? 'YES' : 'NO');
40
+ console.log('🔍 [DIAGNOSTIC] db.ts module loaded successfully\n');
28
41
  // Validate the Kysely instance
29
42
  if (!db) {
30
43
  throw new Error('Failed to initialize Kysely database instance');
@@ -19,15 +19,25 @@ const debug = startDebug('importDate');
19
19
  const isoDate = (date) => formatISO(date, { representation: 'date' });
20
20
  /** check how many visits complete for a given date */
21
21
  const getRecordsCount = (date) => __awaiter(void 0, void 0, void 0, function* () {
22
+ console.log(`🔍 [DIAGNOSTIC] getRecordsCount called for date: ${date}`);
23
+ console.log('🔍 [DIAGNOSTIC] Checking pool validity...');
24
+ console.log(' - pool exists:', pool ? 'YES' : 'NO');
25
+ console.log(' - pool.connect is function:', pool && typeof pool.connect === 'function' ? 'YES' : 'NO');
22
26
  if (!pool || typeof pool.connect !== 'function') {
27
+ console.error('❌ [DIAGNOSTIC] Pool validation failed in getRecordsCount!');
28
+ console.error(' - pool:', pool);
29
+ console.error(' - pool type:', typeof pool);
30
+ console.error(' - pool.connect:', pool && pool.connect);
23
31
  throw new Error('Database connection pool is invalid or undefined in getRecordsCount');
24
32
  }
33
+ console.log('🔍 [DIAGNOSTIC] Pool validated, executing query...');
25
34
  const result = yield db
26
35
  .selectFrom(DESTINATION_TABLE)
27
36
  .select(db.fn.count('idvisit').distinct().as('count'))
28
37
  // UTC to be iso with matomo matomo data
29
38
  .where(sql `date(timezone('UTC', action_timestamp))`, '=', date)
30
39
  .executeTakeFirst();
40
+ console.log(`🔍 [DIAGNOSTIC] Query result:`, result);
31
41
  // start at previous visit in case action didnt finished to record
32
42
  const count = Math.max(0, (result && parseInt(result.count) - 1) || 0);
33
43
  return count;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@socialgouv/matomo-postgres",
3
3
  "description": "Extract visitor events from Matomo API and push to Postgres",
4
- "version": "2.3.1",
4
+ "version": "2.3.2",
5
5
  "types": "types/index.d.ts",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/index.js",