Skip to content

Commit 465ac59

Browse files
committed
adding versioning to purchase info that we actually store going forward.
1 parent 219d5a1 commit 465ac59

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/packages/util/licenses/purchase/consts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import costVersions from "./cost-versions";
1111
// is used when the version is not defined.
1212
const FALLBACK_VERSION = "1";
1313

14-
const CURRENT_VERSION = "1";
14+
export const CURRENT_VERSION = "1";
1515

1616
// Another gamble implicit in this is that pre's are available. When they
1717
// aren't, cocalc.com switches to uses MUCH more expensive non-preemptibles.

src/packages/util/licenses/purchase/purchase-info.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
SiteLicenseDescriptionDB,
44
} from "@cocalc/util/upgrades/shopping";
55
import type { PurchaseInfo, StartEndDates, Subscription } from "./types";
6+
import { CURRENT_VERSION } from "./consts";
67
import type { Date0 } from "@cocalc/util/types/store";
78
import dayjs from "dayjs";
89

@@ -28,6 +29,7 @@ export default function getPurchaseInfo(
2829
boost = false,
2930
} = conf;
3031
return {
32+
version: CURRENT_VERSION,
3133
type, // "quota"
3234
user,
3335
upgrade: "custom" as "custom",
@@ -48,6 +50,7 @@ export default function getPurchaseInfo(
4850

4951
case "vm":
5052
return {
53+
version: CURRENT_VERSION,
5154
type: "vm",
5255
quantity: 1,
5356
dedicated_vm: conf.dedicated_vm,
@@ -59,6 +62,7 @@ export default function getPurchaseInfo(
5962

6063
case "disk":
6164
return {
65+
version: CURRENT_VERSION,
6266
type: "disk",
6367
quantity: 1,
6468
dedicated_disk: conf.dedicated_disk,

src/packages/util/licenses/purchase/types.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import type { DedicatedDisk, DedicatedVM } from "@cocalc/util/types/dedicated";
5555
import type { CustomDescription, Period } from "../../upgrades/shopping";
5656

5757
interface Version {
58-
version?: string; // it's just a string with no special interpretation.
58+
version: string; // it's just a string with no special interpretation.
5959
}
6060

6161
interface PurchaseInfoQuota0 {
@@ -81,8 +81,7 @@ interface PurchaseInfoQuota0 {
8181
run_limit?: number;
8282
}
8383

84-
export type PurchaseInfoQuota = Version &
85-
PurchaseInfoQuota0 &
84+
export type PurchaseInfoQuota = PurchaseInfoQuota0 &
8685
CustomDescription &
8786
StartEndDates;
8887

@@ -113,11 +112,13 @@ export type PurchaseInfoDisk = {
113112
payment_method?: string;
114113
};
115114

116-
export type PurchaseInfo =
117-
| PurchaseInfoQuota
118-
| (PurchaseInfoVoucher & CustomDescription)
119-
| (PurchaseInfoVM & StartEndDates & CustomDescription)
120-
| (PurchaseInfoDisk & StartEndDates & CustomDescription);
115+
export type PurchaseInfo = Version &
116+
(
117+
| PurchaseInfoQuota
118+
| (PurchaseInfoVoucher & CustomDescription)
119+
| (PurchaseInfoVM & StartEndDates & CustomDescription)
120+
| (PurchaseInfoDisk & StartEndDates & CustomDescription)
121+
);
121122

122123
// stripe's metadata can only handle string or number values.
123124
export type ProductMetadataQuota = Record<

src/packages/util/licenses/store/compute-cost.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { fixRange } from "@cocalc/util/licenses/purchase/purchase-info";
1616
import { getDays } from "@cocalc/util/stripe/timecalcs";
1717
import { PRICES } from "@cocalc/util/upgrades/dedicated";
1818
import type { ComputeCostProps } from "@cocalc/util/upgrades/shopping";
19+
import { CURRENT_VERSION } from "@cocalc/util/licenses/purchase/consts";
1920

2021
function computeDedicatedDiskCost(
2122
props: ComputeCostProps,
@@ -138,6 +139,7 @@ export function computeCost(
138139
}
139140

140141
const input: PurchaseInfo = {
142+
version: CURRENT_VERSION,
141143
type: "quota",
142144
user,
143145
upgrade: "custom" as "custom",

0 commit comments

Comments
 (0)