# Domain API Brainstorm

## Resolvers

### createDomain
- add to db as "not ready"
- check cloudfront for an available distro (one with less than 50 aliases)
  
  - if none are available...
    - create a new cloudfront distro
    - create a new SSL certificate for (target-0X.funnels.cc)
    - add that SSL to the ACM
    - add that ACM SSL to the cloudfront distro
    - create a new alias for (target-N).funnels.cc
  
  - check if the domain name cname records are pointing to the available distro's main cname name (e.g. target-01.funnels.cc)
    - if not, set a action queue to check again in 5 minutes
    - if they are...
      - add the domain name to the SSL for that distro
      - re-import the SSL in ACM
      - add the domain name as a new alias on that distro
      - update domain record in db as "ready"

### deleteDomain
- remove alias from cloudfront distro
- update the SSL certificate to not include the domain
- remove from db

## MVP
- add to db (not ready)
- send email to slack to manually add custom domain to cf distro (update to ready)

## Miscellaneous thoughts
- create an ssl with certbot
- update that ssl's info
- delete that ssl
- add a domain to the ssl
- remove a domain from the ssl
- renew a certificate
- list all certs
- filter by renewal date
- create a cf distribution
- delete a distribution
- attach a certificate to a distribution
- get list of aliases
- add an alias
- remove an alias


Types --> Cert; Domain; Distribution
--- they're all connected
--- add a cert and it gets created
--- connect to a domain and it cert gets updated
--- connect to a distribution and distro gets updated with alias


MVP Version
- manually create a multi-domain ssl on certbot and upload it to a new CF distribution
- make the createDomain mutation 
  - require adding a CF Distribution
  - add the domain to the newly created certificate, 
  - re-issue the certificiate in ACM, 
  - then add a new alias to CF
- make sure to pass the CFDIstrId to the publish mutation

------------------------------------------------------------------------------------------------

MVP...
- As a user I want to add a custom domain to my account
- As a user I want that custom domain to have SSL installed (ideally automatically)
- As an admin I want to add up to 50 domains on a certificate
- As an admin I want to create a new certificate on the 51st domain
- As an admin I want to create a new distro to bind new certificates to
- As an admin I want to add new domain alias to the distro upon user requests
- As an admin I want to revoke a domain from a certificate
- As an admin I want to remove a domain alias from the distro
- As an admin I want to use dig to check the readiness state of a domain (check every 5 mins, then add alias/ssl once ready)

Best bet is to create each command, then create two simple super-resolvers to manpulate those commands (e.g. createDomain, deleteDomain)


- As an admin I want resolvers that can create, read one, read all, update certificates