@misiki/gocommerce-connector 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2025,12 +2025,31 @@ var OrderService = class extends BaseService {
2025
2025
  async listPublic(_args = {}) {
2026
2026
  return emptyPage();
2027
2027
  }
2028
- async getOrderByEmailAndOTP() {
2029
- throw new NotSupportedError(
2030
- "OrderService",
2031
- "getOrderByEmailAndOTP",
2032
- "the engine sends no one-time codes; a guest reads an order with its access token"
2028
+ /**
2029
+ * Sends a 4-digit code to the email or phone on the order, when `contact`
2030
+ * is that email or phone. The engine answers the same either way, so this
2031
+ * resolves whether or not anything was sent.
2032
+ */
2033
+ async requestOrderCode({ orderNo, contact }) {
2034
+ const res = await this.data(
2035
+ `/api/orders/${encodeURIComponent(orderNo.trim())}/code`,
2036
+ { method: "POST", body: { contact: contact.trim() } }
2037
+ );
2038
+ return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2039
+ }
2040
+ /**
2041
+ * Opens an order with the code `requestOrderCode` sent. The token it answers
2042
+ * is kept like an order placed in this browser, so the order page and
2043
+ * `getOrder` read it again without another code.
2044
+ */
2045
+ async getOrderByEmailAndOTP({ orderNo, otp }) {
2046
+ const number = orderNo.trim();
2047
+ const res = await this.data(
2048
+ `/api/orders/${encodeURIComponent(number)}/code/verify`,
2049
+ { method: "POST", body: { code: String(otp).trim() } }
2033
2050
  );
2051
+ rememberOrder({ number: res.order.number, token: res.access_token, cartId: "" });
2052
+ return { data: [toOrder(res.order)] };
2034
2053
  }
2035
2054
  };
2036
2055
  var clean2 = (v) => v && v !== "undefined" && v !== "null" ? v : void 0;