0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Removed uuid usage in favor of local object id generation

no refs
This commit is contained in:
Rishabh 2021-10-18 14:25:06 +05:30
parent 24f087ddf2
commit 3b734f5c84
3 changed files with 25 additions and 21 deletions

View file

@ -25,8 +25,7 @@
"@testing-library/user-event": "13.3.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-scripts": "4.0.3",
"uuid": "^8.3.2"
"react-scripts": "4.0.3"
},
"scripts": {
"start": "BROWSER=none react-scripts start",

View file

@ -1,11 +1,16 @@
import {v4 as uuidv4} from 'uuid';
export const sites = {
singleProduct: getSiteData({
products: getProductsData({numOfProducts: 1})
})
};
function objectId() {
const timestamp = (new Date().getTime() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function () {
return (Math.random() * 16 | 0).toString(16);
}).toLowerCase();
}
export function getSiteData({
products = getProductsData({numOfProducts: 1}),
portalProducts = products.map(p => p.id),
@ -50,13 +55,13 @@ function getOfferData({
amount = 50,
duration = 'once',
durationInMonths = null,
currencyRestruction = false,
currencyRestriction = false,
currency = null,
status = 'active',
tierId = ''
} = {}) {
return {
id: `offer_${uuidv4()}`,
id: `offer_${objectId()}`,
name,
code,
display_title: displayTitle,
@ -66,7 +71,7 @@ function getOfferData({
amount,
duration,
duration_in_months: durationInMonths,
currency_restriction: currencyRestruction,
currency_restriction: currencyRestriction,
currency,
status,
tier: {
@ -86,7 +91,7 @@ function getMemberData({
subscribed = true
} = {}) {
return {
uuid: `member_${uuidv4()}`,
uuid: `member_${objectId()}`,
email,
name,
firstname,
@ -145,7 +150,7 @@ export function getProductsData({numOfProducts = 3} = {}) {
function getProductData({
name = 'Basic',
description = '',
id = `product_${uuidv4()}`,
id = `product_${objectId()}`,
monthlyPrice = getPriceData(),
yearlyPrice = getPriceData({interval: 'year'}),
numOfBenefits = 2
@ -172,7 +177,7 @@ function getBenefits({numOfBenefits}) {
}
function getBenefitData({
id = `benefit_${uuidv4()}`,
id = `benefit_${objectId()}`,
name = 'Benefit'
}) {
return {
@ -188,7 +193,7 @@ function getPriceData({
description = null,
currency = 'usd',
active = true,
id = `price_${uuidv4()}`
id = `price_${objectId()}`
}) {
return {
id: id,
@ -198,21 +203,21 @@ function getPriceData({
amount,
interval,
description,
stripe_price_id: `price_${uuidv4()}`,
stripe_product_id: `prod_${uuidv4()}`,
stripe_price_id: `price_${objectId()}`,
stripe_product_id: `prod_${objectId()}`,
type: 'recurring'
};
}
function getSubscriptionData({
id = `sub_${uuidv4()}`,
id = `sub_${objectId()}`,
status = 'active',
currency = 'USD',
interval = 'month',
amount = (interval === 'month' ? 500 : 5000),
nickname = (interval === 'month' ? 'Monthly' : 'Yearly'),
cardLast4 = '4242',
priceId: price_id = `price_${uuidv4()}`,
priceId: price_id = `price_${objectId()}`,
startDate: start_date = '2021-10-05T03:18:30.000Z',
currentPeriodEnd: current_period_end = '2022-10-05T03:18:30.000Z',
cancelAtPeriodEnd: cancel_at_period_end = false
@ -220,12 +225,12 @@ function getSubscriptionData({
return {
id,
customer: {
id: `cus_${uuidv4()}`,
id: `cus_${objectId()}`,
name: 'Jamie',
email: 'jamie@example.com'
},
plan: {
id: `price_${uuidv4()}`,
id: `price_${objectId()}`,
nickname,
amount,
interval,
@ -238,7 +243,7 @@ function getSubscriptionData({
cancellation_reason: null,
current_period_end,
price: {
id: `stripe_price_${uuidv4()}`,
id: `stripe_price_${objectId()}`,
price_id,
nickname,
amount,
@ -246,8 +251,8 @@ function getSubscriptionData({
type: 'recurring',
currency,
product: {
id: `stripe_prod_${uuidv4()}`,
product_id: `prod_${uuidv4()}`
id: `stripe_prod_${objectId()}`,
product_id: `prod_${objectId()}`
}
}
};

View file

@ -11707,7 +11707,7 @@ uuid@^3.3.2, uuid@^3.4.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
uuid@^8.3.0, uuid@^8.3.2:
uuid@^8.3.0:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==