|
1 | 1 | import { getInstallation, getResource } from "../partner";
|
2 | 2 | import { env } from "../env";
|
3 | 3 | import { z } from "zod";
|
4 |
| -import { |
| 4 | +import type { |
5 | 5 | Balance,
|
6 | 6 | BillingData,
|
| 7 | + BillingPlan, |
7 | 8 | CreateInvoiceRequest,
|
8 | 9 | DeploymentActionOutcome,
|
9 | 10 | ImportResourceRequest,
|
@@ -52,7 +53,7 @@ export async function getAccountInfo(
|
52 | 53 | })) as AccountInfo;
|
53 | 54 | }
|
54 | 55 |
|
55 |
| -export async function updateSecrets( |
| 56 | +export async function updateSecrets( // vercel fetch api |
56 | 57 | installationId: string,
|
57 | 58 | resourceId: string,
|
58 | 59 | secrets: { name: string; value: string }[]
|
@@ -159,20 +160,26 @@ export async function submitInvoice(
|
159 | 160 |
|
160 | 161 | let items = billingData.billing.filter((item) => Boolean(item.resourceId));
|
161 | 162 | if (maxAmount !== undefined) {
|
162 |
| - const total = items.reduce((acc, item) => acc + parseFloat(item.total), 0); |
| 163 | + const total = items.reduce( |
| 164 | + (acc, item) => acc + Number.parseFloat(item.total), |
| 165 | + 0 |
| 166 | + ); |
163 | 167 | if (total > maxAmount) {
|
164 | 168 | const ratio = maxAmount / total;
|
165 | 169 | items = items.map((item) => ({
|
166 | 170 | ...item,
|
167 | 171 | quantity: item.quantity * ratio,
|
168 |
| - total: (parseFloat(item.total) * ratio).toFixed(2), |
| 172 | + total: (Number.parseFloat(item.total) * ratio).toFixed(2), |
169 | 173 | }));
|
170 | 174 | }
|
171 | 175 | }
|
172 | 176 |
|
173 | 177 | const discounts: InvoiceDiscount[] = [];
|
174 | 178 | if (opts?.discountPercent !== undefined && opts.discountPercent > 0) {
|
175 |
| - const total = items.reduce((acc, item) => acc + parseFloat(item.total), 0); |
| 179 | + const total = items.reduce( |
| 180 | + (acc, item) => acc + Number.parseFloat(item.total), |
| 181 | + 0 |
| 182 | + ); |
176 | 183 | if (total > 0) {
|
177 | 184 | const discount = total * opts.discountPercent;
|
178 | 185 | discounts.push({
|
@@ -292,3 +299,28 @@ export async function getDeployment(
|
292 | 299 | }
|
293 | 300 | );
|
294 | 301 | }
|
| 302 | + |
| 303 | +export async function requestTransferToMarketplace( |
| 304 | + installationId: string, |
| 305 | + transferId: string, |
| 306 | + requester: string, |
| 307 | + billingPlan: BillingPlan |
| 308 | +): Promise<{ continueUrl: string }> { |
| 309 | + const result = (await fetchVercelApi( |
| 310 | + `/v1/installations/${installationId}/transfers/to-marketplace`, |
| 311 | + { |
| 312 | + installationId, |
| 313 | + method: "POST", |
| 314 | + data: { |
| 315 | + transferId, |
| 316 | + requester: { name: requester }, |
| 317 | + billingPlan, |
| 318 | + } satisfies { |
| 319 | + transferId: string; |
| 320 | + requester: { name: string }; |
| 321 | + billingPlan: BillingPlan; |
| 322 | + }, |
| 323 | + } |
| 324 | + )) as { continueUrl: string }; |
| 325 | + return result; |
| 326 | +} |
0 commit comments