@hestia-earth/data-api 0.0.2-3 → 0.0.2-4

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.
Files changed (102) hide show
  1. package/package.json +1 -1
  2. package/.dockerignore +0 -25
  3. package/.env.test +0 -7
  4. package/.eslintignore +0 -7
  5. package/.eslintrc.js +0 -11
  6. package/.gitlab-ci.yml +0 -128
  7. package/.mocharc.js +0 -8
  8. package/.nvmrc +0 -1
  9. package/.nycrc +0 -15
  10. package/Dockerfile +0 -17
  11. package/cleanup-docker.sh +0 -4
  12. package/commitlint.config.js +0 -1
  13. package/database/index.ts +0 -76
  14. package/database/migrations/001.do.init.sql +0 -53
  15. package/database/migrations/002.do.add-aggregated-sites.sql +0 -16
  16. package/database/migrations/003.do.add-generated-period-cols.sql +0 -7
  17. package/database/migrations/index.ts +0 -36
  18. package/database/seed/common.ts +0 -7
  19. package/database/seed/index.ts +0 -60
  20. package/database/seed/local/index.ts +0 -28
  21. package/database/seed/production/index.ts +0 -3
  22. package/database/seed/staging/index.ts +0 -5
  23. package/dev.ts +0 -3
  24. package/dist/aggregated-nodes/model/index.js +0 -11
  25. package/docker-compose.yml +0 -42
  26. package/envs/.master.env +0 -7
  27. package/envs/.staging.env +0 -7
  28. package/index.js +0 -3
  29. package/package.serverless.json +0 -21
  30. package/run-docker.sh +0 -14
  31. package/run-test.sh +0 -5
  32. package/scripts/run-lambda.ts +0 -10
  33. package/scripts/run-migrations.ts +0 -18
  34. package/scripts/run-resetdb.ts +0 -18
  35. package/scripts/run-seed.ts +0 -18
  36. package/serverless.yml +0 -101
  37. package/src/aggregated-nodes/model/index.ts +0 -37
  38. package/src/aggregated-nodes/routes/pg-get-filters.ts +0 -54
  39. package/src/aggregated-nodes/routes/pg-get.ts +0 -61
  40. package/src/aggregated-nodes/routes.spec.ts +0 -274
  41. package/src/aggregated-nodes/routes.ts +0 -56
  42. package/src/aggregated-nodes/services/pg-get-filters.ts +0 -62
  43. package/src/aggregated-nodes/services/pg-get.ts +0 -77
  44. package/src/app.spec.ts +0 -34
  45. package/src/app.ts +0 -59
  46. package/src/config.ts +0 -21
  47. package/src/cors.spec.ts +0 -32
  48. package/src/cors.ts +0 -7
  49. package/src/errors.spec.ts +0 -114
  50. package/src/errors.ts +0 -121
  51. package/src/index.spec.ts +0 -94
  52. package/src/index.ts +0 -14
  53. package/src/lambdas/sentry.ts +0 -12
  54. package/src/lambdas/update-aggregated-nodes/handler.spec.ts +0 -77
  55. package/src/lambdas/update-aggregated-nodes/handler.ts +0 -129
  56. package/src/logger.spec.ts +0 -20
  57. package/src/logger.ts +0 -45
  58. package/src/maintenance.spec.ts +0 -76
  59. package/src/maintenance.ts +0 -19
  60. package/src/models.ts +0 -1
  61. package/src/routes.ts +0 -8
  62. package/src/settings/model/index.ts +0 -21
  63. package/src/settings/routes/get.spec.ts +0 -33
  64. package/src/settings/routes/get.ts +0 -3
  65. package/src/settings/routes/update.spec.ts +0 -33
  66. package/src/settings/routes/update.ts +0 -5
  67. package/src/settings/routes.spec.ts +0 -75
  68. package/src/settings/routes.ts +0 -21
  69. package/src/settings/services/get.spec.ts +0 -62
  70. package/src/settings/services/get.ts +0 -18
  71. package/src/settings/services/update.spec.ts +0 -118
  72. package/src/settings/services/update.ts +0 -47
  73. package/src/slack.spec.ts +0 -42
  74. package/src/slack.ts +0 -17
  75. package/src/swagger/routes.ts +0 -57
  76. package/src/types/async-express-errors/index.d.ts +0 -1
  77. package/src/types/express/index.d.ts +0 -10
  78. package/src/utils/endpoint-wrapper.spec.ts +0 -80
  79. package/src/utils/endpoint-wrapper.ts +0 -16
  80. package/src/utils/middleware.spec.ts +0 -154
  81. package/src/utils/middleware.ts +0 -33
  82. package/test/Dockerfile +0 -13
  83. package/test/docker-compose.yml +0 -40
  84. package/test/fixtures/aggregated-nodes/get.ts +0 -196
  85. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv +0 -5
  86. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv.cycle.json +0 -458
  87. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-cycle_pivoted.csv.site.json +0 -182
  88. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-impactassessment_pivoted.csv +0 -3
  89. package/test/fixtures/update-aggregated-nodes/abyssinianKaleSeedWhole-impactassessment_pivoted.csv.impactAssessment.json +0 -988
  90. package/test/fixtures/update-aggregated-nodes/abyssinianKaleStraw-impactassessment_pivoted.csv +0 -3
  91. package/test/fixtures/update-aggregated-nodes/cycle-missing-impactassessment_pivoted.csv +0 -3
  92. package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv +0 -5
  93. package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv.cycle.json +0 -584
  94. package/test/fixtures/update-aggregated-nodes/tomatoFruit-cycle_pivoted.csv.site.json +0 -212
  95. package/test/fixtures/update-aggregated-nodes/tomatoFruit-impactassessment_pivoted.csv +0 -3
  96. package/test/fixtures/update-aggregated-nodes/tomatoFruit-impactassessment_pivoted.csv.impactAssessment.json +0 -1002
  97. package/test/prepare.ts +0 -13
  98. package/test/utils.ts +0 -32
  99. package/tsconfig.build.json +0 -13
  100. package/tsconfig.dist.json +0 -14
  101. package/tsconfig.json +0 -42
  102. package/tsconfig.lambdas.json +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/data-api",
