Commit Graph

900 Commits

Author SHA1 Message Date
Daniel Lockyer
119c013229 Updated bson-objectid calls to match API change
refs c873899e49

- as of `bson-objectid` v2.0.0, this library exports the function
  to generate an ObjectID directly, and then you need to use `.toHexString()`
  to get the 24 character hex string - 6696f27d82
- this commit removes all uses of `.generate()` and replaces with this
  change
2021-07-22 01:53:21 +12:00
Peter Zimon
ddedbd4225 Fixed member import email heading spacing 2021-07-22 01:53:21 +12:00
Peter Zimon
3956f93e17 New logo in Admin (#12768)
refs https://github.com/TryGhost/Team/issues/547

- replaced link to static/squircle to orb
2021-07-22 01:53:21 +12:00
Peter Zimon
251ebeaf30 Updated squircle ref to 4.0 repo 2021-07-22 01:53:21 +12:00
Fabien O'Carroll
58b8101781 Fixed Members importer usage of linkStripeCustomer
no-issue

The method signature was updated in the refactor and this was missed
2021-07-22 01:53:21 +12:00
Naz
bfdb6b95fe Extracted members controller's import method
refs #12537

- Moved code related to the importer into the MembersImporter class to  keep the controller code light
2021-07-22 01:53:21 +12:00
Peter Zimon
d12206a5f9 Import email refinements (#12473)
* Updated import email subject

* Updated import email title

* Fixed copy in import email to reflect if there was at least one member added
2021-07-22 01:53:21 +12:00
Fabien O'Carroll
085820bfa8 Added new members importer module
no-issue

This module encapsulates the work around performing imports, it
currently uses the concept of a "Job" which at the moment is not
persisted to the database, however when we want to look at resuming
imports after a server restart, this should give us the flexibility to
do it.
2021-07-22 01:53:21 +12:00
Fabien O'Carroll
0b82f2a9d6 Added email template for completion of background jobs
no-issue

This will be used to generate email content used for notifying users
that their import has been completed.
2021-07-22 01:53:21 +12:00
Fabien O'Carroll
c17c0ec763 Removed support for batched CSV importer
no-issue

We are rewriting the Members CSV importer to use background jobs, the
batched importer will no longer be used locally.
2021-07-22 01:53:21 +12:00
Scott Cabot
1d65c9367c Fixed user import with no created_at date breaking graph
- users imported from CSV with no created_at date where having their created_at date being stored as an int rather than a datetime.
- this was causing parsing issues with the graph so this commit fixes the formatting
2021-07-22 01:53:21 +12:00
Talha
574f2ca9c1 🐛 Fixed table constraint error when updating member's email with an already existing email (#12178)
closes #12045

- When member's email is updated to an already existing email of different member it caused table's unique constraint error, which was not handled properly. 
- Added handling for this error similar to one in members `add` method.
2021-07-22 01:53:21 +12:00
Nazar Gargol
8ea9896622 Refactored members imporeter in preparation for jobs
no issue

- This refactor extracts labels related code into a separate module for easier reuse by the "job-aware" batched importer
2021-07-22 01:53:21 +12:00
Nazar Gargol
8f1691b052 Improved import_label creation logic
no issue

- When an import was done and there were no "global labels" present Ghost created generic `import-[data]` label which later helped to find a specific batch of imported data
- It did not make sense to create such generic label when user provided their own unique label
- The rules that work now are:
1. When there is no global provided Ghost generates on and removes it in case there are no imported records
2. When there is a unique new global label provided no new label is generated, but the label stays even if there are no imported records
2021-07-22 01:53:21 +12:00
Nazar Gargol
3fa94b579d Removed date handling validation in members importer logic
no issue

- This is handled on input sanitization layer with date
format check in JSON schema validation, so there's no need to do this
check again in the importer.
2021-07-22 01:53:21 +12:00
Nazar Gargol
4fe9d1536c Added error handling for failed member imports
no issue

- When bulk insert fails there is no transactional logic to revert
related records form being inserted. Also, previously there were no
attempts to "retry" the insert.
- To avoid complex retry logic, an iterative one-by-one insert retry
approach was taken. If this becomes a bottleneck in the future, the
retry algorithm could be improved.
- To avoid a lot of code duplication refactored model's `bulkAdd` & `bulkDestroy`
methods to use 'bulk-operations' module.
- Updated error handling and logging for bulk delete operations. It's very
unlikely for error to happen here,  but still need to make sure there is
a proper logging in place to trace back the failure.
- Added debug logs. This should improve debugging experience and
performance measurements.
- Added handling for unrecognized errors. Handling inspired by current unrecognized
error handling by ghost importer -10e5d5f3d4/core/server/data/importer/importers/data/base.js (L148-L154)
2021-07-22 01:53:21 +12:00
Nazar Gargol
4feaf49ca7 Improved error handling for batch deleted records
no issue

- Similar handling to one introduced in 31db3c86800b3268da5485417b16e0fcd8e6579a
- Having granular tracking for failed to remove id's would make it possible to return more specific errors to the client
2021-07-22 01:53:21 +12:00
Nazar Gargol
e32ce37a89 Improved error handling for batch inserted records
no issue

- Similar to 4f9e787119221ecb6b6e9703e020ea0e30a37b76 this adds error handling to batch operations done outside models
2021-07-22 01:53:21 +12:00
Nazar Gargol
b47c151855 Refactored bulk insert/delete operations into separate module
no issue

- Moved bulk db operations outside of importer module to create clearer separation of responsibilities
2021-07-22 01:53:21 +12:00
naz
29f9d60d3b Improved error handling for batch inserted member records (#12146)
no issue

- When batch insert fails handling should be more granular and aim to retry and insert as many records from the batch as possible.  
- Added retry logic for failed member's batch inserts. It's a sequential insert for each record in the batch. This implementation was chosen to keep it as simple as possible
- Added filtering of "toCreate" records when member fails to insert. We should not try inserting related members_labels/members_stripe_customers/members_stripe_customer_subscriptions records because they would definitely fail insertion without associated member record
2021-07-22 01:53:21 +12:00
Nazar Gargol
0756d26d22 Fixed handling for Stripe connected members import
no issue

- When stripe is disconnected and there are Stripe-connected records present in imported set they should not be processed and proper error should be thrown
2021-07-22 01:53:21 +12:00
Nazar Gargol
f928b68ee3 Fixed label serialization in members bulk importer
no issue

- After a refactor logic was missing trimming logic and handling for empty labels
2021-07-22 01:53:21 +12:00
Nazar Gargol
7dc70f5607 Fixed default subscribed value for member model in the importer
no issue

- The default value should not be a string but rather a boolean
2021-07-22 01:53:21 +12:00
Fabien 'egg' O'Carroll
0106138fd5 Updated bulk importer to improve performance (#12128)
no-issue

* Added bulkAdd method to Member,Customer&Subscription model
  This allows us to keep the db access in the model layer
* Updated @tryghost/members-api to 0.27.2
  This includes fixes for rate-limiting of requests, and exposes necessary
  Stripe methods for creating customers and complimentary subscriptions,
  without affecting the database.
* Refactored importer to parallelise tasks where possible
  By parallelising our tasks we are able to improve the speed at which the
  entire import completes.
2021-07-22 01:53:21 +12:00
Nazar Gargol
320cf58ff3 Fixed parameter naming for members importer 2021-07-22 01:53:21 +12:00
Nazar Gargol
ccb3068609 Update Stripe concurrency in members importer
no issue

- There were many failed import records due to rate-limit errors. With concurrency of 9 imports go through with 100% success
- Would need to verify these limits with live API to make the most of it
2021-07-22 01:53:21 +12:00
Nazar Gargol
a6ab9a6db2 Moved batching logic inside the members importer module
no issue

- This way importer is more self contained and controller logic doesn't have to know about batch sizes and other unecessary variables
2021-07-22 01:53:21 +12:00
Fabien 'egg' O'Carroll
39aab8ae28 Replaced all usage of member models with members-api (#12117)
no-issue

* Added stripeSubscriptions relation to member model

This allows us to fetch the subscriptions for a member via standard
model usage, e.g. `withRelated: ['stripeSubscriptions']` rather than
offloading to loops and `decorateWithSubscriptions` functions, this is
more performant and less non-standard than the existing method.

* Updated serialize methods to match existing format

The current usage of `decorateWithSubscriptions` and the usage of
members throughout the codebase has a subscriptions array on a stripe
object on the member, this ensures that when we serialize members to
JSON that we are using the same format.

There is definitely room to change this in future, but this is an
attempt to create as few breaking changes as possible.

* Installed @tryghost/members-api@0.26.0

This includes the required API changes so that everywhere can use
members-api directly rather than models and/or helper methods
2021-07-22 01:53:21 +12:00
Nazar Gargol
c5c57cbd85 Extracted batched member import into separate module
no issue

- The code in controller was becoming hard to reason about.
- Having a single module shows exactly how many dependencies are there to do an import for single batch.
- Having a separate module would make it easier to extract into it's own package in Members monorepo
2021-07-22 01:53:21 +12:00
Fabien O'Carroll
d0f587a6cc Published new versions
- @tryghost/members-api@1.22.1
2021-07-20 12:37:36 +01:00
Fabien O'Carroll
6693d470d0 Removed superfluous benefits relation fetch
refs https://github.com/TryGhost/Team/issues/919

As we pass the `benefits` to the Product model on creation, we do not
need to manually fetch them again. In fact doing so causes a strange SQL
error, where we attempt to run `SELECT undefined.*`.
2021-07-20 12:36:41 +01:00
Fabien O'Carroll
19ae16590d Published new versions
- @tryghost/members-ssr@1.0.8
2021-07-20 10:24:31 +01:00
Fabien O'Carroll
ae9bad957b Fixed _removeSessionCookie method use of cookies
refs https://github.com/TryGhost/Team/issues/908

The `cookies` module will unset a cookie if `null` or `undefined` is
passed as the value, or if the value is not passed. The previous call
was passing the options, which were being read as the value, and
resulting in `'[Object object]'` being stored as a cookie.

Explicitly passing `null` as the value makes this code correct and
easier to maintain.
2021-07-20 10:19:39 +01:00
Fabien O'Carroll
5fc0646d5e Published new versions
- @tryghost/members-api@1.22.0
2021-07-19 13:58:43 +01:00
Fabien O'Carroll
caf059cd7e Added WellKnownController and exposed jwks.json
refs https://github.com/TryGhost/Team/issues/664

The well known controller is designed to handle any requests to the
/.well-known endpoint where the members app is mounted. The first and
only requirement so far is that we expose a JSON Web Key Set so that
external services are able to validate Members JWT's
2021-07-19 13:51:58 +01:00
Rishabh
97be7ca3db Published new versions
- @tryghost/members-api@1.21.0
2021-07-19 17:23:50 +05:30
Rishabh
069accdbe8 Fixed stripe migration to avoid complimentary prices as monthly/yearly price
closes https://github.com/TryGhost/Team/issues/778

- cleans up the stripe migration to add default monthly/yearly prices for sites, which had a possibility of using complimentary (0 amount prices) in edge cases
- adds missing return in the same migration for an unlikely failure to parse stripe plans
2021-07-19 16:20:12 +05:30
Fabien O'Carroll
ceec3efe6a Published new versions
- @tryghost/magic-link@1.0.7
 - @tryghost/members-api@1.20.3
 - @tryghost/members-ssr@1.0.7
2021-07-15 18:19:11 +01:00
Fabien O'Carroll
ac3177e0bb Fixed require paths and top level js files
no-issue

We only include index.js and lib in npm packages.
2021-07-15 18:15:49 +01:00
Fabien O'Carroll
128ce5db9a Published new versions
- @tryghost/members-api@1.20.2
2021-07-15 18:08:17 +01:00
Fabien O'Carroll
15915a6040 Fixed index.js require
no-issue
2021-07-15 18:06:45 +01:00
Fabien O'Carroll
fe668113b1 Published new versions
- @tryghost/members-api@1.20.1
2021-07-15 18:03:59 +01:00
Fabien O'Carroll
02766afedd Moved MembersAPI.js into lib
no-issue

The previous published version was broken as we only include index.js
and the lib directory in the npm package
2021-07-15 18:01:53 +01:00
Fabien O'Carroll
d59051c104 Published new versions
- @tryghost/magic-link@1.0.6
 - @tryghost/members-api@1.20.0
 - @tryghost/members-csv@1.1.2
 - @tryghost/members-ssr@1.0.6
2021-07-15 16:34:02 +01:00
Fabien O'Carroll
d427e72b1c Fixed created_at dates for member event objects
refs https://github.com/TryGhost/Team/issues/542

Importing members with a created_at date will incorrectly create events
for the member for the date of the import. This updates our event
handling to use either the passed created_at date, or in the case of
subscriptions the start_date of the subscription. We're using start_date
for subscriptions rather than created, as this is more accurate because
start_date works correctly for backdated subscriptions in Stripe.
2021-07-15 15:20:16 +01:00
Rishabh
aad662267c Added migration to remove invalid subscriptions
closes https://github.com/TryGhost/Team/issues/660

All subscriptions in Ghost are expected to have a corresponding price details in `stripe_price` table, which is used to determine the Stripe price a subscription is on. In some edge cases, specially before we started deleted old Stripe data during Stripe disconnect, it's possible that a subscription exists in DB without having a corresponding Stripe price in the DB. These subscriptions are not active for the connected Stripe account, and are save to remove. Going forward, all existing subscriptions with connected account will be removed when disconnecting stripe so we shouldn't have invalid subscriptions in DB in future.

The goal of this migration is to clean all such subscriptions from the DB to avoid any issues around missing price with invalid subscriptions.
2021-07-14 20:12:39 +05:30
Rishabh
aa19008651 Fixed incorrect import path
no refs
2021-07-14 20:01:29 +05:30
Fabien O'Carroll
9102b7527f Moved MagicLink out of index.js
refs https://github.com/TryGhost/Team/issues/879
2021-07-14 14:17:38 +01:00
Fabien O'Carroll
3e1084905e Removed usage of raw Error class
refs https://github.com/TryGhost/Team/issues/879
2021-07-14 14:17:38 +01:00
Fabien O'Carroll
d51fdc3f4a Moved code out of index.js in directories
refs https://github.com/TryGhost/Team/issues/879
2021-07-14 14:17:38 +01:00
Fabien O'Carroll
13943e9746 Moved MembersAPI out of index.js
refs https://github.com/TryGhost/Team/issues/879
2021-07-14 14:17:38 +01:00
Fabien O'Carroll
004c7d2739 Moved MembersSSR out of index.js
refs https://github.com/TryGhost/Team/issues/879
2021-07-14 14:17:38 +01:00
Renovate Bot
223ee56647 Update Test & linting packages 2021-07-14 14:12:12 +01:00
Renovate Bot
4013642bb1 Update dependency mocha to v8.4.0 2021-07-14 11:35:50 +00:00
Fabien O'Carroll
4f660554eb Fixed linting issues for members-ssr example
refs https://github.com/TryGhost/Team/issues/879
2021-07-14 12:05:10 +01:00
Fabien O'Carroll
e39016423e Removed calls to console.log
refs https://github.com/TryGhost/Team/issues/879
2021-07-14 12:05:07 +01:00
Fabien O'Carroll
6083e4825f Removed trailing commas from .eslintrc.js
refs https://github.com/TryGhost/Team/issues/879
2021-07-14 12:04:46 +01:00
Fabien O'Carroll
8af799bdc9 Published new versions
- @tryghost/members-api@1.19.0
2021-07-06 13:47:38 +01:00
Fabien O'Carroll
dd8376dd90 Restricted Stripe Checkout to members without products
refs https://github.com/TryGhost/Team/issues/858

Replacing the check for subscriptions with products ensures that Stripe
Checkout is not able to be opened by comped members.
2021-07-06 12:59:32 +01:00
Fabien O'Carroll
9841a33c83 Published new versions
- @tryghost/members-api@1.18.1
2021-07-06 11:54:12 +01:00
Fabien O'Carroll
12a3ae77cf Fixed creating members without products
refs https://github.com/TryGhost/Team/issues/790

We were missing a check for the existence of memberData.products before
attempting to read the length property from it, which can result in an
Uncaught TypeError
2021-07-06 11:52:08 +01:00
Fabien O'Carroll
7545e67f2c Published new versions
- @tryghost/magic-link@1.0.5
 - @tryghost/members-api@1.18.0
 - @tryghost/members-csv@1.1.1
 - @tryghost/members-ssr@1.0.5
2021-07-06 11:18:01 +01:00
Fabien O'Carroll
631e78631f Updated linkSubscription to handle comped status
refs https://github.com/TryGhost/Team/issues/790

When linking a subscription to a member we must also update their
status. We could be in one of many states, so we start with the initial
values of either 'free' or 'comped' based on whether the member has any
products. We then make sure to updated the status to 'paid' if we find
any active subscriptions associated with the member, otherwise we leave
it as the initial value.
2021-07-06 11:14:49 +01:00
Fabien O'Carroll
8d8d886705 Supported comped status for create/update methods
refs https://github.com/TryGhost/Team/issues/790

Both creating and updating members only ever need to explicitly set
either the 'comped' or 'free' status as these methods do not deal with
Stripe. When updating a member if the products are not changing, we do
not attempt to change the status either.
2021-07-06 11:14:49 +01:00
Renovate Bot
7f71e28392 Update dependency nock to v13.1.0 2021-06-29 21:43:45 +01:00
Daniel Lockyer
21ec26ea08 Removed used of ghost-ignition dependency
no issue

- we're killing off `ghost-ignition` in favor of explicit packages
  containing its individual components
- this commit switches the Members repo to using the
  `@tryghost/ignition-errors` and `@tryghost/debug` dependencies,
  updates the code with relevant changes and removes the `ghost-ignition`
  dependency
2021-06-29 21:43:05 +01:00
Daniel Lockyer
88fd6c10f5 Added missing dependencies
no issue

- these dependencies are used within the `members-csv` repo but were
  never included in the `package.json`
- this commit adds in the missing dependencies
2021-06-29 21:40:07 +01:00
Fabien O'Carroll
5ea642c8c1 Published new versions
- @tryghost/members-api@1.17.0
2021-06-29 15:14:10 +01:00
Fabien O'Carroll
1fbbdcfc2e Included benefits with products when writing
refs https://github.com/TryGhost/Team/issues/806

This allows API consumers to not need to pass an `includes` for benefits
when creating or updating products.
2021-06-29 15:06:35 +01:00
Fabien O'Carroll
4ea7cdc8fe Published new versions
- @tryghost/members-api@1.16.0
2021-06-24 17:13:56 +01:00
Fabien O'Carroll
57233f7295 Updated ProductRepository to support benefits
refs https://github.com/TryGhost/Team/issues/806

We need to explicitly pass data through to the model layer so that the
benefits relation can be handled.
2021-06-24 16:53:56 +01:00
Fabien O'Carroll
18c2cb9c9f Published new versions
- @tryghost/members-csv@1.1.0
2021-06-23 10:16:22 +01:00
Fabien O'Carroll
4d8c2ebb1f Supported products column for parse & unparse
refs https://github.com/TryGhost/Team/issues/765

Support for multiple products means we can no longer map a members state
to a csv row using just the `complimentary_plan` option. Instead we must
include the product(s) that a member has. This ensures that we can read
and write this data from/to csv files.
2021-06-23 10:14:30 +01:00
Fabien O'Carroll
45c3de71d6 Published new versions
- @tryghost/magic-link@1.0.4
 - @tryghost/members-api@1.15.0
 - @tryghost/members-ssr@1.0.4
2021-06-16 18:25:48 +01:00
Fabien O'Carroll
83d25f71f4 Restricted Members to only one Product
refs https://github.com/TryGhost/Team/issues/748

This ensures that you cannot add more than one product to a Member.

However it does allow a Member which already exists with more than one
Product to continue using the API. This is to account for edgecases such
as a Member going through the Stripe flow twice and ending up with
multiple subscriptions for multiple products
2021-06-16 15:50:42 +01:00
Fabien O'Carroll
54c3340503 Used tpl & errors packages in MemberRepository
no-issue

Cleaning up this file to be adhere with our new standard for errors.
2021-06-16 15:50:42 +01:00
Fabien O'Carroll
5ad0c624e3 Required no active subscriptions when modifying products
refs https://github.com/TryGhost/Team/issues/748

This ensures that a member cannot be attached to a product directly if
they have active subscriptions.
2021-06-16 15:50:42 +01:00
Fabien O'Carroll
9079a9b9e0 Fixed products being removed when canceling subscriptions
refs https://github.com/TryGhost/Team/issues/748

Previously when a change happened to a subscription the member's
products would be reset purely based on the subscriptions. Since we now
support setting products outside of subscriptions, we must make sure
than a change to a subscription will only affect the product for which
the subscription was for
2021-06-16 15:50:42 +01:00
Fabien O'Carroll
5a74c614c5 Updated event storage to use sharedOptions
no-issue

This makes sure that DB operations can be performed in the same
transaction
2021-06-16 15:50:42 +01:00
Fabien O'Carroll
d064a1ea82 Checked existing subscriptions when updating products
refs https://github.com/TryGhost/Team/issues/748

This ensures that products are not removed from members who have an
active subscription for them.
2021-06-16 15:50:42 +01:00
Fabien O'Carroll
11067c4b08 Updated create & update to accept products
refs https://github.com/TryGhost/Team/issues/748

This allows us to start modifying products directly in order to give
complimentary access without using Stripe
2021-06-16 15:50:42 +01:00
Renovate Bot
f6e12a3da7 Update dependency ghost-ignition to v4.6.3 2021-06-15 18:28:07 +00:00
Fabien O'Carroll
30f835b511 Published new versions
- @tryghost/members-api@1.14.0
2021-06-10 17:15:55 +01:00
Fabien O'Carroll
a4dcb66080 Updated cancelSubscription to take member id
refs https://github.com/TryGhost/Team/issues/775

Exposing this to the Admin API means that we want to be able to cancel
by id, not just email. The same pattern from editSubscription has been
used.
2021-06-10 17:10:58 +01:00
Rishabh
b2fccb2e34 Published new versions
- @tryghost/members-api@1.13.1
2021-06-04 17:18:06 +05:30
Rishabh
d37a470f20 Removed redundant portal plans setting migration
refs 7d8e18c802

Since we have now gone back to using `monthly` / `yearly` named values in portal plan settings instead of price ids, the old portal plan migration which was converting named values to ids is now redundant. Moreoever, the old migration is incorrectly resetting the `portal_plans` setting to `[free]` by removing the paid plans as its not found in `stripePlans` setting anymore.
2021-06-04 17:15:05 +05:30
Rishabh
daeacfbd89 Removed setting existing legacy prices to inactive
refs fd40e04105

The current implementation of setting legacy prices as inactive has a bug where it also sets the active price to inactive if only one of monthly/yearly price is edited while the other is not changed. This is a temporary reversal till we can narrow down the issue and fix to correctly set legacy plans to inactive.
2021-06-04 12:20:22 +05:30
Rishabh
7d8e18c802 Added migration to revert portal_plans setting to named values
closes https://github.com/TryGhost/Team/issues/753

Currently, the portal_plans setting is storing price ids for active monthly/yearly prices for the default product, which was done to allow multiple prices in Portal. Since we only want to limit the prices for a Product to monthly/yearly, we are reverting the earlier migration and only store the available prices as monthly / yearly in portal setting instead of ids. Its also in sync with the approach in theme/API where we use named prices for monthly/yearly instead of price id list.
2021-06-04 12:14:57 +05:30
Fabien O'Carroll
bf4467753a Published new versions
- @tryghost/members-api@1.13.0
2021-06-03 14:46:02 +01:00
Fabien O'Carroll
fd40e04105 Handled monthly and yearly prices in product repo
refs https://github.com/TryGhost/Team/issues/712

This allows prices to be created and assigned to a product as the
default monthly or yearly price.
2021-06-03 14:45:36 +01:00
Fabien O'Carroll
601d40320e Published new versions
- @tryghost/members-api@1.12.0
 - @tryghost/members-csv@1.0.1
2021-06-02 09:57:04 +01:00
Fabien O'Carroll
f660405937 Populated {monthly,yearly}_price_id from settings
refs https://github.com/TryGhost/Team/issues/711

As this migration relies on the settings being populated, it cannot be a
standard migration in Ghost core, as the settings are populated by these
code migrations.
2021-06-02 09:04:54 +01:00
Renovate Bot
0c66563df7 Update dependency papaparse to v5.3.1 2021-05-31 01:33:59 +00:00
Fabien O'Carroll
c84d7c7c10 Published new versions
- @tryghost/members-api@1.11.1
2021-05-24 17:42:33 +01:00
Fabien O'Carroll
a126764dcd Updated error message for Stripe not connected
refs https://github.com/TryGhost/Team/issues/704

This improves the error messaging by explaining exactly what the problem
is and including a link to our documentation
2021-05-24 17:41:49 +01:00
Fabien O'Carroll
bac55fcfb7 Published new versions
- @tryghost/magic-link@1.0.3
 - @tryghost/members-api@1.11.0
 - @tryghost/members-ssr@1.0.3
2021-05-24 10:34:04 +01:00
Fabien O'Carroll
6fb7b46f39 Uninstalled jsdom
no-issue

This package is no longer used
2021-05-24 10:32:26 +01:00
Renovate Bot
bf89907d33 Update dependency @types/cookies to v0.7.6 2021-05-24 10:26:15 +01:00
Renovate Bot
5497aadb62 Update dependency keypair to v1.0.3 2021-05-24 10:25:55 +01:00
Renovate Bot
dd630a74fc Update dependency @types/nodemailer to v6.4.1 2021-05-24 10:25:34 +01:00
Renovate Bot
4d98dddc89 Update dependency @types/jsonwebtoken to v8.5.1 2021-05-24 10:24:13 +01:00
Renovate Bot
bc99b1810d Update dependency nock to v13 2021-05-24 10:23:22 +01:00
Renovate Bot
26e3834d59 Pin dependency @types/node-jose to 1.1.6 2021-05-24 10:22:07 +01:00
Renovate Bot
324c008d3a Update dependency @types/node to v14 2021-05-24 10:21:52 +01:00
Fabien O'Carroll
40012160ed Errored when Stripe connection is missing and used
refs https://github.com/TryGhost/Team/issues/704

Currently when attempting to create stripe_prices without a Stripe
connection, it will fail silently. This is an issue when initially
configuring Members as the Stripe connection can take some time to be
established. By erroring we allow the client to be notifed that the
connection does not yet exist, so that it can be retried later.
2021-05-24 10:19:55 +01:00
Fabien O'Carroll
7ba838cf4c Published new versions
- @tryghost/members-api@1.10.0
2021-05-20 17:38:21 +01:00
Fabien O'Carroll
98fe7785d6 Handled week & day interval for calculating MRR
refs https://github.com/TryGhost/Team/issues/635

It's possible that we have subscriptions in the system which have been
created externally, and so using an interval of week or day. This change
ensures that we handle the mrr_delta for these subscriptions correctly.
2021-05-20 16:56:14 +01:00
Fabien O'Carroll
f3ecb44e08 Updated migration to use getPrice method
refs https://github.com/TryGhost/Team/issues/657

Since we have removed the getPlan method we need to update the migration
which is the last piece of code which used it. Prices are backwards
compatible with Plans - so this will continue to work as expected.
2021-05-20 15:35:58 +01:00
Fabien O'Carroll
1b628a1637 Refactored Token Service to use async/await
refs https://github.com/TryGhost/Team/issues/657

- Removes the use of "plans" from token service - method wasn't used
- Updates to use async/await so the code is clearer
- Install types for the node-jose module
- Install types for the jsonwebtoken module
2021-05-20 15:18:46 +01:00
Fabien O'Carroll
10b40dfd16 Added comment for deprecation of plan_from_trial
refs https://github.com/TryGhost/Team/issues/657

We must still use the "plan" approach of creating Checkout Sessions so
that we are able to maintain our current functionality of setting the
free trial from the one associated with the Plan/Price used for the
Checkout Session.

In future we would handle free trials internally in Ghost and apply them
on a subscription-by-subscription basis.
2021-05-20 15:15:33 +01:00
Fabien O'Carroll
16b984e2f6 Fixed types for StripeAPIService
no-issue
2021-05-20 15:15:24 +01:00
Fabien O'Carroll
162722b9d3 Removed unused plan related code
refs https://github.com/TryGhost/Team/issues/657

This code is no longer used since we got rid of the StripePlans service
2021-05-20 15:14:24 +01:00
Fabien O'Carroll
98e6ba8028 Published new versions
- @tryghost/members-api@1.9.0
2021-05-20 12:13:13 +01:00
Fabien O'Carroll
26e2cb98e9 Removed environment checks from webhook service
refs https://github.com/TryGhost/Team/issues/598
refs https://github.com/TryGhost/Ghost/commit/5cdf910e

Since we have included these checks in the Ghost codebase we do not need
to run them here.
2021-05-20 12:11:43 +01:00
Fabien O'Carroll
0d3014a87a Published new versions
- @tryghost/members-api@1.8.0
2021-05-19 15:28:17 +01:00
Fabien O'Carroll
ee32528006 Populated members_{monthly,yearly}_price_id settings
refs https://github.com/TryGhost/Team/issues/698

As this migration relies on the `stripe_prices` table being populated,
it can not be in a standard versioned migration in Ghost core.
2021-05-19 15:16:15 +01:00
Fabien O'Carroll
81d96bbdd3 Published new versions
- @tryghost/members-api@1.7.0
2021-05-17 14:52:46 +01:00
Fabien O'Carroll
25d3d42427 Removed use of 'comped' status for Members
refs https://github.com/TryGhost/Team/issues/693

With the new system of Custom Products, the concept of Complimentary is
not longer a thing, and will instead be handled by explicitly creating
prices with no amount. This means that the 'comped' status for members
will be replaced with 'paid'.
2021-05-17 13:06:41 +01:00
Fabien O'Carroll
3beb1b21e7 Published new versions
- @tryghost/members-api@1.6.1
2021-05-11 12:06:56 +01:00
Fabien O'Carroll
d5269d8a9a Fixed finding newly created zero-amount price
no-issue

The condition in the find statement was incorrecly referring to the
subscription rather than the price for the subscription.
2021-05-11 10:58:41 +01:00
Fabien O'Carroll
12d4e42bb1 Published new versions
- @tryghost/members-api@1.6.0
2021-05-10 20:18:43 +01:00
Fabien O'Carroll
d32e44c73b Mapped Stripe Product name to Product name
closes https://github.com/TryGhost/Team/issues/682

This ensures that the Stripe Product name is updated during the
migrations of an existing site and any future updates to the Product
name.
2021-05-10 19:21:41 +01:00
Fabien O'Carroll
15b535fd45 Removed unused stripe-plans service
no-issue

This module is no longer used!
2021-05-10 19:21:41 +01:00
Fabien O'Carroll
45d338730c Updated webhook service to work with multiple products
no-issue

Since we do not necessarily have a single stripe product anymore, we
should be checking if an invoice webhook is for a stripe product which
we know about. We use the Products repository to search our database for
one.
2021-05-10 19:21:41 +01:00
Fabien O'Carroll
a3f7f3d1a0 Updated setComplimentary to work with new system
closes https://github.com/TryGhost/Team/issues/650

Despite the fact we're getting rid of the concept of Complimentary, we
must maintain backwards compatibility for the `comped` flag in the Admin
API & the importer. This flag is handled via the `setComplimentary`
method, which has been updated to work with the new system.
2021-05-10 19:21:32 +01:00
Kevin Ansfield
cdd52917fd Published new versions
- @tryghost/members-api@1.5.0
2021-05-10 12:07:00 +01:00
Kevin Ansfield
2f7664e1a8 Added labels and products to fetched member identity data (#271)
refs https://github.com/TryGhost/Team/issues/581
refs https://github.com/TryGhost/Team/issues/582

Content gating in Ghost is being expanded from basic public/members/free/paid to allowing full NQL queries. To facilitate quick matching of a member to the visibility query we need details of the associated labels and products alongside the basic member data.
2021-05-10 11:46:34 +01:00
Kevin Ansfield
ca473fc273 🐛 Fixed potential member data loss when assigning geolocation data
no issue

- `setMemberGeolocationFromIp()` was passing a raw model instance through to `users.update()` rather than a data object causing the `model.edit()` call to overwrite existing data such as labels because `modelInstance.labels` is a function rather than an array
- removed unnecessary `withRelated: ['labels']` as it's not necessary for the update, member data is fetched again with all necessary includes by `getMemberIdentityData()` before returning
2021-05-10 11:24:10 +01:00
Renovate Bot
40aabc7539 Update dependency node-jose to v2 2021-05-07 18:08:16 +01:00
Fabien O'Carroll
f2123d07db Added support for un/archiving Prices
https://github.com/TryGhost/Team/issues/665

We update both Stripe and our database based on the `active` flag for
existing stripe prices.
2021-05-07 17:01:00 +01:00
Rishabh
1dd2c4f656 Added prices object to logged in member's identity data
refs https://github.com/TryGhost/Team/issues/637

As we move away from `plan` data to `prices`, this change updates member identity data to include `prices` object in subscriptions object to get the price data for subscription instead of relying on `plan` data.
2021-05-06 15:27:01 +05:30
Rishabh
aa640ada5e Added migration for stripe plans to custom prices
refs https://github.com/TryGhost/Team/issues/637

- Adds one-off migration that reads from current `stripe_plans data` for a price, and ensures that the corresponding price is present in `stripe_prices` table at start.
- Currently, the portal_plans setting is used to determine the prices available to Portal for showing on Signup or Subscription change screen. The values allowed in portal_plans currently only allow [free, monthly, yearly] , which needs to be updated now to store price ids of available prices instead. Uses above migration to populate `portal_plans` with ids instead of names.
2021-05-04 21:52:51 +05:30
Rishabh
460dd09f8b Added description to product repository
refs https://github.com/TryGhost/Team/issues/586
refs https://github.com/TryGhost/Ghost/commit/b4d9ee0b

The `products` and `stripe_prices` were missing a description
column which will be used by Portal to display information about the
products and prices
2021-05-04 21:52:51 +05:30
Rishabh
3a27d1bd0c Updated APIs to use price ids
refs https://github.com/TryGhost/Team/issues/637

All the APIs that currently work with price names needs to be updated to work with price ids instead to work with custom prices/products. This change updates APIs to work with Price IDs in `checkout` , `updateSubscription` and other APIs/methods.
2021-05-04 21:52:51 +05:30
Fabien O'Carroll
fabff2e7e1 Published new versions
- @tryghost/members-api@1.4.0
2021-04-26 17:18:24 +01:00
Fabien O'Carroll
4e98c62b71 Fixed update method for Products repository
no-issue

When updating a Product we can pass existing Stripe Prices, these will
either be adding to the database, or updated if they already exist. When
updating them we were attemping to use the `id` passed in the update,
which is not necessarily included. Instead we should use the `id` of the
StripePrice which we have already retrieved from the database.
2021-04-26 17:15:17 +01:00
Fabien O'Carroll
20e5dcc91d Added createSubscription method to member repo
refs https://github.com/TryGhost/Team/issues/616

This is a generic method for adding a subscription to a member for a
particular price/product pair. This will be used in the Admin for e.g.
giving complimentary subscriptions.
2021-04-23 17:34:04 +01:00
Rishabh Garg
a08690363e Updated product repo to allow editing price names (#265)
refs https://github.com/TryGhost/Team/issues/616

For existing prices linked to a Product, we only allow site owners/admins to edit their nickname and nothing else. This change handles the update in Ghost, but needs extension to update the name in Stripe as well.
2021-04-23 21:46:07 +05:30
Rish
4c7860483e Published new versions
- @tryghost/members-api@1.3.2
2021-04-22 21:53:08 +05:30
Rishabh Garg
42ade8fd12 Updated customer fetch from Stripe to include subscriptions (#264)
closes https://github.com/TryGhost/Team/issues/628
refs 9010a62d54

Following up on last commit, this moves up the expansion of Stripe customer fetch to always include `subscriptions` by default in api service so we don't accidentally miss it.
2021-04-22 21:51:01 +05:30
Rish
9010a62d54 🐛 Fixed members importer failing to link paid subscriptions
no refs

The latest version of Stripe doesn't return the `subscriptions` object on `Customer` resource by default and needs an extra param to do so. As we recently updated Members to use the latest Stripe version, the importer tries to fetch all subscriptions of a customer to map in Ghost but was failing due to missing `subscriptions` data. Fix updates the Stripe API to include `subscriptions` by default in response.
2021-04-22 21:22:23 +05:30
Rish
881077ad9d Published new versions
- @tryghost/members-api@1.3.1
2021-04-22 11:50:32 +05:30
Rish
c612b4d194 Ignored missing plans on Stripe for update
refs https://github.com/TryGhost/Team/issues/591

It's possible to have sites which still have subscriptions in their DB from old Stripe accounts, most likely added when we allowed Stripe Direct, as those subscriptions were not cleaned up. While populating plans and products for existing subscriptions, we want to ignore these old subscriptions which are not part of current Stripe account.
2021-04-22 11:49:08 +05:30
Rish
25a1f7d0b4 Published new versions
- @tryghost/magic-link@1.0.2
 - @tryghost/members-api@1.3.0
 - @tryghost/members-ssr@1.0.2
2021-04-20 17:23:04 +05:30
Rishabh Garg
bee619c123 Updated link subscription to handle missing stripe data (#262)
refs https://github.com/TryGhost/Team/issues/619

On linking a stripe subscription to a member, this change -

- Adds missing stripe price or stripe product from subscription to DB
  - Missing Stripe price is attached to the first Ghost Product if no matching Product exists
- Updates usage from plan to price in the `linkSubscription` method
- Updates products associated with a member based on active subscriptions
2021-04-20 17:21:16 +05:30
Fabien 'egg' O'Carroll
dc0e5b0ec8 Wired up ProductRepository to members-api
refs https://github.com/TryGhost/Team/issues/616

Working with ProductRepository as a separate package was more trouble
than it was worth, so it's been moved into members-api. We expose the
product repository so that Ghost Admin API can access it.
2021-04-19 15:09:28 +01:00
Renovate Bot
bd3b3738e5 Update dependency ghost-ignition to v4.6.2 2021-04-19 05:22:28 +00:00
Rishabh Garg
836b7f235e Populate stripe prices and products for existing customers (#258)
refs https://github.com/TryGhost/Team/issues/586

On Ghost Boot, as part of configuring Stripe, this populates stripe products and prices for existing stripe customers in the newly created `stripe_prices` and `stripe_products` table, which allows us to map existing customers to default Ghost product and on current prices. The population script on boot is only run if we find -

- A Ghost Product
- No rows in `stripe_products`
- No rows in `stripe_prices`
- One or more rows in `members_stripe_customers_subscriptions`
2021-04-12 20:38:01 +05:30
Fabien O'Carroll
3f6498c12f Published new versions
- @tryghost/members-api@1.2.0
 - @tryghost/product-repository@0.1.1
2021-04-12 15:31:32 +01:00
Fabien 'egg' O'Carroll
6602928099 Added initial ProductRepository implementation (#259)
refs https://github.com/TryGhost/Team/issues/616

WIP but needs to be released so we can start using it as a dependency
2021-04-12 15:30:17 +01:00