@dooer/dooer-test-env 1.0.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.
Files changed (60) hide show
  1. package/bin/index.js +7 -0
  2. package/discovery-router/Dockerfile +18 -0
  3. package/discovery-router/README.md +99 -0
  4. package/discovery-router/package.json +13 -0
  5. package/discovery-router/registry.example.json +5 -0
  6. package/discovery-router/server.js +272 -0
  7. package/lib/account.js +120 -0
  8. package/lib/auth-dev-keys.js +12 -0
  9. package/lib/bankid.js +130 -0
  10. package/lib/cli.js +27 -0
  11. package/lib/command/bankid.js +45 -0
  12. package/lib/command/customer.js +108 -0
  13. package/lib/command/db.js +156 -0
  14. package/lib/command/env.js +114 -0
  15. package/lib/command/logs.js +143 -0
  16. package/lib/command/measure.js +81 -0
  17. package/lib/command/service.js +166 -0
  18. package/lib/command/setup.js +92 -0
  19. package/lib/command/shred.js +60 -0
  20. package/lib/compose/README.md +98 -0
  21. package/lib/compose/generate.js +375 -0
  22. package/lib/compose/manifests.js +108 -0
  23. package/lib/db/roles.js +118 -0
  24. package/lib/discovery/client.js +40 -0
  25. package/lib/engine/GUIDE.md +176 -0
  26. package/lib/engine/PROCESS.md +571 -0
  27. package/lib/engine/dbbuild.js +325 -0
  28. package/lib/engine/gen-schema-map.js +479 -0
  29. package/lib/engine/purge.js +137 -0
  30. package/lib/engine/schema-map.json +11016 -0
  31. package/lib/engine/seed.js +1045 -0
  32. package/lib/obc.js +72 -0
  33. package/lib/registry.js +123 -0
  34. package/lib/runtime.js +101 -0
  35. package/lib/service-token.js +40 -0
  36. package/lib/shred/README.md +118 -0
  37. package/lib/shred/audit.js +128 -0
  38. package/lib/shred/faker.js +545 -0
  39. package/lib/shred/index.js +126 -0
  40. package/lib/shred/scripts/base-partner-emails.sql +9 -0
  41. package/lib/shred/scripts/dev-accounts.sql +195 -0
  42. package/lib/shred/scripts/emails.sql +48 -0
  43. package/lib/shred/scripts/institution-browser.sql +3 -0
  44. package/lib/shred/scripts/notification-targets.sql +5 -0
  45. package/lib/shred/scripts/partners.sql +2 -0
  46. package/lib/shred/scripts/passwords.sql +8 -0
  47. package/lib/shred/scripts/personal-numbers.sql +177 -0
  48. package/lib/shred/scripts/phone-numbers.sql +22 -0
  49. package/lib/shred/scripts/salary-spec-reports.sql +5 -0
  50. package/lib/shred/scripts/service-activity-tracker-data.sql +4 -0
  51. package/lib/shred/scripts/service-core-objects.sql +19 -0
  52. package/lib/shred/scripts/service-event-stream.sql +2 -0
  53. package/lib/shred/scripts/service-integrations.sql +4 -0
  54. package/lib/shred/scripts/template.sql +4 -0
  55. package/lib/shred/scripts/x-service-billing.sql +34 -0
  56. package/lib/shred/scripts/xxx-history-tables.sql +25 -0
  57. package/lib/stub.js +8 -0
  58. package/local-postgres/Dockerfile +11 -0
  59. package/package.json +46 -0
  60. package/readme.md +92 -0