3
- "version": "0.0.2-3",
3
+ "version": "0.0.2-4",
4
4
  "description": "Hestia Data API definitions",
5
5
  "main": "dist/models.js",
6
6
  "typings": "dist/models.d.ts",
package/.dockerignore DELETED
@@ -1,25 +0,0 @@
1
- *.DS_Store
2
- .gitignore
3
- .env
4
- .git
5
- .gitlab*
6
- .npmignore
7
- *.md
8
- *.sh
9
- .nvmrc
10
- .eslintrc.js
11
- .nycrc
12
- *.spec.ts
13
- .nyc_output/
14
- build/
15
- coverage/
16
- dist/
17
- logs/
18
- node_modules/
19
- test/
20
- docker-compose*
21
- Dockerfile
22
- commitlint.config.js
23
- build-lambdas/
24
- tsconfig.lambdas.json
25
- envs/
package/.env.test DELETED
@@ -1,7 +0,0 @@
1
- PGHOST=localhost
2
- PGUSER=postgres
3
- PGDATABASE=postgres
4
- PGPASSWORD=password
5
- PGPORT=5432
6
-
7
- WRITE_SETTINGS_SECRET=dummy
package/.eslintignore DELETED
@@ -1,7 +0,0 @@
1
- .eslintrc.js
2
- coverage
3
- build
4
- build-lambdas
5
- commitlint.config.js
6
- .mocharc.js
7
- dist
package/.eslintrc.js DELETED
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- env: {
3
- node: true
4
- },
5
- extends: ['@hestia-earth/eslint-config'],
6
- parser: '@typescript-eslint/parser',
7
- parserOptions: {
8
- project: 'tsconfig.json',
9
- sourceType: 'module'
10
- }
11
- };
package/.gitlab-ci.yml DELETED
@@ -1,128 +0,0 @@
1
- stages:
2
- - test
3
- - publish
4
- - deploy
5
-
6
- default:
7
- image: node:18
8
- cache:
9
- paths:
10
- - node_modules/
11
- before_script:
12
- - npm ci --include=dev
13
-
14
- variables:
15
- CONTAINER_IMAGE: hestia-data-api
16
- CONTAINER_IMAGE_BUILD: $CONTAINER_IMAGE:$CI_COMMIT_REF_NAME
17
-
18
- lint:
19
- stage: test
20
- script:
21
- - npm run lint
22
- except:
23
- - tags
24
-
25
- lint-commit:
26
- stage: test
27
- script:
28
- - git fetch origin develop
29
- - npx commitlint --from=origin/develop
30
- except:
31
- - tags
32
- - develop
33
- - master
34
-
35
- test:
36
- stage: test
37
- services:
38
- - postgres:14
39
- coverage: /^Statements\s*:\s*([^%]+)/
40
- artifacts:
41
- paths:
42
- - coverage/
43
- reports:
44
- coverage_report:
45
- coverage_format: cobertura
46
- path: coverage/cobertura-coverage.xml
47
- variables:
48
- PGHOST: postgres
49
- PGUSER: postgres
50
- PGDATABASE: "${CI_COMMIT_SHORT_SHA}"
51
- POSTGRES_DB: "${CI_COMMIT_SHORT_SHA}"
52
- PGPORT: 5432
53
- PGPASSWORD: password
54
- POSTGRES_PASSWORD: password
55
- WRITE_SETTINGS_SECRET: dummy
56
- ENVIRONMENT: test
57
- script:
58
- - npm test
59
- except:
60
- - tags
61
-
62
- publish-sources:
63
- stage: publish
64
- artifacts:
65
- paths:
66
- - build/
67
- script:
68
- - npm run build
69
- only:
70
- - tags
71
-
72
- publish-npm:
73
- stage: publish
74
- script:
75
- - npm run build:module
76
- - npm config set //registry.npmjs.org/:_authToken=${NPM_TOKEN}
77
- - rm *.md
78
- - npm publish --access public --verbose
79
- only:
80
- - tags
81
-
82
- publish-docker:
83
- image: docker:stable
84
- stage: publish
85
- services:
86
- - docker:dind
87
- before_script:
88
- - apk add --no-cache curl jq python3 py3-pip
89
- # fix error PyYAML
90
- - pip install pyyaml==5.3.1
91
- - pip install awscli
92
- - $(aws ecr get-login --no-include-email --region us-east-1)
93
- script:
94
- - docker build -f Dockerfile -t $CONTAINER_REGISTRY/$CONTAINER_IMAGE_BUILD .
95
- - docker push $CONTAINER_REGISTRY/$CONTAINER_IMAGE_BUILD
96
- # cleanup
97
- - ./cleanup-docker.sh $CONTAINER_IMAGE
98
- only:
99
- - tags
100
-
101
- deploy-lambdas:
102
- stage: deploy
103
- script:
104
- - source envs/.${CI_COMMIT_REF_NAME}.env
105
- - npm run build:lambdas
106
- # copy serverless package to include correct dependencies
107
- - rm -rf package.json node_modules
108
- - mv package.serverless.json package.json && npm ci --include=dev
109
- - npx serverless deploy --verbose
110
- only:
111
- - master
112
- - staging
113
-
114
- sentry:
115
- stage: deploy
116
- image: getsentry/sentry-cli
117
- before_script:
118
- - export SENTRY_PROJECT=hestia-data-api
119
- - export RELEASE=$(echo $CI_COMMIT_REF_NAME| cut -c2-)
120
- script:
121
- - echo "Create a new release $RELEASE..."
122
- - sentry-cli releases new $RELEASE
123
- - sentry-cli releases set-commits --auto $RELEASE
124
- - sentry-cli releases files $RELEASE upload-sourcemaps $CI_PROJECT_DIR/build -x .js -x .map --validate --verbose --rewrite --strip-common-prefix
125
- - sentry-cli releases finalize $RELEASE
126
- - echo "Create a new release $RELEASE DONE"
127
- only:
128
- - tags
package/.mocharc.js DELETED
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- require: ['ts-node/register', 'source-map-support/register', 'test/prepare.ts'],
5
- 'full-trace': true,
6
- 'watch-files': 'src',
7
- timeout: 10000
8
- };
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 18
package/.nycrc DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "check-coverage": true,
3
- "per-file": false,
4
- "statements": 95,
5
- "branches": 85,
6
- "functions": 95,
7
- "lines": 95,
8
- "include": ["src/**/*.ts"],
9
- "exclude": ["src/swagger/*.ts", "src/**/*.spec.ts"],
10
- "extension": [".ts"],
11
- "require": ["ts-node/register"],
12
- "reporter": ["text-summary", "html", "lcov", "cobertura"],
13
- "sourceMap": true,
14
- "instrument": true
15
- }
package/Dockerfile DELETED
@@ -1,17 +0,0 @@
1
- FROM node:18-slim
2
-
3
- WORKDIR /app
4
-
5
- COPY package.json .
6
- COPY package-lock.json .
7
- RUN npm ci --include=dev
8
-
9
- # copy source from context
10
- ADD . .
11
- # build
12
- RUN npm run build
13
-
14
- RUN mkdir -p logs
15
-
16
- COPY index.js ./
17
- CMD npm start
package/cleanup-docker.sh DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
-
3
- IMAGES_TO_DELETE=$( aws ecr list-images --region us-east-1 --repository-name $1 --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json )
4
- aws ecr batch-delete-image --region us-east-1 --repository-name $1 --image-ids "$IMAGES_TO_DELETE" || true
@@ -1 +0,0 @@
1
- module.exports = { extends: ['@commitlint/config-conventional'] };
package/database/index.ts DELETED
@@ -1,76 +0,0 @@
1
- import Debug from 'debug';
2
- import pg from 'pg';
3
- pg.defaults.parseInt8 = true;
4
- import { logger } from '../src/logger';
5
-
6
- const debug = Debug('@hestia/data-api:db');
7
-
8
- logger.info('Creating pg pool');
9
-
10
- const pool = new pg.Pool({
11
- connectionTimeoutMillis: 10000,
12
- max: 4
13
- });
14
-
15
- pool.on('error', (err) => logger.error('Pool error:', err));
16
-
17
- export const endPool = () => pool.end();
18
-
19
- export const query = async <R extends pg.QueryResultRow = any, I extends any[] = any[]>(
20
- queryTextOrConfig: string | pg.QueryConfig<I>,
21
- params?: I | undefined
22
- ): Promise<pg.QueryResult<R>> => {
23
- const start = Date.now();
24
- try {
25
- const res = await pool.query<R, I>(queryTextOrConfig, params);
26
- const duration = Date.now() - start;
27
- debug('Executed query %O', { queryTextOrConfig, duration, rows: res.rowCount });
28
- return res;
29
- }
30
- catch (e) {
31
- logger.error('Query failed', { queryTextOrConfig, params });
32
- throw e;
33
- }
34
- };
35
-
36
- export const getClient = () => pool.connect();
37
-
38
- type OperationsFn<R extends pg.QueryResultRow> = (client: pg.PoolClient) => Promise<pg.QueryResult<R>>;
39
-
40
- export async function transaction<R extends pg.QueryResultRow>(operations: OperationsFn<R>) {
41
- const start = Date.now();
42
- const client = await pool.connect();
43
- const gotClient = Date.now() - start;
44
- let committed: number | null = null;
45
- let released: number;
46
- try {
47
- await client.query('BEGIN');
48
- const result = await operations(client);
49
- await client.query('COMMIT');
50
- committed = Date.now() - start;
51
- return result;
52
- }
53
- catch (e) {
54
- await client.query('ROLLBACK');
55
- throw e;
56
- }
57
- finally {
58
- client.release();
59
- released = Date.now() - start;
60
- debug('Executed transaction', { gotClient, committed, released });
61
- }
62
- }
63
-
64
- void (async () => {
65
- const { asyncExitHook } = await import('exit-hook');
66
-
67
- asyncExitHook(
68
- async () => {
69
- logger.info('Closing pool...');
70
- await endPool();
71
- },
72
- {
73
- minimumWait: 300
74
- }
75
- );
76
- })();
@@ -1,53 +0,0 @@
1
- CREATE TABLE
2
- aggregated_cycles (
3
- id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
4
- hestia_id TEXT UNIQUE NOT NULL GENERATED ALWAYS AS (jsonld_pivoted->>'@id') STORED,
5
- jsonld_pivoted JSONB NOT NULL,
6
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
7
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
8
- );
9
-
10
- CREATE TABLE
11
- aggregated_impact_assessments (
12
- id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
13
- cycle_hestia_id TEXT REFERENCES aggregated_cycles(hestia_id) NOT NULL GENERATED ALWAYS AS (jsonld_pivoted->'cycle'->>'@id') STORED,
14
- hestia_id TEXT UNIQUE NOT NULL GENERATED ALWAYS AS (jsonld_pivoted->>'@id') STORED,
15
- jsonld_pivoted JSONB NOT NULL,
16
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
17
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
18
- );
19
-
20
- CREATE TYPE setting_type AS ENUM ('maintenanceEnabled');
21
-
22
- CREATE TABLE
23
- settings (
24
- id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
25
- setting setting_type NOT NULL UNIQUE,
26
- active BOOLEAN NOT NULL DEFAULT FALSE,
27
- metadata JSONB NOT NULL DEFAULT '{}',
28
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
29
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
30
- );
31
-
32
- CREATE OR REPLACE FUNCTION trigger_set_timestamp()
33
- RETURNS TRIGGER AS $$
34
- BEGIN
35
- NEW.updated_at = NOW();
36
- RETURN NEW;
37
- END;
38
- $$ LANGUAGE plpgsql;
39
-
40
- CREATE TRIGGER set_timestamp
41
- BEFORE UPDATE ON aggregated_cycles
42
- FOR EACH ROW
43
- EXECUTE PROCEDURE trigger_set_timestamp();
44
-
45
- CREATE TRIGGER set_timestamp
46
- BEFORE UPDATE ON aggregated_impact_assessments
47
- FOR EACH ROW
48
- EXECUTE PROCEDURE trigger_set_timestamp();
49
-
50
- CREATE TRIGGER set_timestamp
51
- BEFORE UPDATE ON settings
52
- FOR EACH ROW
53
- EXECUTE PROCEDURE trigger_set_timestamp();
@@ -1,16 +0,0 @@
1
- CREATE TABLE
2
- aggregated_sites (
3
- id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
4
- hestia_id TEXT UNIQUE NOT NULL GENERATED ALWAYS AS (jsonld_pivoted->>'@id') STORED,
5
- jsonld_pivoted JSONB NOT NULL,
6
- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
7
- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
8
- );
9
-
10
- CREATE TRIGGER set_timestamp
11
- BEFORE UPDATE ON aggregated_sites
12
- FOR EACH ROW
13
- EXECUTE PROCEDURE trigger_set_timestamp();
14
-
15
- ALTER TABLE aggregated_cycles
16
- ADD COLUMN site_hestia_id TEXT REFERENCES aggregated_sites(hestia_id) NOT NULL GENERATED ALWAYS AS (jsonld_pivoted->'site'->>'@id') STORED;
@@ -1,7 +0,0 @@
1
- ALTER TABLE aggregated_impact_assessments
2
- ADD COLUMN generated_period TEXT
3
- GENERATED ALWAYS AS ((jsonld_pivoted::jsonb->>'startDate') || '-' || (jsonld_pivoted::jsonb->>'endDate')) STORED;
4
-
5
- ALTER TABLE aggregated_cycles
6
- ADD COLUMN generated_period TEXT
7
- GENERATED ALWAYS AS ((jsonld_pivoted::jsonb->>'startDate') || '-' || (jsonld_pivoted::jsonb->>'endDate')) STORED;
@@ -1,36 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { join } from 'path';
3
- import Debug from 'debug';
4
-
5
- import { query } from '../index';
6
-
7
- const debug = Debug('@hestia/data-api:db:migrate');
8
-
9
- export const runMigrations = async () => {
10
- const { default: Postgrator } = await import('postgrator');
11
-
12
- try {
13
- const postgrator = new Postgrator({
14
- migrationPattern: join(__dirname, '/*.sql'),
15
- driver: 'pg',
16
- execQuery: query
17
- });
18
-
19
- postgrator.on('validation-started', (migration) => debug('Started validation:', migration.filename));
20
- postgrator.on('validation-finished', (migration) => debug('Finished validation:', migration.filename));
21
- postgrator.on('migration-started', (migration) => debug('Started migration:', migration.filename));
22
- postgrator.on('migration-finished', (migration) => debug('Finished migration:', migration.filename));
23
-
24
- // Migrate to specific version -> postgrator.migrate('002')
25
- const appliedMigrations = await postgrator.migrate();
26
-
27
- debug(
28
- 'Applied:',
29
- appliedMigrations.map((m) => m.filename)
30
- );
31
- }
32
- catch (error) {
33
- console.log('Applied:', error.appliedMigrations);
34
- throw error;
35
- }
36
- };
@@ -1,7 +0,0 @@
1
- export const settings = [
2
- {
3
- setting: 'maintenanceEnabled',
4
- active: false,
5
- metadata: {}
6
- }
7
- ];
@@ -1,60 +0,0 @@
1
- import Debug from 'debug';
2
-
3
- import { query } from '..';
4
- import * as commonSeeds from './common';
5
-
6
- const debug = Debug('@hestia/data-api:db:seed');
7
-
8
- export const seed = async ({
9
- aggregatedCycles = [],
10
- aggregatedImpactAssessments = [],
11
- aggregatedSites = [],
12
- settings = []
13
- }) => {
14
- for (const site of aggregatedSites) {
15
- const { rows } = await query(
16
- `INSERT INTO aggregated_sites (jsonld_pivoted) VALUES ($1)
17
- ON CONFLICT DO NOTHING
18
- RETURNING id`,
19
- [site.jsonld_pivoted]
20
- );
21
- const rowId = rows[0]?.id;
22
- debug('Inserted aggregated site with ID:', rowId);
23
- }
24
- for (const cycle of aggregatedCycles) {
25
- const { rows } = await query(
26
- `INSERT INTO aggregated_cycles (jsonld_pivoted) VALUES ($1)
27
- ON CONFLICT DO NOTHING
28
- RETURNING id`,
29
- [cycle.jsonld_pivoted]
30
- );
31
- const rowId = rows[0]?.id;
32
- debug('Inserted aggregated cycle with ID:', rowId);
33
- }
34
- for (const ia of aggregatedImpactAssessments) {
35
- const { rows } = await query(
36
- `INSERT INTO aggregated_impact_assessments (jsonld_pivoted) VALUES ($1)
37
- ON CONFLICT DO NOTHING
38
- RETURNING id`,
39
- [ia.jsonld_pivoted]
40
- );
41
- const rowId = rows[0]?.id;
42
- debug('Inserted aggregated impact assessment with ID:', rowId);
43
- }
44
- for (const setting of settings) {
45
- const { rows } = await query(
46
- `INSERT INTO settings (setting, active, metadata) VALUES ($1, $2, $3)
47
- ON CONFLICT DO NOTHING
48
- RETURNING id`,
49
- [setting.setting, setting.active, setting.metadata]
50
- );
51
- const rowId = rows[0]?.id;
52
- debug('Inserted setting with ID:', rowId);
53
- }
54
- };
55
-
56
- export const runSeed = async () => {
57
- const seedFile = `./${process.env.ENVIRONMENT || 'local'}`;
58
- const envSeeds = require(seedFile);
59
- await seed({ ...commonSeeds, ...envSeeds });
60
- };
@@ -1,28 +0,0 @@
1
- export const aggregatedCycles = [
2
- {
3
- jsonld_pivoted: {
4
- '@id': 'test_cycle_id',
5
- '@type': 'Cycle',
6
- site: { '@id': 'test_site_id' }
7
- }
8
- }
9
- ];
10
-
11
- export const aggregatedImpactAssessments = [
12
- {
13
- jsonld_pivoted: {
14
- '@id': 'test_impact_assessment_id',
15
- '@type': 'ImpactAssessment',
16
- cycle: { '@id': 'test_cycle_id' }
17
- }
18
- }
19
- ];
20
-
21
- export const aggregatedSites = [
22
- {
23
- jsonld_pivoted: {
24
- '@id': 'test_site_id',
25
- '@type': 'Site'
26
- }
27
- }
28
- ];
@@ -1,3 +0,0 @@
1
- export const aggregatedCycles = [];
2
-
3
- export const aggregatedImpactAssessments = [];
@@ -1,5 +0,0 @@
1
- export const aggregatedCycles = [];
2
-
3
- export const aggregatedImpactAssessments = [];
4
-
5
- export const aggregatedSites = [];
package/dev.ts DELETED
@@ -1,3 +0,0 @@
1
- require('dotenv').config();
2
-
3
- require('./src').run();
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validFilterFields = void 0;
4
- exports.validFilterFields = [
5
- 'regions',
6
- 'periods',
7
- 'products',
8
- 'defaultMethodClassifications',
9
- 'practices',
10
- 'minAggregatedQualityScore'
11
- ];
@@ -1,42 +0,0 @@
1
- version: '3'
2
-
3
- services:
4
- api:
5
- image: hestia-data-api
6
- build:
7
- context: ./
8
- ports:
9
- - '${PORT}:${PORT}'
10
- env_file: .env
11
- command: sh -c 'npm run migrate && npm run seed && npm run dev'
12
- environment:
13
- - PGHOST=hestia-data-api-local-db
14
- - PGUSER=postgres
15
- - PGDATABASE=postgres
16
- - PGPASSWORD=password
17
- volumes:
18
- - ./logs:/app/logs
19
- - ./scripts:/app/scripts
20
- - ./src:/app/src
21
- depends_on:
22
- db:
23
- condition: service_healthy
24
-
25
- db:
26
- image: postgres:14
27
- container_name: hestia-data-api-local-db
28
- ports:
29
- - 5432:5432
30
- volumes:
31
- - postgres:/data/postgres
32
- environment:
33
- - POSTGRES_USER=postgres
34
- - POSTGRES_PASSWORD=password
35
- - POSTGRES_DB=postgres
36
- healthcheck:
37
- test: ['CMD', 'pg_isready', '-q', '-d', 'postgres', '-U', 'postgres']
38
- interval: 1s
39
- timeout: 5s
40
- retries: 5
41
- volumes:
42
- postgres:
package/envs/.master.env DELETED
@@ -1,7 +0,0 @@
1
- export ENVIRONMENT='production'
2
- export STAGE='prod'
3
- export PGHOST=$PG_HOST_PROD
4
- export PGPASSWORD=$PG_PASSWORD_PROD
5
- export PGDATABASE=$PG_DATABASE
6
- export PGPORT=$PG_PORT
7
- export PGUSER=$PG_USER
package/envs/.staging.env DELETED
@@ -1,7 +0,0 @@
1
- export ENVIRONMENT='staging'
2
- export STAGE='staging'
3
- export PGHOST=$PG_HOST_STAGING
4
- export PGPASSWORD=$PG_PASSWORD_STAGING
5
- export PGDATABASE=$PG_DATABASE
6
- export PGPORT=$PG_PORT
7
- export PGUSER=$PG_USER
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- require('dotenv').config();
2
-
3
- require('./build/src').run();
@@ -1,21 +0,0 @@
1
- {
2
- "name": "@hestia-earth/data-api-serverless",
3
- "dependencies": {
4
- "@hestia-earth/schema": "*",
5
- "@hestia-earth/pipeline-utils": "*",
6
- "@sentry/serverless": "*",
7
- "csvtojson": "*",
8
- "debug": "*",
9
- "exit-hook": "*",
10
- "lodash.chunk": "*",
11
- "lodash.uniqby": "*",
12
- "map-obj": "*",
13
- "pg": "*",
14
- "winston": "*"
15
- },
16
- "devDependencies": {
17
- "serverless": "^3.32.2",
18
- "serverless-deployment-bucket": "^1.6.0",
19
- "serverless-offline": "^12.0.4"
20
- }
21
- }
package/run-docker.sh DELETED
@@ -1,14 +0,0 @@
1
- #!/bin/sh
2
-
3
- docker build --progress=plain \
4
- -t hestia-data-api:latest \
5
- .
6
-
7
- docker run --rm \
8
- --name hestia-data-api \
9
- --env-file .env \
10
- --env PORT=80 \
11
- -v ${PWD}/scripts:/app/scripts \
12
- -v ${PWD}/src:/app/src \
13
- -p 3001:80 \
14
- hestia-data-api:latest npm run dev
package/run-test.sh DELETED
@@ -1,5 +0,0 @@
1
- #!/bin/sh
2
-
3
- docker-compose -f test/docker-compose.yml build
4
- docker-compose -f test/docker-compose.yml run test
5
- docker-compose -f test/docker-compose.yml down