ghost 5.115.1 → 5.116.1
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/components/{tryghost-api-framework-5.115.1.tgz → tryghost-api-framework-5.116.1.tgz} +0 -0
- package/components/tryghost-constants-5.116.1.tgz +0 -0
- package/components/tryghost-custom-fonts-5.116.1.tgz +0 -0
- package/components/{tryghost-custom-theme-settings-service-5.115.1.tgz → tryghost-custom-theme-settings-service-5.116.1.tgz} +0 -0
- package/components/{tryghost-domain-events-5.115.1.tgz → tryghost-domain-events-5.116.1.tgz} +0 -0
- package/components/{tryghost-donations-5.115.1.tgz → tryghost-donations-5.116.1.tgz} +0 -0
- package/components/tryghost-email-addresses-5.116.1.tgz +0 -0
- package/components/tryghost-email-service-5.116.1.tgz +0 -0
- package/components/tryghost-email-suppression-list-5.116.1.tgz +0 -0
- package/components/tryghost-html-to-plaintext-5.116.1.tgz +0 -0
- package/components/tryghost-i18n-5.116.1.tgz +0 -0
- package/components/tryghost-job-manager-5.116.1.tgz +0 -0
- package/components/tryghost-link-replacer-5.116.1.tgz +0 -0
- package/components/tryghost-magic-link-5.116.1.tgz +0 -0
- package/components/{tryghost-member-attribution-5.115.1.tgz → tryghost-member-attribution-5.116.1.tgz} +0 -0
- package/components/tryghost-member-events-5.116.1.tgz +0 -0
- package/components/tryghost-members-api-5.116.1.tgz +0 -0
- package/components/tryghost-members-csv-5.116.1.tgz +0 -0
- package/components/{tryghost-members-offers-5.115.1.tgz → tryghost-members-offers-5.116.1.tgz} +0 -0
- package/components/{tryghost-milestones-5.115.1.tgz → tryghost-milestones-5.116.1.tgz} +0 -0
- package/components/{tryghost-mw-error-handler-5.115.1.tgz → tryghost-mw-error-handler-5.116.1.tgz} +0 -0
- package/components/tryghost-mw-vhost-5.116.1.tgz +0 -0
- package/components/{tryghost-post-events-5.115.1.tgz → tryghost-post-events-5.116.1.tgz} +0 -0
- package/components/{tryghost-post-revisions-5.115.1.tgz → tryghost-post-revisions-5.116.1.tgz} +0 -0
- package/components/tryghost-posts-service-5.116.1.tgz +0 -0
- package/components/{tryghost-prometheus-metrics-5.115.1.tgz → tryghost-prometheus-metrics-5.116.1.tgz} +0 -0
- package/components/tryghost-security-5.116.1.tgz +0 -0
- package/components/{tryghost-tiers-5.115.1.tgz → tryghost-tiers-5.116.1.tgz} +0 -0
- package/components/tryghost-webmentions-5.116.1.tgz +0 -0
- package/content/themes/casper/LICENSE +1 -1
- package/content/themes/casper/README.md +1 -1
- package/content/themes/source/LICENSE +1 -1
- package/content/themes/source/README.md +1 -1
- package/content/themes/source/assets/built/screen.css +1 -1
- package/content/themes/source/assets/built/screen.css.map +1 -1
- package/content/themes/source/assets/css/screen.css +6 -11
- package/content/themes/source/partials/feature-image.hbs +2 -2
- package/core/boot.js +0 -42
- package/core/built/admin/assets/admin-x-activitypub/admin-x-activitypub.js +24764 -24129
- package/core/built/admin/assets/admin-x-demo/admin-x-demo.js +1 -1
- package/core/built/admin/assets/admin-x-demo/{index-15df2af5.mjs → index-a9601514.mjs} +3 -3
- package/core/built/admin/assets/admin-x-demo/{modals-8ca61d78.mjs → modals-c1789d04.mjs} +2 -2
- package/core/built/admin/assets/admin-x-settings/{CodeEditorView-d2e6872f.mjs → CodeEditorView-e9c9deb8.mjs} +2 -2
- package/core/built/admin/assets/admin-x-settings/admin-x-settings.js +2 -2
- package/core/built/admin/assets/admin-x-settings/{index-8e8821e5.mjs → index-84580c3a.mjs} +2 -2
- package/core/built/admin/assets/admin-x-settings/{index-f5cb3db3.mjs → index-f744cab7.mjs} +49 -35
- package/core/built/admin/assets/admin-x-settings/{modals-e8ae4d46.mjs → modals-d9ca60c5.mjs} +1198 -1192
- package/core/built/admin/assets/chunk.524.cb72a86e19c9ffd6172e.js +35 -0
- package/core/built/admin/assets/chunk.582.4f4d38ffe79fbdbd26f7.js +37 -0
- package/core/built/admin/assets/{chunk.874.461cb3cf5b6b36915f8c.js → chunk.713.e9027c0cc3c56110f5da.js} +125 -98
- package/core/built/admin/assets/{ghost-df7b9558260aa27d18b195ee895b487d.js → ghost-03b64c086f3c60cabc85fe7a7e2b640a.js} +144 -145
- package/core/built/admin/assets/ghost-ba58e9822f7384461e926c7e23f04a75.css +1 -0
- package/core/built/admin/assets/ghost-dark-f1f29683b14ffa11615b3bba8b6ab92c.css +1 -0
- package/core/built/admin/assets/koenig-lexical/index.css +1 -1
- package/core/built/admin/assets/koenig-lexical/koenig-lexical.js +20563 -20891
- package/core/built/admin/assets/koenig-lexical/koenig-lexical.umd.js +139 -139
- package/core/built/admin/assets/posts/posts.js +5732 -5667
- package/core/built/admin/assets/stats/stats.js +71082 -7533
- package/core/built/admin/assets/{vendor-68a4aa424a179a90f5bbc2b750def576.js → vendor-72026232b36d97babc6320917c16c321.js} +36 -34
- package/core/built/admin/index.html +6 -6
- package/core/cli/generate-data.js +1 -1
- package/core/frontend/helpers/ghost_head.js +6 -1
- package/core/frontend/public/ghost-stats.js +55 -2
- package/core/frontend/services/assets-minification/AdminAuthAssets.js +2 -1
- package/core/frontend/services/assets-minification/CardAssets.js +1 -1
- package/core/frontend/services/assets-minification/CommentCountsAssets.js +1 -1
- package/core/frontend/services/assets-minification/MemberAttributionAssets.js +1 -1
- package/core/frontend/services/assets-minification/Minifier.js +191 -0
- package/core/frontend/services/routing/controllers/previews.js +2 -1
- package/core/server/adapters/cache/Redis.js +1 -1
- package/core/server/adapters/lib/redis/AdapterCacheRedis.js +287 -0
- package/core/server/adapters/lib/redis/redis-store-factory.js +22 -0
- package/core/server/api/endpoints/posts.js +9 -3
- package/core/server/api/endpoints/previews.js +35 -1
- package/core/server/api/endpoints/utils/serializers/output/utils/post-gating.js +6 -9
- package/core/server/api/endpoints/utils/validators/input/settings.js +1 -1
- package/core/server/data/db/connection.js +2 -0
- package/core/server/data/db/index.js +1 -0
- package/core/server/data/importer/handlers/ImporterContentFileHandler.js +90 -0
- package/core/server/data/importer/import-manager.js +1 -1
- package/core/server/data/seeders/DataGenerator.js +288 -0
- package/core/server/data/seeders/importers/BenefitsImporter.js +28 -0
- package/core/server/data/seeders/importers/CommentsImporter.js +73 -0
- package/core/server/data/seeders/importers/EmailBatchesImporter.js +38 -0
- package/core/server/data/seeders/importers/EmailRecipientFailuresImporter.js +67 -0
- package/core/server/data/seeders/importers/EmailRecipientsImporter.js +212 -0
- package/core/server/data/seeders/importers/EmailsImporter.js +99 -0
- package/core/server/data/seeders/importers/LabelsImporter.js +41 -0
- package/core/server/data/seeders/importers/MembersClickEventsImporter.js +69 -0
- package/core/server/data/seeders/importers/MembersCreatedEventsImporter.js +103 -0
- package/core/server/data/seeders/importers/MembersFeedbackImporter.js +45 -0
- package/core/server/data/seeders/importers/MembersImporter.js +111 -0
- package/core/server/data/seeders/importers/MembersLabelsImporter.js +39 -0
- package/core/server/data/seeders/importers/MembersLoginEventsImporter.js +69 -0
- package/core/server/data/seeders/importers/MembersNewslettersImporter.js +38 -0
- package/core/server/data/seeders/importers/MembersPaidSubscriptionEventsImporter.js +99 -0
- package/core/server/data/seeders/importers/MembersProductsImporter.js +42 -0
- package/core/server/data/seeders/importers/MembersStatusEventsImporter.js +58 -0
- package/core/server/data/seeders/importers/MembersStripeCustomersImporter.js +60 -0
- package/core/server/data/seeders/importers/MembersStripeCustomersSubscriptionsImporter.js +259 -0
- package/core/server/data/seeders/importers/MembersSubscribeEventsImporter.js +69 -0
- package/core/server/data/seeders/importers/MembersSubscriptionCreatedEventsImporter.js +95 -0
- package/core/server/data/seeders/importers/NewslettersImporter.js +40 -0
- package/core/server/data/seeders/importers/OffersImporter.js +70 -0
- package/core/server/data/seeders/importers/PostsAuthorsImporter.js +32 -0
- package/core/server/data/seeders/importers/PostsImporter.js +102 -0
- package/core/server/data/seeders/importers/PostsProductsImporter.js +35 -0
- package/core/server/data/seeders/importers/PostsTagsImporter.js +46 -0
- package/core/server/data/seeders/importers/ProductsBenefitsImporter.js +54 -0
- package/core/server/data/seeders/importers/ProductsImporter.js +90 -0
- package/core/server/data/seeders/importers/RecommendationClickEventsImporter.js +32 -0
- package/core/server/data/seeders/importers/RecommendationSubscribeEventsImporter.js +32 -0
- package/core/server/data/seeders/importers/RecommendationsImporter.js +34 -0
- package/core/server/data/seeders/importers/RedirectsImporter.js +49 -0
- package/core/server/data/seeders/importers/RolesUsersImporter.js +42 -0
- package/core/server/data/seeders/importers/StripePricesImporter.js +69 -0
- package/core/server/data/seeders/importers/StripeProductsImporter.js +34 -0
- package/core/server/data/seeders/importers/TableImporter.js +187 -0
- package/core/server/data/seeders/importers/TagsImporter.js +41 -0
- package/core/server/data/seeders/importers/UsersImporter.js +31 -0
- package/core/server/data/seeders/importers/WebMentionsImporter.js +42 -0
- package/core/server/data/seeders/importers/index.js +41 -0
- package/core/server/data/seeders/utils/JsonImporter.js +39 -0
- package/core/server/data/seeders/utils/blog-info.js +3 -0
- package/core/server/data/seeders/utils/database-date.js +7 -0
- package/core/server/data/seeders/utils/event-generator.js +48 -0
- package/core/server/data/seeders/utils/random.js +13 -0
- package/core/server/data/seeders/utils/topological-sort.js +33 -0
- package/core/server/services/adapter-manager/AdapterManager.js +161 -0
- package/core/server/services/adapter-manager/index.js +1 -1
- package/core/server/services/announcement-bar-service/AnnouncementBarSettings.js +54 -0
- package/core/server/services/announcement-bar-service/AnnouncementVisibilityValues.js +11 -0
- package/core/server/services/announcement-bar-service/index.js +1 -1
- package/core/server/services/api-version-compatibility/APIVersionCompatibilityService.js +1 -1
- package/core/server/services/auth/session/session-service.js +15 -5
- package/core/server/services/custom-redirects/index.js +1 -1
- package/core/server/services/email-analytics/EmailAnalyticsProviderMailgun.js +1 -1
- package/core/server/services/email-service/EmailServiceWrapper.js +4 -4
- package/core/server/services/email-suppression-list/MailgunEmailSuppressionList.js +1 -1
- package/core/server/services/email-suppression-list/service.js +1 -1
- package/core/server/services/lib/DynamicRedirectManager.js +156 -0
- package/core/server/services/lib/EmailContentGenerator.js +54 -0
- package/core/server/services/lib/InMemoryRepository.js +62 -0
- package/core/server/services/lib/InMemoryRepository.ts +80 -0
- package/core/server/services/lib/MailgunClient.js +364 -0
- package/core/server/services/link-redirection/LinkRedirect.js +26 -0
- package/core/server/services/link-redirection/LinkRedirectRepository.js +7 -7
- package/core/server/services/link-redirection/LinkRedirectsService.js +123 -0
- package/core/server/services/link-redirection/README.md +151 -0
- package/core/server/services/link-redirection/RedirectEvent.js +24 -0
- package/core/server/services/link-redirection/index.js +1 -1
- package/core/server/services/link-tracking/LinkClickTrackingService.js +1 -1
- package/core/server/services/mail/index.js +1 -1
- package/core/server/services/mail-events/InMemoryMailEventRepository.js +2 -2
- package/core/server/services/mail-events/InMemoryMailEventRepository.ts +1 -1
- package/core/server/services/members-events/LastSeenAtUpdater.js +1 -1
- package/core/server/services/offers/service.js +1 -1
- package/core/server/services/recommendations/RecommendationServiceWrapper.js +8 -8
- package/core/server/services/recommendations/service/BookshelfClickEventRepository.js +48 -0
- package/core/server/services/recommendations/service/BookshelfClickEventRepository.ts +49 -0
- package/core/server/services/recommendations/service/BookshelfRecommendationRepository.js +98 -0
- package/core/server/services/recommendations/service/BookshelfRecommendationRepository.ts +117 -0
- package/core/server/services/recommendations/service/BookshelfRepository.js +134 -0
- package/core/server/services/recommendations/service/BookshelfRepository.ts +196 -0
- package/core/server/services/recommendations/service/BookshelfSubscribeEventRepository.js +48 -0
- package/core/server/services/recommendations/service/BookshelfSubscribeEventRepository.ts +49 -0
- package/core/server/services/recommendations/service/ClickEvent.js +33 -0
- package/core/server/services/recommendations/service/ClickEvent.ts +32 -0
- package/core/server/services/recommendations/service/InMemoryRecommendationRepository.js +19 -0
- package/core/server/services/recommendations/service/InMemoryRecommendationRepository.ts +20 -0
- package/core/server/services/recommendations/service/IncomingRecommendationController.js +34 -0
- package/core/server/services/recommendations/service/IncomingRecommendationController.ts +51 -0
- package/core/server/services/recommendations/service/IncomingRecommendationEmailRenderer.js +25 -0
- package/core/server/services/recommendations/service/IncomingRecommendationEmailRenderer.ts +37 -0
- package/core/server/services/recommendations/service/IncomingRecommendationService.js +93 -0
- package/core/server/services/recommendations/service/IncomingRecommendationService.ts +160 -0
- package/core/server/services/recommendations/service/Recommendation.js +140 -0
- package/core/server/services/recommendations/service/Recommendation.ts +201 -0
- package/core/server/services/recommendations/service/RecommendationController.js +208 -0
- package/core/server/services/recommendations/service/RecommendationController.ts +258 -0
- package/core/server/services/recommendations/service/RecommendationMetadataService.js +86 -0
- package/core/server/services/recommendations/service/RecommendationMetadataService.ts +128 -0
- package/core/server/services/recommendations/service/RecommendationRepository.js +2 -0
- package/core/server/services/recommendations/service/RecommendationRepository.ts +13 -0
- package/core/server/services/recommendations/service/RecommendationService.js +228 -0
- package/core/server/services/recommendations/service/RecommendationService.ts +281 -0
- package/core/server/services/recommendations/service/SubscribeEvent.js +33 -0
- package/core/server/services/recommendations/service/SubscribeEvent.ts +32 -0
- package/core/server/services/recommendations/service/UnsafeData.js +183 -0
- package/core/server/services/recommendations/service/UnsafeData.ts +217 -0
- package/core/server/services/recommendations/service/WellknownService.js +36 -0
- package/core/server/services/recommendations/service/WellknownService.ts +47 -0
- package/core/server/services/recommendations/service/index.js +31 -0
- package/core/server/services/recommendations/service/index.ts +15 -0
- package/core/server/services/recommendations/service/libraries.d.ts +5 -0
- package/core/server/services/slack-notifications/SlackNotifications.js +211 -0
- package/core/server/services/slack-notifications/SlackNotificationsService.js +90 -0
- package/core/server/services/slack-notifications/service.js +4 -6
- package/core/server/web/api/endpoints/admin/app.js +1 -21
- package/core/server/web/api/middleware/version-match.js +41 -0
- package/core/shared/labs.js +2 -2
- package/package.json +87 -104
- package/tsconfig.tsbuildinfo +1 -1
- package/yarn.lock +1470 -1540
- package/components/tryghost-adapter-cache-redis-5.115.1.tgz +0 -0
- package/components/tryghost-adapter-manager-5.115.1.tgz +0 -0
- package/components/tryghost-announcement-bar-settings-5.115.1.tgz +0 -0
- package/components/tryghost-constants-5.115.1.tgz +0 -0
- package/components/tryghost-custom-fonts-5.115.1.tgz +0 -0
- package/components/tryghost-data-generator-5.115.1.tgz +0 -0
- package/components/tryghost-email-addresses-5.115.1.tgz +0 -0
- package/components/tryghost-email-content-generator-5.115.1.tgz +0 -0
- package/components/tryghost-email-events-5.115.1.tgz +0 -0
- package/components/tryghost-email-service-5.115.1.tgz +0 -0
- package/components/tryghost-email-suppression-list-5.115.1.tgz +0 -0
- package/components/tryghost-express-dynamic-redirects-5.115.1.tgz +0 -0
- package/components/tryghost-ghost-5.115.1.tgz +0 -0
- package/components/tryghost-html-to-plaintext-5.115.1.tgz +0 -0
- package/components/tryghost-i18n-5.115.1.tgz +0 -0
- package/components/tryghost-importer-handler-content-files-5.115.1.tgz +0 -0
- package/components/tryghost-in-memory-repository-5.115.1.tgz +0 -0
- package/components/tryghost-job-manager-5.115.1.tgz +0 -0
- package/components/tryghost-link-redirects-5.115.1.tgz +0 -0
- package/components/tryghost-link-replacer-5.115.1.tgz +0 -0
- package/components/tryghost-magic-link-5.115.1.tgz +0 -0
- package/components/tryghost-mailgun-client-5.115.1.tgz +0 -0
- package/components/tryghost-member-events-5.115.1.tgz +0 -0
- package/components/tryghost-members-api-5.115.1.tgz +0 -0
- package/components/tryghost-members-csv-5.115.1.tgz +0 -0
- package/components/tryghost-members-payments-5.115.1.tgz +0 -0
- package/components/tryghost-minifier-5.115.1.tgz +0 -0
- package/components/tryghost-mw-version-match-5.115.1.tgz +0 -0
- package/components/tryghost-mw-vhost-5.115.1.tgz +0 -0
- package/components/tryghost-posts-service-5.115.1.tgz +0 -0
- package/components/tryghost-recommendations-5.115.1.tgz +0 -0
- package/components/tryghost-security-5.115.1.tgz +0 -0
- package/components/tryghost-slack-notifications-5.115.1.tgz +0 -0
- package/components/tryghost-webmentions-5.115.1.tgz +0 -0
- package/core/built/admin/assets/chunk.524.2439684964c164c598ab.js +0 -35
- package/core/built/admin/assets/chunk.582.bf5a2bbb2c4eb69ef1e7.js +0 -37
- package/core/built/admin/assets/ghost-327b17ea23cb8c89bd7e6a51e18e8506.css +0 -1
- package/core/built/admin/assets/ghost-dark-f30a597ac19632a118939492591c531b.css +0 -1
- /package/core/built/admin/assets/{chunk.874.461cb3cf5b6b36915f8c.js.LICENSE.txt → chunk.713.e9027c0cc3c56110f5da.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const TableImporter = require('./TableImporter');
|
|
2
|
+
const {faker} = require('@faker-js/faker');
|
|
3
|
+
const {luck} = require('../utils/random');
|
|
4
|
+
const dateToDatabaseString = require('../utils/database-date');
|
|
5
|
+
|
|
6
|
+
class MembersSubscribeEventsImporter extends TableImporter {
|
|
7
|
+
static table = 'members_subscribe_events';
|
|
8
|
+
static dependencies = ['members', 'newsletters'];
|
|
9
|
+
|
|
10
|
+
constructor(knex, transaction) {
|
|
11
|
+
super(MembersSubscribeEventsImporter.table, knex, transaction);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async import(quantity) {
|
|
15
|
+
if (quantity === 0) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let offset = 0;
|
|
20
|
+
let limit = 100000;
|
|
21
|
+
this.newsletters = await this.transaction.select('id').from('newsletters').orderBy('sort_order');
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line no-constant-condition
|
|
24
|
+
while (true) {
|
|
25
|
+
const members = await this.transaction.select('id', 'created_at', 'status').from('members').limit(limit).offset(offset);
|
|
26
|
+
|
|
27
|
+
if (members.length === 0) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await this.importForEach(members, quantity ? quantity / members.length : this.newsletters.length);
|
|
32
|
+
offset += limit;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setReferencedModel(model) {
|
|
37
|
+
this.model = model;
|
|
38
|
+
this.count = 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
generate() {
|
|
42
|
+
const count = this.count;
|
|
43
|
+
this.count = this.count + 1;
|
|
44
|
+
|
|
45
|
+
if (count === 1 && this.model.status === 'free') {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let subscribed = luck(80);
|
|
50
|
+
|
|
51
|
+
if (!subscribed) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const createdAt = dateToDatabaseString(faker.date.between(new Date(this.model.created_at), new Date()));
|
|
56
|
+
const newsletterId = this.newsletters[count % this.newsletters.length].id;
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
id: this.fastFakeObjectId(),
|
|
60
|
+
member_id: this.model.id,
|
|
61
|
+
newsletter_id: newsletterId,
|
|
62
|
+
subscribed: 1,
|
|
63
|
+
created_at: createdAt,
|
|
64
|
+
source: 'member'
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = MembersSubscribeEventsImporter;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const TableImporter = require('./TableImporter');
|
|
2
|
+
const {faker} = require('@faker-js/faker');
|
|
3
|
+
const {luck} = require('../utils/random');
|
|
4
|
+
|
|
5
|
+
class MembersSubscriptionCreatedEventsImporter extends TableImporter {
|
|
6
|
+
static table = 'members_subscription_created_events';
|
|
7
|
+
static dependencies = ['members_stripe_customers', 'members_stripe_customers_subscriptions', 'posts', 'mentions'];
|
|
8
|
+
|
|
9
|
+
constructor(knex, transaction) {
|
|
10
|
+
super(MembersSubscriptionCreatedEventsImporter.table, knex, transaction);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async import(quantity) {
|
|
14
|
+
let offset = 0;
|
|
15
|
+
let limit = 1000;
|
|
16
|
+
this.posts = await this.transaction.select('id', 'published_at', 'visibility', 'type', 'slug').from('posts').whereNotNull('published_at').where('visibility', 'public').orderBy('published_at', 'desc');
|
|
17
|
+
this.incomingRecommendations = await this.transaction.select('id', 'source', 'created_at').from('mentions');
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line no-constant-condition
|
|
20
|
+
while (true) {
|
|
21
|
+
const membersStripeCustomersSubscriptions = await this.transaction.select('id', 'created_at', 'customer_id').from('members_stripe_customers_subscriptions').limit(limit).offset(offset);
|
|
22
|
+
|
|
23
|
+
if (membersStripeCustomersSubscriptions.length === 0) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
const membersStripeCustomers = await this.transaction.select('id', 'member_id', 'customer_id').from('members_stripe_customers').whereIn('customer_id', membersStripeCustomersSubscriptions.map(subscription => subscription.customer_id));
|
|
27
|
+
|
|
28
|
+
this.membersStripeCustomers = new Map();
|
|
29
|
+
for (const memberStripeCustomer of membersStripeCustomers) {
|
|
30
|
+
this.membersStripeCustomers.set(memberStripeCustomer.customer_id, memberStripeCustomer);
|
|
31
|
+
}
|
|
32
|
+
await this.importForEach(membersStripeCustomersSubscriptions, quantity ? quantity / membersStripeCustomersSubscriptions.length : 1);
|
|
33
|
+
offset += limit;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
generate() {
|
|
38
|
+
// We need to add all properties here already otherwise CSV imports won't know all the columns
|
|
39
|
+
let attribution = {
|
|
40
|
+
attribution_id: null,
|
|
41
|
+
attribution_type: null,
|
|
42
|
+
attribution_url: null
|
|
43
|
+
};
|
|
44
|
+
let referrer = {
|
|
45
|
+
referrer_source: null,
|
|
46
|
+
referrer_url: null,
|
|
47
|
+
referrer_medium: null
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (luck(30)) {
|
|
51
|
+
const post = this.posts.find(p => p.visibility === 'public' && new Date(p.published_at) < new Date(this.model.created_at));
|
|
52
|
+
if (post) {
|
|
53
|
+
attribution = {
|
|
54
|
+
attribution_id: post.id,
|
|
55
|
+
attribution_type: post.type,
|
|
56
|
+
attribution_url: post.slug
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (luck(40)) {
|
|
62
|
+
if (luck(20)) {
|
|
63
|
+
// Ghost network
|
|
64
|
+
referrer = {
|
|
65
|
+
referrer_source: luck(20) ? 'Ghost.org' : 'Ghost Explore',
|
|
66
|
+
referrer_url: 'ghost.org',
|
|
67
|
+
referrer_medium: 'Ghost Network'
|
|
68
|
+
};
|
|
69
|
+
} else {
|
|
70
|
+
// Incoming recommendation
|
|
71
|
+
const incomingRecommendation = faker.helpers.arrayElement(this.incomingRecommendations);
|
|
72
|
+
|
|
73
|
+
const hostname = new URL(incomingRecommendation.source).hostname;
|
|
74
|
+
referrer = {
|
|
75
|
+
referrer_source: hostname,
|
|
76
|
+
referrer_url: hostname,
|
|
77
|
+
referrer_medium: faker.helpers.arrayElement([null, 'Email'])
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const memberCustomer = this.membersStripeCustomers.get(this.model.customer_id);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
id: this.fastFakeObjectId(),
|
|
86
|
+
created_at: this.model.created_at,
|
|
87
|
+
member_id: memberCustomer.member_id,
|
|
88
|
+
subscription_id: this.model.id,
|
|
89
|
+
...attribution,
|
|
90
|
+
...referrer
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = MembersSubscriptionCreatedEventsImporter;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const TableImporter = require('./TableImporter');
|
|
2
|
+
const {blogStartDate} = require('../utils/blog-info');
|
|
3
|
+
const {faker} = require('@faker-js/faker');
|
|
4
|
+
const {slugify} = require('@tryghost/string');
|
|
5
|
+
|
|
6
|
+
class NewslettersImporter extends TableImporter {
|
|
7
|
+
static table = 'newsletters';
|
|
8
|
+
static dependencies = [];
|
|
9
|
+
|
|
10
|
+
defaultQuantity = 2;
|
|
11
|
+
|
|
12
|
+
sortOrder = 0;
|
|
13
|
+
|
|
14
|
+
constructor(knex, transaction) {
|
|
15
|
+
super(NewslettersImporter.table, knex, transaction);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
generate() {
|
|
19
|
+
const name = `${faker.commerce.productAdjective()} ${faker.word.noun()}`;
|
|
20
|
+
const sortOrder = this.sortOrder;
|
|
21
|
+
this.sortOrder = this.sortOrder + 1;
|
|
22
|
+
|
|
23
|
+
const weekAfter = new Date(blogStartDate);
|
|
24
|
+
weekAfter.setDate(weekAfter.getDate() + 7);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
id: this.fastFakeObjectId(),
|
|
28
|
+
uuid: faker.datatype.uuid(),
|
|
29
|
+
name: name,
|
|
30
|
+
slug: `${slugify(name)}-${faker.random.numeric(3)}`,
|
|
31
|
+
sender_reply_to: 'newsletter',
|
|
32
|
+
status: 'active',
|
|
33
|
+
subscribe_on_signup: faker.datatype.boolean(),
|
|
34
|
+
sort_order: sortOrder,
|
|
35
|
+
created_at: faker.date.between(blogStartDate, weekAfter)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = NewslettersImporter;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const TableImporter = require('./TableImporter');
|
|
2
|
+
const {faker} = require('@faker-js/faker');
|
|
3
|
+
const {slugify} = require('@tryghost/string');
|
|
4
|
+
const {blogStartDate} = require('../utils/blog-info');
|
|
5
|
+
const dateToDatabaseString = require('../utils/database-date');
|
|
6
|
+
|
|
7
|
+
class OffersImporter extends TableImporter {
|
|
8
|
+
static table = 'offers';
|
|
9
|
+
static dependencies = ['products'];
|
|
10
|
+
defaultQuantity = 2;
|
|
11
|
+
|
|
12
|
+
constructor(knex, transaction) {
|
|
13
|
+
super(OffersImporter.table, knex, transaction);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async import(quantity = this.defaultQuantity) {
|
|
17
|
+
this.products = await this.transaction.select('id', 'currency').from('products').where('type', 'paid');
|
|
18
|
+
this.names = ['Black Friday', 'Free Trial'];
|
|
19
|
+
this.count = 0;
|
|
20
|
+
|
|
21
|
+
await super.import(quantity);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
generate() {
|
|
25
|
+
const name = this.names.pop();
|
|
26
|
+
|
|
27
|
+
const product = this.products[faker.datatype.number({
|
|
28
|
+
min: 0,
|
|
29
|
+
max: this.products.length - 1
|
|
30
|
+
})];
|
|
31
|
+
|
|
32
|
+
// id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
|
33
|
+
// // @deprecated: use a status enum with isIn validation, not an `active` boolean
|
|
34
|
+
// active: {type: 'boolean', nullable: false, defaultTo: true},
|
|
35
|
+
// name: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
|
36
|
+
// code: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
|
37
|
+
// product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id'},
|
|
38
|
+
// stripe_coupon_id: {type: 'string', maxlength: 255, nullable: true, unique: true},
|
|
39
|
+
// interval: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['month', 'year']]}},
|
|
40
|
+
// currency: {type: 'string', maxlength: 50, nullable: true},
|
|
41
|
+
// discount_type: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['percent', 'amount', 'trial']]}},
|
|
42
|
+
// discount_amount: {type: 'integer', nullable: false},
|
|
43
|
+
// duration: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['trial', 'once', 'repeating', 'forever']]}},
|
|
44
|
+
// duration_in_months: {type: 'integer', nullable: true},
|
|
45
|
+
// portal_title: {type: 'string', maxlength: 191, nullable: true},
|
|
46
|
+
// portal_description: {type: 'string', maxlength: 2000, nullable: true},
|
|
47
|
+
// created_at: {type: 'dateTime', nullable: false},
|
|
48
|
+
// updated_at: {type: 'dateTime', nullable: true}
|
|
49
|
+
return {
|
|
50
|
+
id: this.fastFakeObjectId(),
|
|
51
|
+
active: true,
|
|
52
|
+
name,
|
|
53
|
+
code: slugify(name),
|
|
54
|
+
product_id: product.id,
|
|
55
|
+
stripe_coupon_id: faker.random.alphaNumeric(8),
|
|
56
|
+
interval: 'month',
|
|
57
|
+
currency: product.currency,
|
|
58
|
+
discount_type: name === 'Free Trial' ? 'trial' : 'percent',
|
|
59
|
+
discount_amount: name === 'Free Trial' ? 7 : 20,
|
|
60
|
+
duration: name === 'Free Trial' ? 'trial' : 'once',
|
|
61
|
+
duration_in_months: name === 'Free Trial' ? 1 : 12,
|
|
62
|
+
portal_title: name,
|
|
63
|
+
portal_description: name === 'Free Trial' ? 'Get a 1 week free trial' : 'Get 20% off for Black Friday',
|
|
64
|
+
created_at: dateToDatabaseString(blogStartDate),
|
|
65
|
+
updated_at: dateToDatabaseString(blogStartDate)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = OffersImporter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const {faker} = require('@faker-js/faker');
|
|
2
|
+
const TableImporter = require('./TableImporter');
|
|
3
|
+
|
|
4
|
+
class PostsAuthorsImporter extends TableImporter {
|
|
5
|
+
static table = 'posts_authors';
|
|
6
|
+
static dependencies = ['posts', 'users'];
|
|
7
|
+
|
|
8
|
+
constructor(knex, transaction) {
|
|
9
|
+
super(PostsAuthorsImporter.table, knex, transaction);
|
|
10
|
+
this.sortOrder = 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async import(quantity) {
|
|
14
|
+
const posts = await this.transaction.select('id').from('posts');
|
|
15
|
+
this.users = await this.transaction.select('id').from('users');
|
|
16
|
+
|
|
17
|
+
await this.importForEach(posts, quantity ? quantity / posts.length : 1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
generate() {
|
|
21
|
+
const sortOrder = this.sortOrder;
|
|
22
|
+
this.sortOrder = this.sortOrder + 1;
|
|
23
|
+
return {
|
|
24
|
+
id: this.fastFakeObjectId(),
|
|
25
|
+
post_id: this.model.id,
|
|
26
|
+
author_id: this.users[faker.datatype.number(this.users.length - 1)].id,
|
|
27
|
+
sort_order: sortOrder
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = PostsAuthorsImporter;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const {faker} = require('@faker-js/faker');
|
|
2
|
+
const {slugify} = require('@tryghost/string');
|
|
3
|
+
const {luck} = require('../utils/random');
|
|
4
|
+
const TableImporter = require('./TableImporter');
|
|
5
|
+
const dateToDatabaseString = require('../utils/database-date');
|
|
6
|
+
|
|
7
|
+
class PostsImporter extends TableImporter {
|
|
8
|
+
static table = 'posts';
|
|
9
|
+
static dependencies = ['newsletters'];
|
|
10
|
+
defaultQuantity = faker.datatype.number({
|
|
11
|
+
min: 80,
|
|
12
|
+
max: 120
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
type = 'post';
|
|
16
|
+
|
|
17
|
+
constructor(knex, transaction) {
|
|
18
|
+
super(PostsImporter.table, knex, transaction);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async import(quantity = this.defaultQuantity) {
|
|
22
|
+
this.newsletters = await this.transaction.select('id').from('newsletters').orderBy('sort_order');
|
|
23
|
+
|
|
24
|
+
await super.import(quantity);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
generate() {
|
|
28
|
+
const title = faker.lorem.sentence();
|
|
29
|
+
const content = faker.lorem.paragraphs(faker.datatype.number({
|
|
30
|
+
min: 3,
|
|
31
|
+
max: 10
|
|
32
|
+
})).split('\n');
|
|
33
|
+
const twoYearsAgo = new Date();
|
|
34
|
+
twoYearsAgo.setFullYear(twoYearsAgo.getFullYear() - 2);
|
|
35
|
+
const twoWeeksFromNow = new Date();
|
|
36
|
+
twoWeeksFromNow.setDate(twoWeeksFromNow.getDate() + 14);
|
|
37
|
+
const timestamp = faker.date.between(twoYearsAgo, twoWeeksFromNow);
|
|
38
|
+
const currentTime = new Date();
|
|
39
|
+
|
|
40
|
+
let status = 'published';
|
|
41
|
+
if (timestamp > currentTime) {
|
|
42
|
+
status = 'scheduled';
|
|
43
|
+
}
|
|
44
|
+
if (luck(5)) {
|
|
45
|
+
status = 'draft';
|
|
46
|
+
}
|
|
47
|
+
if (this.type === 'page') {
|
|
48
|
+
status = 'published';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const visibility = luck(85) ? 'paid' : luck(10) ? 'members' : 'public';
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
id: this.fastFakeObjectId(),
|
|
55
|
+
created_at: dateToDatabaseString(timestamp),
|
|
56
|
+
created_by: '1',
|
|
57
|
+
updated_at: dateToDatabaseString(timestamp),
|
|
58
|
+
published_at: status === 'published' ? dateToDatabaseString(timestamp) : status === 'scheduled' ? dateToDatabaseString(faker.date.soon(5, timestamp)) : null,
|
|
59
|
+
uuid: faker.datatype.uuid(),
|
|
60
|
+
title: title,
|
|
61
|
+
type: this.type,
|
|
62
|
+
slug: `${slugify(title)}-${faker.random.numeric(3)}`,
|
|
63
|
+
status,
|
|
64
|
+
visibility,
|
|
65
|
+
lexical: JSON.stringify({
|
|
66
|
+
root: {
|
|
67
|
+
children: content.map(paragraph => (
|
|
68
|
+
{
|
|
69
|
+
children: [
|
|
70
|
+
{
|
|
71
|
+
detail: 0,
|
|
72
|
+
format: 0,
|
|
73
|
+
mode: 'normal',
|
|
74
|
+
style: '',
|
|
75
|
+
text: paragraph,
|
|
76
|
+
type: 'extended-text',
|
|
77
|
+
version: 1
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
direction: 'ltr',
|
|
81
|
+
format: '',
|
|
82
|
+
indent: 0,
|
|
83
|
+
type: 'paragraph',
|
|
84
|
+
version: 1
|
|
85
|
+
}
|
|
86
|
+
)),
|
|
87
|
+
direction: 'ltr',
|
|
88
|
+
format: '',
|
|
89
|
+
indent: 0,
|
|
90
|
+
type: 'root',
|
|
91
|
+
version: 1
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
html: content.map(paragraph => `<p>${paragraph}</p>`).join(''),
|
|
95
|
+
plaintext: content.join('\n\n'),
|
|
96
|
+
email_recipient_filter: 'all',
|
|
97
|
+
newsletter_id: this.type === 'post' && status === 'published' && luck(90) ? (visibility === 'paid' ? this.newsletters[0].id : this.newsletters[1].id) : null
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = PostsImporter;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const TableImporter = require('./TableImporter');
|
|
2
|
+
|
|
3
|
+
class PostsProductsImporter extends TableImporter {
|
|
4
|
+
static table = 'posts_products';
|
|
5
|
+
static dependencies = ['posts', 'products'];
|
|
6
|
+
|
|
7
|
+
constructor(knex, transaction) {
|
|
8
|
+
super(PostsProductsImporter.table, knex, transaction);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async import(quantity) {
|
|
12
|
+
const posts = await this.transaction.select('id').from('posts').where('type', 'post');
|
|
13
|
+
this.products = await this.transaction.select('id').from('products');
|
|
14
|
+
|
|
15
|
+
await this.importForEach(posts, quantity ? quantity / posts.length : 1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setReferencedModel(model) {
|
|
19
|
+
this.model = model;
|
|
20
|
+
this.sortOrder = 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
generate() {
|
|
24
|
+
const sortOrder = this.sortOrder;
|
|
25
|
+
this.sortOrder = this.sortOrder + 1;
|
|
26
|
+
return {
|
|
27
|
+
id: this.fastFakeObjectId(),
|
|
28
|
+
post_id: this.model.id,
|
|
29
|
+
product_id: this.products[sortOrder].id,
|
|
30
|
+
sort_order: this.sortOrder
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = PostsProductsImporter;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const {faker} = require('@faker-js/faker');
|
|
2
|
+
const TableImporter = require('./TableImporter');
|
|
3
|
+
|
|
4
|
+
class PostsTagsImporter extends TableImporter {
|
|
5
|
+
static table = 'posts_tags';
|
|
6
|
+
static dependencies = ['posts', 'tags'];
|
|
7
|
+
|
|
8
|
+
constructor(knex, transaction) {
|
|
9
|
+
super(PostsTagsImporter.table, knex, transaction);
|
|
10
|
+
this.sortOrder = 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async import(quantity) {
|
|
14
|
+
const posts = await this.transaction.select('id').from('posts').where('type', 'post');
|
|
15
|
+
this.tags = await this.transaction.select('id').from('tags');
|
|
16
|
+
|
|
17
|
+
await this.importForEach(posts, quantity ? quantity / posts.length : () => faker.datatype.number({
|
|
18
|
+
min: 0,
|
|
19
|
+
max: 3
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setReferencedModel(model) {
|
|
24
|
+
this.model = model;
|
|
25
|
+
this.notIndex = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
generate() {
|
|
29
|
+
const sortOrder = this.sortOrder;
|
|
30
|
+
this.sortOrder = this.sortOrder + 1;
|
|
31
|
+
let tagIndex = 0;
|
|
32
|
+
do {
|
|
33
|
+
tagIndex = faker.datatype.number(this.tags.length - 1);
|
|
34
|
+
} while (this.notIndex.includes(tagIndex));
|
|
35
|
+
this.notIndex.push(tagIndex);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
id: this.fastFakeObjectId(),
|
|
39
|
+
post_id: this.model.id,
|
|
40
|
+
tag_id: this.tags[tagIndex].id,
|
|
41
|
+
sort_order: sortOrder
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = PostsTagsImporter;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const TableImporter = require('./TableImporter');
|
|
2
|
+
|
|
3
|
+
class ProductsBenefitsImporter extends TableImporter {
|
|
4
|
+
static table = 'products_benefits';
|
|
5
|
+
static dependencies = ['benefits', 'products'];
|
|
6
|
+
|
|
7
|
+
constructor(knex, transaction) {
|
|
8
|
+
super(ProductsBenefitsImporter.table, knex, transaction);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async import(quantity) {
|
|
12
|
+
const products = await this.transaction.select('id', 'name').from('products');
|
|
13
|
+
this.benefits = await this.transaction.select('id').from('benefits');
|
|
14
|
+
|
|
15
|
+
await this.importForEach(products, quantity ? quantity / products.length : 5);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
setReferencedModel(model) {
|
|
19
|
+
this.model = model;
|
|
20
|
+
|
|
21
|
+
this.sortOrder = 0;
|
|
22
|
+
switch (this.model.name) {
|
|
23
|
+
case 'Bronze':
|
|
24
|
+
this.benefitCount = 1;
|
|
25
|
+
break;
|
|
26
|
+
case 'Silver':
|
|
27
|
+
this.benefitCount = 3;
|
|
28
|
+
break;
|
|
29
|
+
case 'Gold':
|
|
30
|
+
this.benefitCount = 5;
|
|
31
|
+
break;
|
|
32
|
+
case 'Free Preview':
|
|
33
|
+
this.benefitCount = 0;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
generate() {
|
|
39
|
+
if (this.sortOrder >= this.benefitCount) {
|
|
40
|
+
// No more benefits than benefitCount
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const sortOrder = this.sortOrder;
|
|
44
|
+
this.sortOrder = this.sortOrder + 1;
|
|
45
|
+
return {
|
|
46
|
+
id: this.fastFakeObjectId(),
|
|
47
|
+
product_id: this.model.id,
|
|
48
|
+
benefit_id: this.benefits[sortOrder].id,
|
|
49
|
+
sort_order: sortOrder
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = ProductsBenefitsImporter;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const TableImporter = require('./TableImporter');
|
|
2
|
+
const {faker} = require('@faker-js/faker');
|
|
3
|
+
const {slugify} = require('@tryghost/string');
|
|
4
|
+
const {blogStartDate} = require('../utils/blog-info');
|
|
5
|
+
|
|
6
|
+
class ProductsImporter extends TableImporter {
|
|
7
|
+
static table = 'products';
|
|
8
|
+
static dependencies = [];
|
|
9
|
+
defaultQuantity = 4;
|
|
10
|
+
|
|
11
|
+
constructor(knex, transaction) {
|
|
12
|
+
super(ProductsImporter.table, knex, transaction);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async import(quantity = this.defaultQuantity) {
|
|
16
|
+
// TODO: Add random products if quantity != 4
|
|
17
|
+
this.names = ['Free', 'Bronze', 'Silver', 'Gold'].reverse();
|
|
18
|
+
this.count = 0;
|
|
19
|
+
|
|
20
|
+
await super.import(quantity);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Add the stripe products / prices
|
|
25
|
+
*/
|
|
26
|
+
async finalise() {
|
|
27
|
+
const stripeProducts = await this.transaction.select('id', 'product_id', 'stripe_product_id').from('stripe_products');
|
|
28
|
+
const stripePrices = await this.transaction.select('id', 'stripe_product_id', 'interval').from('stripe_prices');
|
|
29
|
+
|
|
30
|
+
const products = await this.transaction.select('id').from('products');
|
|
31
|
+
|
|
32
|
+
for (const {id} of products) {
|
|
33
|
+
const stripeProduct = stripeProducts.find(p => id === p.product_id);
|
|
34
|
+
if (!stripeProduct) {
|
|
35
|
+
// Free product
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const monthlyPrice = stripePrices.find((p) => {
|
|
39
|
+
return p.stripe_product_id === stripeProduct.stripe_product_id &&
|
|
40
|
+
p.interval === 'monthly';
|
|
41
|
+
});
|
|
42
|
+
const yearlyPrice = stripePrices.find((p) => {
|
|
43
|
+
return p.stripe_product_id === stripeProduct.stripe_product_id &&
|
|
44
|
+
p.interval === 'yearly';
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const update = {};
|
|
48
|
+
if (monthlyPrice) {
|
|
49
|
+
update.monthly_price_id = monthlyPrice.id;
|
|
50
|
+
}
|
|
51
|
+
if (yearlyPrice) {
|
|
52
|
+
update.yearly_price_id = yearlyPrice.id;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Object.keys(update).length > 0) {
|
|
56
|
+
await this.transaction('products').update(update).where({
|
|
57
|
+
id
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
generate() {
|
|
64
|
+
const name = this.names.pop();
|
|
65
|
+
const count = this.count;
|
|
66
|
+
this.count = this.count + 1;
|
|
67
|
+
const sixMonthsLater = new Date(blogStartDate);
|
|
68
|
+
sixMonthsLater.setMonth(sixMonthsLater.getMonth() + 6);
|
|
69
|
+
const tierInfo = {
|
|
70
|
+
type: 'free',
|
|
71
|
+
description: 'A free sample of content'
|
|
72
|
+
};
|
|
73
|
+
if (count !== 0) {
|
|
74
|
+
tierInfo.type = 'paid';
|
|
75
|
+
tierInfo.description = `${name} tier member`;
|
|
76
|
+
tierInfo.currency = 'USD';
|
|
77
|
+
tierInfo.monthly_price = count * 500;
|
|
78
|
+
tierInfo.yearly_price = count * 5000;
|
|
79
|
+
}
|
|
80
|
+
return Object.assign({}, {
|
|
81
|
+
id: this.fastFakeObjectId(),
|
|
82
|
+
name: name,
|
|
83
|
+
slug: `${slugify(name)}-${faker.random.numeric(3)}`,
|
|
84
|
+
visibility: 'public',
|
|
85
|
+
created_at: faker.date.between(blogStartDate, sixMonthsLater)
|
|
86
|
+
}, tierInfo);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = ProductsImporter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const TableImporter = require('./TableImporter');
|
|
2
|
+
const {faker} = require('@faker-js/faker');
|
|
3
|
+
const {luck} = require('../utils/random');
|
|
4
|
+
|
|
5
|
+
class RecommendationClickEventsImporter extends TableImporter {
|
|
6
|
+
static table = 'recommendation_click_events';
|
|
7
|
+
static dependencies = ['recommendations', 'members'];
|
|
8
|
+
|
|
9
|
+
constructor(knex, transaction) {
|
|
10
|
+
super(RecommendationClickEventsImporter.table, knex, transaction);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async import(quantity) {
|
|
14
|
+
const recommendations = await this.transaction.select('id', 'created_at').from('recommendations');
|
|
15
|
+
this.members = await this.transaction.select('id').from('members').limit(500);
|
|
16
|
+
|
|
17
|
+
await this.importForEach(recommendations, quantity ? quantity / recommendations.length : () => faker.datatype.number({min: 0, max: 30}));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
generate() {
|
|
21
|
+
// Not unique
|
|
22
|
+
const member = luck(30) ? null : faker.helpers.arrayElement(this.members);
|
|
23
|
+
return {
|
|
24
|
+
id: this.fastFakeObjectId(),
|
|
25
|
+
recommendation_id: this.model.id,
|
|
26
|
+
member_id: member?.id ?? null,
|
|
27
|
+
created_at: faker.date.past()
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = RecommendationClickEventsImporter;
|