@dooer/dooer-test-env 1.0.3 → 1.2.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/lib/account.js CHANGED
@@ -7,6 +7,7 @@
7
7
  // - service_accounts.companies2users the given user linked as role 'Owner'
8
8
  // - service_accounts.subscriptions the same active set Ghost Inspector has on staging
9
9
  // - service_accounts."partnerOrganization" the org placed under partner `dooer` by default
10
+ // - service_accounts."tosAcceptance" the current Terms of Service pre-accepted (so sumify doesn't block)
10
11
  // It does NOT add customer data (ledger, documents, tasks, …) — the account starts empty.
11
12
 
12
13
  const crypto = require('crypto')
@@ -50,10 +51,20 @@ async function createAccount({ local, name, ownerUserId, execute = false } = {})
50
51
  const client = new Client({ ...local, ssl: local.ssl === false ? undefined : { rejectUnauthorized: false } })
51
52
  await client.connect()
52
53
  try {
53
- const owner = await client.query('SELECT users_pk, email FROM service_accounts.users WHERE users_pk=$1', [
54
- ownerUserId,
55
- ])
54
+ // user_type is the fk_user_roles_at_dooer_pk column (User model). Only 'customer' users get a
55
+ // type:'customer' login token; a 'hi'/admin user is blocked from customer-only flows (e.g. accepting
56
+ // Terms of Service in sumify → "only-owner-can-accept-tos"). Warn if the owner isn't a customer.
57
+ const owner = await client.query(
58
+ 'SELECT users_pk, email, fk_user_roles_at_dooer_pk AS user_type FROM service_accounts.users WHERE users_pk=$1',
59
+ [ownerUserId]
60
+ )
56
61
  if (!owner.rowCount) throw new Error(`owner user ${ownerUserId} not found in the local DB (run \`db pull\` first?)`)
62
+ const ownerType = owner.rows[0].user_type
63
+ const warning =
64
+ ownerType === 'customer'
65
+ ? null
66
+ : `owner ${ownerUserId} is a '${ownerType}' user, not 'customer' — customer-only flows ` +
67
+ `(e.g. accepting Terms of Service in sumify) will fail. Use a customer user as the owner.`
57
68
 
58
69
  const partner = await client.query('SELECT id, name FROM service_accounts.partner WHERE domain=$1', [
59
70
  DEFAULT_PARTNER_DOMAIN,
@@ -67,8 +78,10 @@ async function createAccount({ local, name, ownerUserId, execute = false } = {})
67
78
  name,
68
79
  shortName,
69
80
  owner: owner.rows[0].email,
81
+ ownerType,
70
82
  partner: DEFAULT_PARTNER_DOMAIN,
71
83
  subscriptions: SUBSCRIPTION_TYPES,
84
+ warning,
72
85
  }
73
86
  if (!execute) {
74
87
  console.log('DRY-RUN (pass --execute to create):')
@@ -105,6 +118,19 @@ async function createAccount({ local, name, ownerUserId, execute = false } = {})
105
118
  VALUES ($1,$2,$3,now(),now())`,
106
119
  [uuid(), partner.rows[0].id, orgId]
107
120
  )
121
+ // Pre-accept the current Terms of Service so the account is ready to use (sumify otherwise prompts and
122
+ // blocks). Accept every active tos (usedFrom passed, not yet ended), acceptedBy the owner.
123
+ const activeTos = await client.query(
124
+ 'SELECT id FROM service_accounts.tos WHERE "usedFrom" <= now() AND ("usedTo" IS NULL OR "usedTo" > now())'
125
+ )
126
+ for (const row of activeTos.rows) {
127
+ await client.query(
128
+ `INSERT INTO service_accounts."tosAcceptance" (id, "tosId", "organizationId", "acceptedBy", "createdAt", "updatedAt")
129
+ VALUES ($1,$2,$3,$4,now(),now())`,
130
+ [uuid(), row.id, orgId, ownerUserId]
131
+ )
132
+ }
133
+ plan.tosAccepted = activeTos.rowCount
108
134
  await client.query('COMMIT')
109
135
  return plan
110
136
  } catch (e) {
@@ -96,10 +96,12 @@ module.exports = {
96
96
  console.log(chalk.green(`\ncreated account "${res.name}"`))
97
97
  console.log(` org id: ${res.orgId}`)
98
98
  console.log(` short name: ${res.shortName}`)
99
- console.log(` owner: ${argv.owner} (${res.owner}) — role Owner`)
99
+ console.log(` owner: ${argv.owner} (${res.owner}) — role Owner, user_type '${res.ownerType}'`)
100
100
  console.log(` partner: ${res.partner}`)
101
101
  console.log(` subscriptions: ${SUBSCRIPTION_TYPES.join(', ')} (active)`)
102
+ console.log(` TOS: ${res.tosAccepted} version(s) pre-accepted`)
102
103
  }
104
+ if (res.warning) console.log(chalk.yellow(`\n⚠ ${res.warning}`))
103
105
  },
104
106
  })
105
107
  .demandCommand(1, 'Use: customer copy | customer purge | customer new')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dooer/dooer-test-env",
3
- "version": "1.0.3",
3
+ "version": "1.2.0",
4
4
  "description": "Run the whole Dooer backend locally (staging DB minus customers), copy/purge customers between environments, and shred — one CLI.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": "Dooer/cli-dooer-test-env",