@@ -0,0 +1,195 @@
1
+ CREATE OR REPLACE FUNCTION luhn_generate_checkdigit(int8) RETURNS int8 AS $$
2
+ SELECT
3
+ ((INT8 '10' - SUM(doubled_digit / INT8 '10' + doubled_digit % INT8 '10') % INT8 '10') % INT8 '10')::INT8
4
+ FROM (SELECT
5
+ MOD( ($1::int8 / (10^n)::int8), 10::int8 ) * (2 - MOD(n,2))
6
+ AS doubled_digit
7
+ FROM generate_series(0, CEIL(LOG($1))::INTEGER - 1) AS n
8
+ ) AS doubled_digits;
9
+ $$ LANGUAGE SQL
10
+ IMMUTABLE
11
+ STRICT;
12
+
13
+ CREATE OR REPLACE FUNCTION luhn_generate(int8) RETURNS int8 AS $$
14
+ SELECT 10 * $1 + luhn_generate_checkdigit($1);
15
+ $$ LANGUAGE SQL
16
+ IMMUTABLE
17
+ STRICT;
18
+
19
+ CREATE OR REPLACE FUNCTION date_with_index_in_range_sequence(start_date TIMESTAMP, end_date TIMESTAMP, entries_per_date INTEGER) RETURNS BIGINT AS $$
20
+ DECLARE
21
+ sequence_name TEXT;
22
+ max_value INTEGER;
23
+ next_value INTEGER;
24
+ BEGIN
25
+ sequence_name := 'date_sequence' || to_char(start_date, 'YYYYMMDD') || to_char(end_date, 'YYYYMMDD') || entries_per_date;
26
+ max_value := extract(DAYS FROM end_date - start_date)::INTEGER * entries_per_date;
27
+ EXECUTE 'CREATE TEMPORARY SEQUENCE IF NOT EXISTS ' || sequence_name || ' MINVALUE 1 MAXVALUE ' || max_value + 1;
28
+ next_value := nextval(sequence_name);
29
+ return CAST(
30
+ to_char(start_date + CAST(floor((next_value - 1) / entries_per_date) || ' days' AS INTERVAL), 'YYYYMMDD') ||
31
+ lpad(mod(next_value - 1, entries_per_date) :: TEXT, length((entries_per_date - 1) :: TEXT), '0') AS BIGINT);
32
+ END;
33
+ $$
34
+ LANGUAGE PLPGSQL
35
+ STRICT;
36
+
37
+ CREATE OR REPLACE FUNCTION createAccount(fname text) RETURNS VOID AS
38
+ $$
39
+ DECLARE
40
+ owner_id uuid;
41
+ admin_id uuid;
42
+ staff_id uuid;
43
+ company_id uuid;
44
+ BEGIN
45
+ INSERT INTO
46
+ service_accounts.users (
47
+ "fk_user_roles_at_dooer_pk",
48
+ "first_name",
49
+ "last_name",
50
+ "email",
51
+ "password_hash",
52
+ "api_uuid"
53
+ )
54
+ VALUES
55
+ (
56
+ 'customer',
57
+ fname,
58
+ 'ownersson',
59
+ fname || '@example.com',
60
+ crypt('money1234MONEY', gen_salt('bf', 8))::bytea,
61
+ 'e723a0be-4576-5c10-8035-a05e29bb65c7'
62
+ )
63
+ ON CONFLICT (email, fk_user_roles_at_dooer_pk) WHERE email IS NOT NULL DO UPDATE SET first_name = EXCLUDED.first_name
64
+ RETURNING users_pk INTO owner_id;
65
+
66
+ INSERT INTO
67
+ service_accounts.users (
68
+ "fk_user_roles_at_dooer_pk",
69
+ "first_name",
70
+ "last_name",
71
+ "email",
72
+ "password_hash",
73
+ "api_uuid"
74
+ )
75
+ VALUES
76
+ (
77
+ 'customer',
78
+ fname,
79
+ 'staffsson',
80
+ fname || '+staff@example.com',
81
+ crypt('money1234MONEY', gen_salt('bf', 8))::bytea,
82
+ 'e723a0be-4576-5c10-8035-a05e29bb65c7'
83
+ )
84
+ ON CONFLICT (email, fk_user_roles_at_dooer_pk) WHERE email IS NOT NULL DO UPDATE SET first_name = EXCLUDED.first_name
85
+ RETURNING users_pk INTO staff_id;
86
+
87
+ INSERT INTO
88
+ service_accounts.users (
89
+ "fk_user_roles_at_dooer_pk",
90
+ "first_name",
91
+ "last_name",
92
+ "email",
93
+ "password_hash",
94
+ "api_uuid"
95
+ )
96
+ VALUES
97
+ (
98
+ 'customer',
99
+ fname,
100
+ 'adminsson',
101
+ fname || '+admin@example.com',
102
+ crypt('money1234MONEY', gen_salt('bf', 8))::bytea,
103
+ 'e723a0be-4576-5c10-8035-a05e29bb65c7'
104
+ )
105
+ ON CONFLICT (email, fk_user_roles_at_dooer_pk) WHERE email IS NOT NULL DO UPDATE SET first_name = EXCLUDED.first_name
106
+ RETURNING users_pk INTO admin_id;
107
+
108
+ INSERT INTO
109
+ service_accounts.companies (
110
+ "fk_countries_pk",
111
+ "fk_company_types_pk",
112
+ "organization_number",
113
+ "company_name",
114
+ "short_name",
115
+ "address",
116
+ "postal_code",
117
+ "city",
118
+ "api_uuid"
119
+ )
120
+ VALUES
121
+ (
122
+ 'SE',
123
+ 'AB',
124
+ luhn_generate(date_with_index_in_range_sequence(TIMESTAMP '1700-01-01', TIMESTAMP '1799-12-31', 1000)),
125
+ fname,
126
+ REPLACE(fname, '.', ''),
127
+ 'Gatan 56',
128
+ '12345',
129
+ 'Staden',
130
+ 'e723a0be-4576-5c10-8035-a05e29bb65c7'
131
+ )
132
+ ON CONFLICT (short_name) DO UPDATE SET company_name = EXCLUDED.company_name
133
+ RETURNING companies_pk INTO company_id;
134
+
135
+ INSERT INTO
136
+ service_accounts.companies2users (
137
+ "fk_companies_pk",
138
+ "fk_users_pk",
139
+ "fk_user_roles_at_companies_pk",
140
+ "api_uuid"
141
+ )
142
+ VALUES
143
+ (
144
+ company_id,
145
+ owner_id,
146
+ 'Owner',
147
+ 'e723a0be-4576-5c10-8035-a05e29bb65c7'
148
+ ),
149
+ (
150
+ company_id,
151
+ admin_id,
152
+ 'Admin',
153
+ 'e723a0be-4576-5c10-8035-a05e29bb65c7'
154
+ ),
155
+ (
156
+ company_id,
157
+ staff_id,
158
+ 'Staff',
159
+ 'e723a0be-4576-5c10-8035-a05e29bb65c7'
160
+ ),
161
+ (
162
+ 'e45a3bc4-1b61-4f55-9bd6-de2705420cc2',
163
+ owner_id,
164
+ 'Admin',
165
+ 'e723a0be-4576-5c10-8035-a05e29bb65c7'
166
+ )
167
+ ON CONFLICT ON CONSTRAINT companies2users_fk_companies_pk_fk_users_pk_key DO NOTHING;
168
+
169
+ INSERT INTO
170
+ service_accounts.subscriptions (
171
+ "fk_companies_pk",
172
+ "subscription_type",
173
+ "start_date",
174
+ "end_date",
175
+ "fee_ex_vat",
176
+ "api_uuid"
177
+ )
178
+ SELECT company_id, 'accounting', '2000-01-01', '2280-12-31', 0, 'e723a0be-4576-5c10-8035-a05e29bb65c7'
179
+ WHERE
180
+ NOT EXISTS (
181
+ SELECT fk_companies_pk FROM service_accounts.subscriptions WHERE fk_companies_pk = company_id
182
+ );
183
+ END
184
+ $$
185
+ LANGUAGE 'plpgsql';
186
+
187
+
188
+ SELECT createAccount('johan');
189
+ SELECT createAccount('osm');
190
+ SELECT createAccount('kustera');
191
+ SELECT createAccount('tunell');
192
+ SELECT createAccount('linus');
193
+ SELECT createAccount('fredrik');
194
+ SELECT createAccount('markus.klock');
195
+ SELECT createAccount('jma');
@@ -0,0 +1,48 @@
1
+ -- Updates all tables which include real emails to a hashed version
2
+
3
+ UPDATE service_outgoing_email.email
4
+ SET "toEmail" = concat('testcustomer+', MD5("toEmail"), '@dooer.com')
5
+ WHERE "toEmail" != ''
6
+ AND "companyId" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags));
7
+
8
+ UPDATE service_outgoing_email.email
9
+ SET "toEmail" = concat('testcustomer+', MD5("toEmail"), '@dooer.com')
10
+ WHERE "toEmail" != '' AND "companyId" IS NULL;
11
+
12
+ UPDATE service_invoices.invoice
13
+ SET "companyEmail" = concat('testcustomer+', MD5("companyEmail"), '@dooer.com')
14
+ WHERE "companyEmail" != ''
15
+ AND "organizationId" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags));
16
+
17
+ UPDATE service_invoices.invoice
18
+ SET "billingEmail" = concat('testcustomer+', MD5("billingEmail"), '@dooer.com')
19
+ WHERE "billingEmail" != ''
20
+ AND "organizationId" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags));
21
+
22
+ UPDATE service_orders.contact
23
+ SET "email" = concat('testcustomer+', MD5("email"), '@dooer.com')
24
+ WHERE "email" != '';
25
+
26
+ UPDATE "service_salaries"."salarySpecification"
27
+ SET "employeeEmail" = concat('testcustomer+', MD5("employeeEmail"), '@dooer.com')
28
+ WHERE "employeeEmail" != ''
29
+ AND "organizationId" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags));
30
+
31
+ UPDATE service_accounts.incoming_email_whitelists
32
+ SET "email" = concat('testcustomer+', MD5("email"), '@dooer.com')
33
+ WHERE "email" != ''
34
+ AND "fk_companies_pk" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags));
35
+
36
+ UPDATE service_accounts.invites
37
+ SET "email" = concat('testcustomer+', MD5("email"), '@dooer.com')
38
+ WHERE "email" != ''
39
+ AND "fk_companies_pk" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags));
40
+
41
+ UPDATE service_accounts.users
42
+ SET "contactEmail" = concat('testcustomer+', MD5("contactEmail"), '@dooer.com')
43
+ WHERE "contactEmail" != '';
44
+
45
+ UPDATE service_billing."companyInformation"
46
+ SET "email" = concat('testcustomer+', MD5("email"), '@dooer.com')
47
+ WHERE "email" != ''
48
+ AND "organizationId" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags));
@@ -0,0 +1,3 @@
1
+ -- Drop all rows containing cookie data.
2
+
3
+ DELETE FROM service_institution_browser."cookieJar";
@@ -0,0 +1,5 @@
1
+ -- Drop all rows that can allow us to send notifications from dev/stage envs.
2
+
3
+ DELETE FROM service_notification_targets.twilio;
4
+
5
+ --SELECT * FROM service_notification_targets.twilio
@@ -0,0 +1,2 @@
1
+ UPDATE "service_accounts"."partner" SET "isDefaultPartner" = false;
2
+ UPDATE "service_accounts"."partner" SET "isDefaultPartner" = true WHERE "domain" = 'dooer-devteam';
@@ -0,0 +1,8 @@
1
+ CREATE EXTENSION IF NOT EXISTS pgcrypto;
2
+
3
+ UPDATE
4
+ service_accounts.users
5
+ SET
6
+ password_hash = crypt('money1234MONEY', gen_salt('bf', 8))::bytea;
7
+
8
+ TRUNCATE TABLE service_accounts_history.users;
@@ -0,0 +1,177 @@
1
+ CREATE OR REPLACE FUNCTION md5_int(text) RETURNS int as $$
2
+ SELECT ('x' || substr(md5($1), 1, 8))::bit(32)::int;
3
+ $$ LANGUAGE SQL
4
+ IMMUTABLE
5
+ STRICT;
6
+
7
+ CREATE OR REPLACE FUNCTION luhn_verify(int8) RETURNS BOOLEAN AS $$
8
+ SELECT
9
+ MOD(SUM(doubled_digit / INT8 '10' + doubled_digit % INT8 '10'), 10) = 0
10
+ FROM
11
+ (SELECT
12
+ MOD( ( $1::int8 / (10^n)::int8 ), 10::int8) * (MOD(n,2) + 1)
13
+ AS doubled_digit
14
+ FROM generate_series(0, CEIL(LOG( $1 ))::INTEGER - 1) AS n
15
+ ) AS doubled_digits;
16
+
17
+ $$ LANGUAGE SQL
18
+ IMMUTABLE
19
+ STRICT;
20
+
21
+ CREATE OR REPLACE FUNCTION luhn_generate_checkdigit(int8) RETURNS int8 AS $$
22
+ SELECT
23
+ ((INT8 '10' - SUM(doubled_digit / INT8 '10' + doubled_digit % INT8 '10') % INT8 '10') % INT8 '10')::INT8
24
+ FROM (SELECT
25
+ MOD( ($1::int8 / (10^n)::int8), 10::int8 ) * (2 - MOD(n,2))
26
+ AS doubled_digit
27
+ FROM generate_series(0, CEIL(LOG($1))::INTEGER - 1) AS n
28
+ ) AS doubled_digits;
29
+
30
+ $$ LANGUAGE SQL
31
+ IMMUTABLE
32
+ STRICT;
33
+
34
+ CREATE OR REPLACE FUNCTION luhn_generate(int8) RETURNS int8 AS $$
35
+ SELECT 10 * $1 + luhn_generate_checkdigit($1);
36
+ $$ LANGUAGE SQL
37
+ IMMUTABLE
38
+ STRICT;
39
+
40
+ CREATE OR REPLACE FUNCTION luhn_strip(int8) RETURNS int8 AS $$
41
+ SELECT $1 / 10;
42
+ $$ LANGUAGE SQL
43
+ IMMUTABLE
44
+ STRICT;
45
+
46
+ -- Create random personal numbers
47
+ UPDATE service_employees.employee SET "sePersonnummer" = luhn_generate(1000 * CAST(to_char(TIMESTAMP '1899-12-31' + random() * (TIMESTAMP '1800-01-01' - TIMESTAMP '1899-12-31'), 'YYYYMMDD') AS bigint) + CAST(floor(1000 * random()) as bigint));
48
+ UPDATE service_employees.employee SET "taxIdentification" = json_build_object('value',"sePersonnummer",'type','sePersonnummer');
49
+ UPDATE service_employees_legacy.employee SET "sePersonnummer" = luhn_generate(1000 * CAST(to_char(TIMESTAMP '1899-12-31' + random() * (TIMESTAMP '1800-01-01' - TIMESTAMP '1899-12-31'), 'YYYYMMDD') AS bigint) + CAST(floor(1000 * random()) as bigint));
50
+ UPDATE service_salaries."salarySpecification" SET "employeePersonalIdNumber" = luhn_generate(1000 * CAST(to_char(TIMESTAMP '1899-12-31' + random() * (TIMESTAMP '1800-01-01' - TIMESTAMP '1899-12-31'), 'YYYYMMDD') AS bigint) + CAST(floor(1000 * random()) as bigint));
51
+ UPDATE service_salaries_legacy."salarySpecification" SET "employeePersonalIdNumber" = luhn_generate(1000 * CAST(to_char(TIMESTAMP '1899-12-31' + random() * (TIMESTAMP '1800-01-01' - TIMESTAMP '1899-12-31'), 'YYYYMMDD') AS bigint) + CAST(floor(1000 * random()) as bigint));
52
+
53
+ -- Set fake organizationNumber for billing company
54
+ UPDATE service_billing."companyInformation" SET "organizationNumber" = '191212121212';
55
+
56
+ -- Create random organizationNumber for billing customer
57
+ UPDATE service_billing.customer SET "organizationNumber" = luhn_generate(1000 * CAST(to_char(TIMESTAMP '1899-12-31' + random() * (TIMESTAMP '1800-01-01' - TIMESTAMP '1899-12-31'), 'YYYYMMDD') AS bigint) + CAST(floor(1000 * random()) as bigint))
58
+ WHERE service_billing.customer."type" = 'privatePerson';
59
+
60
+ UPDATE service_billing.customer SET "organizationNumber" = luhn_generate(444000000 + md5_int("organizationNumber") % 5000000)
61
+ WHERE service_billing.customer."type" = 'company';
62
+
63
+ CREATE OR REPLACE FUNCTION date_with_index_in_range_sequence(start_date TIMESTAMP, end_date TIMESTAMP, entries_per_date INTEGER) RETURNS BIGINT AS $$
64
+ DECLARE
65
+ sequence_name TEXT;
66
+ max_value INTEGER;
67
+ next_value INTEGER;
68
+ BEGIN
69
+ sequence_name := 'date_sequence' || to_char(start_date, 'YYYYMMDD') || to_char(end_date, 'YYYYMMDD') || entries_per_date;
70
+ max_value := extract(DAYS FROM end_date - start_date)::INTEGER * entries_per_date;
71
+ EXECUTE 'CREATE TEMPORARY SEQUENCE IF NOT EXISTS ' || sequence_name || ' MINVALUE 1 MAXVALUE ' || max_value + 1;
72
+ next_value := nextval(sequence_name);
73
+ return CAST(
74
+ to_char(start_date + CAST(floor((next_value - 1) / entries_per_date) || ' days' AS INTERVAL), 'YYYYMMDD') ||
75
+ lpad(mod(next_value - 1, entries_per_date) :: TEXT, length((entries_per_date - 1) :: TEXT), '0') AS BIGINT);
76
+ END;
77
+ $$
78
+ LANGUAGE PLPGSQL
79
+ STRICT;
80
+
81
+ DO $$
82
+ DECLARE
83
+ c CURSOR FOR
84
+ SELECT accounts_at_institution_pk, luhn_generate(444000000 + md5_int("organization_number") % 5000000) AS new_organization_number
85
+ FROM service_core_objects.accounts_at_institution au
86
+ JOIN service_core_objects.accounts_at_institution2users au2u ON au.accounts_at_institution_pk = au2u.fk_accounts_at_institution_pk
87
+ JOIN service_accounts.users u ON u.users_pk = au2u.fk_users_pk
88
+ WHERE u.email != ''
89
+ AND NOT (
90
+ u.email ILIKE '%@dooer.com'
91
+ OR
92
+ u.email ILIKE '%@voitto.se'
93
+ OR
94
+ u.email ILIKE '%@example.com'
95
+ OR
96
+ u.email = 'johan@steffner.nu'
97
+ )
98
+ ORDER BY au.organization_number ASC
99
+ FOR UPDATE;
100
+ BEGIN
101
+ FOR row IN c LOOP
102
+ UPDATE service_core_objects.accounts_at_institution
103
+ SET organization_number = row.new_organization_number
104
+ WHERE CURRENT OF c;
105
+ END LOOP;
106
+ END
107
+ $$;
108
+
109
+ DO $$
110
+ DECLARE
111
+ c CURSOR FOR
112
+ SELECT accounts_at_institution2users_pk, luhn_generate(date_with_index_in_range_sequence(TIMESTAMP '1000-01-01', TIMESTAMP '1899-12-31', 1000)) AS new_credentials_user
113
+ FROM service_core_objects.accounts_at_institution2users au2u
114
+ JOIN service_accounts.users u ON u.users_pk = au2u.fk_users_pk
115
+ WHERE u.email != ''
116
+ AND NOT (
117
+ u.email ILIKE '%@dooer.com'
118
+ OR
119
+ u.email ILIKE '%@voitto.se'
120
+ OR
121
+ u.email ILIKE '%@example.com'
122
+ OR
123
+ u.email = 'johan@steffner.nu'
124
+ )
125
+ ORDER BY au2u.credentials_user ASC
126
+ FOR UPDATE;
127
+ BEGIN
128
+ FOR row IN c LOOP
129
+ UPDATE service_core_objects.accounts_at_institution2users
130
+ SET credentials_user = row.new_credentials_user
131
+ WHERE CURRENT OF c;
132
+ END LOOP;
133
+ END
134
+ $$;
135
+
136
+ -- For users, we just empty them
137
+ UPDATE service_accounts.users SET id_number = NULL
138
+ WHERE email != ''
139
+ AND NOT (
140
+ ("email" ILIKE '%@dooer.com' AND NOT "email" ILIKE '%live-email%')
141
+ OR
142
+ "email" ILIKE '%@voitto.se'
143
+ OR
144
+ "email" ILIKE '%@example.com'
145
+ OR
146
+ "email" = 'johan@steffner.nu'
147
+ );
148
+
149
+ -- BankID sessions are not needed att all
150
+ TRUNCATE TABLE service_accounts."bankIdSession";
151
+
152
+ -- Generate organization numbers
153
+ DO $$
154
+ DECLARE
155
+ c CURSOR FOR
156
+ SELECT companies_pk, luhn_generate(444000000 + md5_int("organization_number") % 5000000) AS new_organization_number
157
+ FROM service_accounts.companies
158
+ FOR UPDATE;
159
+ BEGIN
160
+ FOR row IN c LOOP
161
+ UPDATE service_accounts.companies
162
+ SET organization_number = row.new_organization_number
163
+ WHERE CURRENT OF c;
164
+ END LOOP;
165
+ END
166
+ $$;
167
+
168
+ -- Update org no. of the salary specifications
169
+ UPDATE service_salaries."salarySpecification" AS s
170
+ SET "companyOrgNumber" = c.organization_number
171
+ FROM service_accounts.companies AS c
172
+ WHERE s."organizationId" = c.companies_pk;
173
+
174
+ UPDATE service_salaries_legacy."salarySpecification" AS s
175
+ SET "companyOrgNumber" = c.organization_number
176
+ FROM service_accounts.companies AS c
177
+ WHERE s."organizationId" = c.companies_pk;
@@ -0,0 +1,22 @@
1
+ -- UPDATE PHONE NUMBERS
2
+ -- it replace the phone numbers in the schemas below
3
+
4
+ UPDATE service_employees.employee
5
+ SET phone = concat('+46555', floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10))
6
+ WHERE phone != '';
7
+
8
+ UPDATE service_employees_legacy.employee
9
+ SET phone = concat('+46555', floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10))
10
+ WHERE phone != '';
11
+
12
+ UPDATE service_orders.contact
13
+ SET phone = concat('+46555', floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10))
14
+ WHERE phone != '';
15
+
16
+ UPDATE service_billing."companyInformation"
17
+ SET phone = concat('+46555', floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10))
18
+ WHERE phone != '';
19
+
20
+ UPDATE service_billing."customerContact"
21
+ SET "cellPhone" = concat('+46555', floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10),floor(random() * 10), floor(random() * 10))
22
+ WHERE "cellPhone" != '';
@@ -0,0 +1,5 @@
1
+ -- Update salary spec reports with shredded employee names
2
+ UPDATE service_core_objects.reports AS r
3
+ SET "description" = 'Lönebesked ' || s."employeeName" || ' ' || s."fromDate"::text || ' - ' || s."toDate"::text
4
+ FROM service_salaries."salarySpecification" AS s
5
+ WHERE s."salaryId" = (r.data->>'salaryId')::uuid;
@@ -0,0 +1,4 @@
1
+ TRUNCATE TABLE
2
+ service_activity_tracker_data."activityTrackerUser",
3
+ service_activity_tracker_data."activityTrackerVisit",
4
+ service_activity_tracker_data."userActivity";
@@ -0,0 +1,19 @@
1
+ UPDATE service_core_objects.reports
2
+ SET data = jsonb_set(sub.data, array['meta', 'attributes', sub.elem_index::text], '{"key": "legalName", "label": "REDACTED", "value": "123456-7890"}')
3
+ FROM
4
+ (
5
+ SELECT reports_pk, data, pos-1 as elem_index
6
+ FROM service_core_objects.reports, jsonb_array_elements(data->'meta'->'attributes')
7
+ WITH ordinality arr(elem, pos)
8
+ WHERE data@> ('{"meta":{"attributes":[{"key":"legalName"}]}}')::jsonb AND elem->>'key' = 'legalName'
9
+ AND "fk_companies_pk" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags))
10
+ ) sub
11
+ WHERE reports.reports_pk = sub.reports_pk;
12
+
13
+ -- DELETE reports affected by this bug
14
+ -- https://github.com/Dooer/service-report-generator/pull/272/files
15
+ DELETE FROM service_core_objects.reports WHERE reports_pk IN (
16
+ SELECT reports_pk
17
+ FROM service_core_objects.reports, jsonb_array_elements(data->'meta'->'attributes')
18
+ WHERE value->>'key' = value->>'label'
19
+ );
@@ -0,0 +1,2 @@
1
+ -- Truncate the events table
2
+ TRUNCATE TABLE "service_event_stream"."event";
@@ -0,0 +1,4 @@
1
+ DELETE FROM service_integrations."integration";
2
+ DELETE FROM service_integrations_history."integration";
3
+ DELETE FROM service_integrations."integrationSync";
4
+ DELETE FROM service_integrations_history."integrationSync";
@@ -0,0 +1,4 @@
1
+ -- The scripts under this folder are
2
+ -- executed in the database which match with the folder name
3
+
4
+ -- You can add more scripts *.sql which will been executed sequentially
@@ -0,0 +1,34 @@
1
+
2
+ UPDATE service_billing."invoiceLine" AS line
3
+ SET description = item.description
4
+ FROM service_billing.item AS item
5
+ WHERE line."itemId" = item.id;
6
+
7
+ -- Last of all billing updates, do the frozenCustomerDetails on invoice
8
+ UPDATE service_billing.invoice AS inv
9
+ SET "frozenCustomerDetails" = jsonb_set("frozenCustomerDetails", '{customer}', row_to_json(customer)::jsonb)
10
+ FROM "service_billing"."customer" AS customer
11
+ WHERE inv."customerId" = customer.id;
12
+
13
+ UPDATE service_billing.invoice AS inv
14
+ SET "frozenCustomerDetails" = jsonb_set("frozenCustomerDetails", '{contact}', row_to_json(contact)::jsonb)
15
+ FROM "service_billing"."customerContact" AS contact
16
+ WHERE inv."customerContactId" = contact.id;
17
+
18
+ UPDATE service_billing.invoice AS inv
19
+ SET "frozenCustomerDetails" = jsonb_set("frozenCustomerDetails", '{companyInfo}', row_to_json("companyInfo")::jsonb)
20
+ FROM "service_billing"."companyInformation" AS "companyInfo"
21
+ WHERE inv."organizationId" = "companyInfo"."organizationId";
22
+
23
+ UPDATE service_billing.invoice AS inv
24
+ SET "frozenCustomerDetails" = jsonb_set("frozenCustomerDetails", '{deliveryAddress}', row_to_json("customerDeliveryAddress")::jsonb)
25
+ FROM "service_billing"."customerAddress" AS "customerDeliveryAddress"
26
+ WHERE inv."deliveryAddressId" = "customerDeliveryAddress".id;
27
+
28
+ UPDATE service_billing.invoice AS inv
29
+ SET "frozenCustomerDetails" = jsonb_set("frozenCustomerDetails", '{invoicingAddress}', row_to_json("customerInvoicingAddress")::jsonb)
30
+ FROM "service_billing"."customerAddress" AS "customerInvoicingAddress"
31
+ WHERE inv."invoicingAddressId" = "customerInvoicingAddress".id;
32
+
33
+ UPDATE service_billing."invoiceDelivery" SET "deliveryOptions" = '{}'
34
+ WHERE "organizationId" NOT IN (SELECT companies_pk from service_accounts.companies WHERE 'test-company' = any(tags));
@@ -0,0 +1,25 @@
1
+ -- Drop all rows from history tables.
2
+
3
+ TRUNCATE TABLE service_accounts_history.companies;
4
+ TRUNCATE TABLE service_accounts_history.incoming_email_whitelists;
5
+ TRUNCATE TABLE service_accounts_history.invites;
6
+ TRUNCATE TABLE service_accounts_history."bankIdSession";
7
+ TRUNCATE TABLE service_core_objects_history.accounts_at_institution;
8
+ TRUNCATE TABLE service_employees_history.employee;
9
+ TRUNCATE TABLE service_employees_history."employeeAddress";
10
+ TRUNCATE TABLE service_employees_legacy_history.employee;
11
+ TRUNCATE TABLE service_employees_legacy_history."employeeAddress";
12
+ TRUNCATE TABLE service_orders_history.contact;
13
+ TRUNCATE TABLE service_outgoing_email_history.email;
14
+ TRUNCATE TABLE service_salaries_history."salarySpecification";
15
+ TRUNCATE TABLE service_salaries_legacy_history."salarySpecification";
16
+
17
+ TRUNCATE TABLE service_billing_history.item;
18
+ TRUNCATE TABLE service_billing_history.invoice;
19
+ TRUNCATE TABLE service_billing_history.customer;
20
+ TRUNCATE TABLE service_billing_history."invoiceDelivery";
21
+ TRUNCATE TABLE service_billing_history."invoiceLine";
22
+ TRUNCATE TABLE service_billing_history."customerAddress";
23
+ TRUNCATE TABLE service_billing_history."customerContact";
24
+ TRUNCATE TABLE service_billing_history."companyInformation";
25
+ TRUNCATE TABLE service_billing_history."paymentIntention";
package/lib/stub.js ADDED
@@ -0,0 +1,8 @@
1
+ const chalk = require('chalk')
2
+
3
+ // A placeholder handler for commands scaffolded but not yet built. Prints what it WILL do + the plan
4
+ // reference, so the CLI surface is complete and discoverable while we fill it in phase by phase.
5
+ module.exports = (label, planned) => () => {
6
+ // eslint-disable-next-line no-console
7
+ console.log(`${chalk.yellow(`${label} is not implemented yet.`)}\n${planned}\nSee ENVIRONMENT-PLAN.md.`)
8
+ }
@@ -0,0 +1,11 @@
1
+ # Local Postgres with SSL enabled. The Dooer services (@dooer/database) ALWAYS connect with ssl
2
+ # (rejectUnauthorized:false) — a plain postgres image (no SSL) makes every service fail with
3
+ # "server does not support SSL". We bake a self-signed cert and start postgres with ssl=on.
4
+ FROM postgres:14
5
+
6
+ RUN set -eux; \
7
+ openssl req -new -x509 -days 3650 -nodes -text \
8
+ -subj "/CN=localhost" \
9
+ -out /etc/postgresql/server.crt -keyout /etc/postgresql/server.key; \
10
+ chmod 600 /etc/postgresql/server.key; \
11
+ chown postgres:postgres /etc/postgresql/server.crt /etc/postgresql/server.key
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@dooer/dooer-test-env",
3
+ "version": "1.0.0",
4
+ "description": "Run the whole Dooer backend locally (staging DB minus customers), copy/purge customers between environments, and shred — one CLI.",
5
+ "license": "UNLICENSED",
6
+ "repository": "Dooer/cli-dooer-test-env",
7
+ "bin": {
8
+ "dooer-test-env": "bin/index.js"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "bin/",
15
+ "lib/",
16
+ "local-postgres/",
17
+ "discovery-router/"
18
+ ],
19
+ "scripts": {
20
+ "start": "node ./bin/index.js",
21
+ "test": "yarn lint",
22
+ "lint": "dooer-lint",
23
+ "gen-schema-map": "node lib/engine/gen-schema-map.js",
24
+ "precommit": "lint-staged"
25
+ },
26
+ "dependencies": {
27
+ "@aws-sdk/client-s3": "^3.600.0",
28
+ "@dooer/package-info": "^1.6.7",
29
+ "chalk": "^4.1.2",
30
+ "js-yaml": "^3.14.1",
31
+ "pg": "^8.23.0",
32
+ "pg-copy-streams": "^6.0.0",
33
+ "pg-cursor": "^2.11.0",
34
+ "yargs": "^17.7.2"
35
+ },
36
+ "devDependencies": {
37
+ "@dooer/eslint-config-dooer": "^6.0.15",
38
+ "husky": "^4.3.8",
39
+ "lint-staged": "^11.1.2"
40
+ },
41
+ "lint-staged": {
42
+ "**/*.js": [
43
+ "yarn lint"
44
+ ]
45
+ }
46
+ }