173 lines
4.5 KiB
TypeScript
173 lines
4.5 KiB
TypeScript
// Metro module 5678 (f5679).
|
|
import { Endpoints } from "../../Constants";
|
|
import Logger from "../debug/Logger";
|
|
import BillingError from "../../errors/BillingError";
|
|
import { HTTP, HTTPResponseError } from "../../_bundle/sendRequest";
|
|
import { captureBillingException } from "../../utils/BillingUtils";
|
|
let OrderSigningFailedWithConstraintsError;
|
|
let c3514_4 = new Logger("OrderActionCreators");
|
|
const OrderSigningFailedWithConstraintsError2 = class OrderSigningFailedWithConstraintsError extends BillingError {
|
|
constructor(a0) {
|
|
super("Order signing failed due to unsatisfied constraints");
|
|
this.order = a0;
|
|
}
|
|
};
|
|
OrderSigningFailedWithConstraintsError2.prototype;
|
|
OrderSigningFailedWithConstraintsError = OrderSigningFailedWithConstraintsError2;
|
|
class OrderProcessingPendingError extends BillingError {
|
|
constructor() {
|
|
super("Order signed but entitlements not yet visible after polling");
|
|
}
|
|
}
|
|
export { OrderSigningFailedWithConstraintsError };
|
|
export { OrderProcessingPendingError };
|
|
export async function signOrder(c25531_0) {
|
|
let body;
|
|
let c25531_1, c25531_2, c25531_3;
|
|
let c25531_4 = 0;
|
|
const r16 = void 0;
|
|
try {
|
|
let env29546;
|
|
c25531_2 = r16;
|
|
const r36 = env29546 = {};
|
|
c25531_1 = r36;
|
|
env29546[0] = void 0;
|
|
env29546[1] = void 0;
|
|
env29546[2] = void 0;
|
|
env29546[0] = c25531_0.orderId;
|
|
env29546[1] = c25531_0.expectedRevision;
|
|
env29546[2] = c25531_0.loadId;
|
|
env29546[3] = void 0;
|
|
env29546[4] = void 0;
|
|
await void 0;
|
|
env29546[4] = {};
|
|
if (env29546[1] != null) {
|
|
env29546[4].expected_revision = env29546[1];
|
|
}
|
|
c25531_4 = 1;
|
|
env29546[3] = await HTTP.post({
|
|
url: Endpoints.ORDER_SIGN(env29546[0]),
|
|
body: env29546[4],
|
|
context: env29546[2] != null ? env29546[2] !== "" ? {
|
|
load_id: env29546[2]
|
|
} : void 0 : void 0,
|
|
rejectWithError: true
|
|
});
|
|
c25531_4 = 0;
|
|
if (env29546[3].body == null) {
|
|
throw new Error("Invalid sign order response");
|
|
}
|
|
body = env29546[3].body;
|
|
} catch ($e) {
|
|
const r34 = $e;
|
|
let r8 = r34;
|
|
c25531_3 = r34;
|
|
if (c25531_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r121 = c25531_3;
|
|
c25531_4 = 0;
|
|
env29546[5] = r121;
|
|
if (env29546[5] instanceof HTTPResponseError && env29546[5].status === 400 && (function isOrderShape(a0) {
|
|
return a0 != null && typeof a0 === "object" && "id" in a0 && "status" in a0;
|
|
})(env29546[5].body)) {
|
|
throw new OrderSigningFailedWithConstraintsError(env29546[5].body);
|
|
}
|
|
throw env29546[5];
|
|
} catch (r117) {
|
|
r8 = r117;
|
|
c25531_3 = r117;
|
|
if (c25531_4 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return body;
|
|
}
|
|
export async function getOrder(c25532_0) {
|
|
let r54;
|
|
let c25532_3;
|
|
let c25532_4 = 0;
|
|
let c29547_0, c29547_1;
|
|
try {
|
|
c29547_0 = c25532_0;
|
|
c25532_4 = 1;
|
|
r54 = (await HTTP.get({
|
|
url: Endpoints.ORDER_GET(c25532_0),
|
|
rejectWithError: true
|
|
})).body || null;
|
|
c25532_4 = 0;
|
|
} catch ($e) {
|
|
const r28 = $e;
|
|
let r8 = r28;
|
|
c25532_3 = r28;
|
|
if (c25532_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r63 = c25532_3;
|
|
c25532_4 = 0;
|
|
c29547_1 = r63;
|
|
c3514_4.error("failed to fetch order", {
|
|
error: c29547_1,
|
|
orderId: c29547_0
|
|
});
|
|
captureBillingException(c29547_1, {
|
|
tags: {
|
|
source: "OrderActionCreators_getOrder"
|
|
},
|
|
extra: {
|
|
orderId: c29547_0
|
|
}
|
|
});
|
|
} catch (r59) {
|
|
r8 = r59;
|
|
c25532_3 = r59;
|
|
if (c25532_4 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r54;
|
|
}
|
|
export async function fetchOrderEntitlements(c25533_0) {
|
|
let r57;
|
|
let c25533_4 = 0;
|
|
let c29548_0;
|
|
try {
|
|
c29548_0 = void 0;
|
|
c25533_4 = 1;
|
|
c29548_0 = await HTTP.get({
|
|
url: Endpoints.ORDER_ENTITLEMENTS(c25533_0),
|
|
rejectWithError: false
|
|
});
|
|
r57 = c29548_0.body != null ? c29548_0.body : [];
|
|
c25533_4 = 0;
|
|
} catch ($e) {
|
|
let r8 = $e;
|
|
if (c25533_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c25533_4 = 0;
|
|
} catch ($e) {
|
|
r8 = $e;
|
|
if (c25533_4 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return [];
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r57;
|
|
}
|