307 lines
6.8 KiB
JavaScript
307 lines
6.8 KiB
JavaScript
let isPremium = true; // if false, will use plus
|
|
|
|
let feature_enrollments = [{
|
|
"id": 0,
|
|
"feature": "publish",
|
|
"createDate": "2011-11-11T00:00:00.000Z",
|
|
"status": "active",
|
|
"isActive": true
|
|
},
|
|
{
|
|
"id": 0,
|
|
"feature": "backup",
|
|
"createDate": "2011-11-11T00:00:00.000Z",
|
|
"status": "active",
|
|
"isActive": true
|
|
},
|
|
{
|
|
"id": 0,
|
|
"feature": "sync",
|
|
"createDate": "2011-11-11T00:00:00.000Z",
|
|
"status": "active",
|
|
"isActive": true
|
|
}
|
|
]
|
|
|
|
let subscription = {
|
|
"premium": isPremium,
|
|
"plus_on_ios": true,
|
|
"plus_on_mac": true,
|
|
"source": [
|
|
"Receipt"
|
|
],
|
|
"auto_renew": false,
|
|
"is_trial": false,
|
|
"expires": (isPremium ? "2099-12-31T23:59:59.999Z" : null),
|
|
"product_id": (isPremium ? "com.bloombuilt.dayoneios.subscription.premium.yearly" : null),
|
|
"is_eligible_for_trial": true,
|
|
"is_in_billing_retry_period": false
|
|
}
|
|
|
|
let bundle = {
|
|
"bundleName": (isPremium ? "premium" : "grandfathered"),
|
|
"reason": "purchase",
|
|
"features": [{
|
|
"name": "imagesPerEntry",
|
|
"limit": (isPremium ? 30 : 10),
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "imagesPerSharedEntry",
|
|
"limit": 30,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "journalLimit",
|
|
"limit": (isPremium ? 200 : 10),
|
|
"canUpgrade": !isPremium
|
|
},
|
|
...(isPremium ? [{
|
|
"name": "audioPerEntry",
|
|
"limit": 10,
|
|
"canUpgrade": false
|
|
}] : []),
|
|
{
|
|
"name": "sync",
|
|
"limit": null,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "backup",
|
|
"limit": null,
|
|
"canUpgrade": false
|
|
},
|
|
...(!isPremium ? [{
|
|
"name": "discountedSubscription",
|
|
"limit": null,
|
|
"canUpgrade": false
|
|
}] : []),
|
|
...(isPremium ? [{
|
|
"name": "printingDiscount",
|
|
"limit": null,
|
|
"canUpgrade": false
|
|
}, {
|
|
"name": "prioritySupport",
|
|
"limit": null,
|
|
"canUpgrade": false
|
|
}, {
|
|
"name": "drawingsPerEntry",
|
|
"limit": 30,
|
|
"canUpgrade": false
|
|
}, {
|
|
"name": "scanToPDF",
|
|
"limit": 30,
|
|
"canUpgrade": false
|
|
}, {
|
|
"name": "videosPerEntry",
|
|
"limit": 30,
|
|
"canUpgrade": false
|
|
}, {
|
|
"name": "journalViaSMS",
|
|
"limit": null,
|
|
"canUpgrade": false
|
|
}] : [])
|
|
],
|
|
"featuresFull": [{
|
|
"name": "journalLimit",
|
|
"limit": (isPremium ? 200 : 10),
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "backup",
|
|
"enabled": true,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "sync",
|
|
"enabled": true,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "discountedSubscription",
|
|
"enabled": !isPremium,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "printingDiscount",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "prioritySupport",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "scanToPDF",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "attachmentsPerEntry",
|
|
"limit": (isPremium ? 30 : 10),
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "journalViaSMS",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "canAttachPhoto",
|
|
"enabled": true,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "canAttachVideo",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "canAttachAudio",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "canAttachDrawing",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "canAttachPDF",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "canAttachSharedPhoto",
|
|
"enabled": true,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "canAttachSharedVideo",
|
|
"enabled": true,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "canAttachSharedAudio",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "canAttachSharedDrawing",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "canAttachSharedPDF",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "attachmentsPerSharedEntry",
|
|
"limit": 30,
|
|
"canUpgrade": false
|
|
},
|
|
{
|
|
"name": "instagram",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "ifttt",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "colors",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "emailToJournal",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "appIcons",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "moonPhase",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "foursquareNearbyVenues",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
},
|
|
{
|
|
"name": "createSharedJournal",
|
|
"enabled": isPremium,
|
|
"canUpgrade": !isPremium
|
|
}
|
|
]
|
|
}
|
|
|
|
let account_status = {
|
|
"subscriptionName": (isPremium ? "premium" : "grandfathered"),
|
|
"bundleReason": "purchase",
|
|
"expirationDate": (isPremium ? 4102415999999 : null),
|
|
"giftedByName": null,
|
|
"source": (isPremium ? "receipt" : "min")
|
|
}
|
|
|
|
async function onResponse(context, url, request, response) {
|
|
response.headers["Content-Type"] = "application/json";
|
|
response.statusCode = 200;
|
|
response.statusPhrase = "OK";
|
|
|
|
let body = response.body;
|
|
|
|
if (url.includes("account-status")) { // /account-status
|
|
body = account_status;
|
|
} else { // /users OR /v2/users/receipt
|
|
body.subscription = subscription;
|
|
if (url.includes("v2")) { // /v2/users/receipt
|
|
body.bundle = bundle;
|
|
} else { // /users
|
|
body.featureBundle = bundle;
|
|
body.featureEnrollments = feature_enrollments;
|
|
}
|
|
}
|
|
|
|
response.body = body;
|
|
return response;
|
|
}
|
|
|
|
|
|
const isSurge = typeof $httpClient != "undefined";
|
|
const isQuanX = typeof $task != "undefined";
|
|
const isLoon = typeof $loon != "undefined";
|
|
const isJSBox = typeof $app != "undefined" && typeof $http != "undefined";
|
|
const isNode = typeof require == "function" && !isJSBox;
|
|
|
|
if (isSurge || isQuanX) {
|
|
url = $request.url;
|
|
|
|
$request.body = typeof $request.body != "undefined" ? JSON.parse($request.body) : {};
|
|
$response.body = typeof $response.body != "undefined" ? JSON.parse($response.body) : {};
|
|
|
|
response = onResponse(null, url, $request, $response);
|
|
|
|
if (isQuanX) {
|
|
$request.status = "HTTP/1.1 " + $request.statusCode + " " + $request.statusPhrase;
|
|
$response.status = "HTTP/1.1 " + $response.statusCode + " " + $response.statusPhrase;
|
|
$request.body = JSON.stringify($request.body);
|
|
$response.body = JSON.stringify($response.body);
|
|
}
|
|
|
|
$done({
|
|
status: $response.status,
|
|
headers: $response.headers,
|
|
body: $response.body
|
|
});
|
|
}
|