@misiki/gocommerce-connector 0.4.3 → 0.4.5

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.
@@ -4534,7 +4534,124 @@ declare class OrderService extends BaseService {
4534
4534
  noOfPage: number;
4535
4535
  page: number;
4536
4536
  }>;
4537
- getOrderByEmailAndOTP(): Promise<never>;
4537
+ /**
4538
+ * Sends a 4-digit code to the email or phone on the order, when `contact`
4539
+ * is that email or phone. The engine answers the same either way, so this
4540
+ * resolves whether or not anything was sent.
4541
+ */
4542
+ requestOrderCode({ orderNo, contact }: {
4543
+ orderNo: string;
4544
+ contact: string;
4545
+ }): Promise<{
4546
+ expiresInMinutes: number;
4547
+ }>;
4548
+ /**
4549
+ * Opens an order with the code `requestOrderCode` sent. The token it answers
4550
+ * is kept like an order placed in this browser, so the order page and
4551
+ * `getOrder` read it again without another code.
4552
+ */
4553
+ getOrderByEmailAndOTP({ orderNo, otp }: {
4554
+ orderNo: string;
4555
+ otp: string;
4556
+ email?: string;
4557
+ }): Promise<{
4558
+ data: {
4559
+ id: string;
4560
+ orderNo: string;
4561
+ orderNumber: string;
4562
+ number: string;
4563
+ parentOrderNo: string;
4564
+ status: string;
4565
+ engineStatus: string;
4566
+ paymentStatus: string;
4567
+ paymentMethod: string;
4568
+ currencyCode: string;
4569
+ subtotal: number;
4570
+ shippingCharges: number;
4571
+ discount: number;
4572
+ tax: number;
4573
+ taxIncluded: boolean;
4574
+ total: number;
4575
+ refunded: number;
4576
+ codCharges: number;
4577
+ coupon: {
4578
+ code: string;
4579
+ } | null;
4580
+ userEmail: string;
4581
+ email: string;
4582
+ phone: string | null;
4583
+ shippingAddress: {
4584
+ firstName: string;
4585
+ lastName: string;
4586
+ email: string | null;
4587
+ phone: string | null;
4588
+ address_1: string;
4589
+ address_2: string;
4590
+ city: string;
4591
+ state: string;
4592
+ zip: string;
4593
+ country: string;
4594
+ countryCode: string;
4595
+ } | null;
4596
+ billingAddress: {
4597
+ firstName: string;
4598
+ lastName: string;
4599
+ email: string | null;
4600
+ phone: string | null;
4601
+ address_1: string;
4602
+ address_2: string;
4603
+ city: string;
4604
+ state: string;
4605
+ zip: string;
4606
+ country: string;
4607
+ countryCode: string;
4608
+ } | null;
4609
+ shippingMethod: string | null;
4610
+ shippingRate: {
4611
+ name: string;
4612
+ } | null;
4613
+ lineItems: {
4614
+ id: string;
4615
+ productId: string;
4616
+ variantId: string;
4617
+ sku: string;
4618
+ title: string;
4619
+ name: string;
4620
+ slug: string;
4621
+ thumbnail: string | null;
4622
+ img: string | null;
4623
+ variantTitle: string;
4624
+ qty: number;
4625
+ shippedQty: number;
4626
+ price: number;
4627
+ mrp: number;
4628
+ subtotal: number;
4629
+ total: number;
4630
+ currencyCode: string;
4631
+ status: string;
4632
+ files: never[];
4633
+ usedOptions: never[];
4634
+ }[];
4635
+ fulfillments: {
4636
+ id: string;
4637
+ status: string;
4638
+ carrier: string;
4639
+ trackingNumber: string | null;
4640
+ trackingUrl: string | null;
4641
+ lineItems: {
4642
+ id: string;
4643
+ title: string;
4644
+ qty: number;
4645
+ }[];
4646
+ createdAt: string;
4647
+ }[];
4648
+ tracking: never[];
4649
+ orderHistory: never[];
4650
+ isReplaceOrReturn: boolean;
4651
+ createdAt: string;
4652
+ updatedAt: string;
4653
+ }[];
4654
+ }>;
4538
4655
  }
4539
4656
  declare const orderService: OrderService;
4540
4657
 
@@ -4784,15 +4901,35 @@ declare class UserService extends BaseService {
4784
4901
  deleteUser(): Promise<never>;
4785
4902
  checkEmail(): Promise<never>;
4786
4903
  joinAsVendor(): Promise<never>;
4787
- private signedIn;
4904
+ protected signedIn(auth: AuthResponse): Promise<{
4905
+ id: string;
4906
+ userId: string;
4907
+ email: string;
4908
+ phone: string | null;
4909
+ firstName: string;
4910
+ lastName: string;
4911
+ name: string;
4912
+ fullName: string;
4913
+ avatar: null;
4914
+ role: string;
4915
+ emailVerified: boolean;
4916
+ storeId: null;
4917
+ }>;
4788
4918
  /** An identity call, with a 404 from a build without the module said in words. */
4789
4919
  protected account<T>(path: string, req?: Parameters<BaseService['engine']>[1]): Promise<T>;
4790
4920
  }
4791
4921
  /**
4792
- * Password resets and email confirmation. Phone sign-in by one-time code is a
4793
- * Litekart flow; the engine has no such thing and says so.
4922
+ * Password resets, email confirmation, and phone sign-in. A store signs its
4923
+ * customers in one way (D116), read from `loginMethod`; the engine refuses
4924
+ * the other.
4794
4925
  */
4795
4926
  declare class AuthService extends UserService {
4927
+ private readonly facts;
4928
+ /**
4929
+ * How this store signs customers in: `email_password` or `phone_otp`.
4930
+ * A store whose accounts module says nothing signs in by email.
4931
+ */
4932
+ loginMethod(): Promise<'email_password' | 'phone_otp'>;
4796
4933
  forgotPassword({ email }: {
4797
4934
  email: string;
4798
4935
  referrer?: string;
@@ -4839,8 +4976,30 @@ declare class AuthService extends UserService {
4839
4976
  errorCode: string;
4840
4977
  message: string;
4841
4978
  }>;
4842
- getOtp(): Promise<never>;
4843
- verifyOtp(): Promise<never>;
4979
+ /** Texts a 4-digit sign-in code to `phone`, which needs its country code. */
4980
+ getOtp({ phone }: {
4981
+ phone: string;
4982
+ }): Promise<{
4983
+ expiresInMinutes: number;
4984
+ }>;
4985
+ /** Signs in the account on `phone` with the code it was sent, opening one the first time. */
4986
+ verifyOtp({ phone, otp }: {
4987
+ phone: string;
4988
+ otp: string;
4989
+ }): Promise<{
4990
+ id: string;
4991
+ userId: string;
4992
+ email: string;
4993
+ phone: string | null;
4994
+ firstName: string;
4995
+ lastName: string;
4996
+ name: string;
4997
+ fullName: string;
4998
+ avatar: null;
4999
+ role: string;
5000
+ emailVerified: boolean;
5001
+ storeId: null;
5002
+ }>;
4844
5003
  joinAsAdmin(): Promise<never>;
4845
5004
  }
4846
5005
  /** The `/my/profile` form: the same account, read and saved. */
@@ -4534,7 +4534,124 @@ declare class OrderService extends BaseService {
4534
4534
  noOfPage: number;
4535
4535
  page: number;
4536
4536
  }>;
4537
- getOrderByEmailAndOTP(): Promise<never>;
4537
+ /**
4538
+ * Sends a 4-digit code to the email or phone on the order, when `contact`
4539
+ * is that email or phone. The engine answers the same either way, so this
4540
+ * resolves whether or not anything was sent.
4541
+ */
4542
+ requestOrderCode({ orderNo, contact }: {
4543
+ orderNo: string;
4544
+ contact: string;
4545
+ }): Promise<{
4546
+ expiresInMinutes: number;
4547
+ }>;
4548
+ /**
4549
+ * Opens an order with the code `requestOrderCode` sent. The token it answers
4550
+ * is kept like an order placed in this browser, so the order page and
4551
+ * `getOrder` read it again without another code.
4552
+ */
4553
+ getOrderByEmailAndOTP({ orderNo, otp }: {
4554
+ orderNo: string;
4555
+ otp: string;
4556
+ email?: string;
4557
+ }): Promise<{
4558
+ data: {
4559
+ id: string;
4560
+ orderNo: string;
4561
+ orderNumber: string;
4562
+ number: string;
4563
+ parentOrderNo: string;
4564
+ status: string;
4565
+ engineStatus: string;
4566
+ paymentStatus: string;
4567
+ paymentMethod: string;
4568
+ currencyCode: string;
4569
+ subtotal: number;
4570
+ shippingCharges: number;
4571
+ discount: number;
4572
+ tax: number;
4573
+ taxIncluded: boolean;
4574
+ total: number;
4575
+ refunded: number;
4576
+ codCharges: number;
4577
+ coupon: {
4578
+ code: string;
4579
+ } | null;
4580
+ userEmail: string;
4581
+ email: string;
4582
+ phone: string | null;
4583
+ shippingAddress: {
4584
+ firstName: string;
4585
+ lastName: string;
4586
+ email: string | null;
4587
+ phone: string | null;
4588
+ address_1: string;
4589
+ address_2: string;
4590
+ city: string;
4591
+ state: string;
4592
+ zip: string;
4593
+ country: string;
4594
+ countryCode: string;
4595
+ } | null;
4596
+ billingAddress: {
4597
+ firstName: string;
4598
+ lastName: string;
4599
+ email: string | null;
4600
+ phone: string | null;
4601
+ address_1: string;
4602
+ address_2: string;
4603
+ city: string;
4604
+ state: string;
4605
+ zip: string;
4606
+ country: string;
4607
+ countryCode: string;
4608
+ } | null;
4609
+ shippingMethod: string | null;
4610
+ shippingRate: {
4611
+ name: string;
4612
+ } | null;
4613
+ lineItems: {
4614
+ id: string;
4615
+ productId: string;
4616
+ variantId: string;
4617
+ sku: string;
4618
+ title: string;
4619
+ name: string;
4620
+ slug: string;
4621
+ thumbnail: string | null;
4622
+ img: string | null;
4623
+ variantTitle: string;
4624
+ qty: number;
4625
+ shippedQty: number;
4626
+ price: number;
4627
+ mrp: number;
4628
+ subtotal: number;
4629
+ total: number;
4630
+ currencyCode: string;
4631
+ status: string;
4632
+ files: never[];
4633
+ usedOptions: never[];
4634
+ }[];
4635
+ fulfillments: {
4636
+ id: string;
4637
+ status: string;
4638
+ carrier: string;
4639
+ trackingNumber: string | null;
4640
+ trackingUrl: string | null;
4641
+ lineItems: {
4642
+ id: string;
4643
+ title: string;
4644
+ qty: number;
4645
+ }[];
4646
+ createdAt: string;
4647
+ }[];
4648
+ tracking: never[];
4649
+ orderHistory: never[];
4650
+ isReplaceOrReturn: boolean;
4651
+ createdAt: string;
4652
+ updatedAt: string;
4653
+ }[];
4654
+ }>;
4538
4655
  }
4539
4656
  declare const orderService: OrderService;
4540
4657
 
@@ -4784,15 +4901,35 @@ declare class UserService extends BaseService {
4784
4901
  deleteUser(): Promise<never>;
4785
4902
  checkEmail(): Promise<never>;
4786
4903
  joinAsVendor(): Promise<never>;
4787
- private signedIn;
4904
+ protected signedIn(auth: AuthResponse): Promise<{
4905
+ id: string;
4906
+ userId: string;
4907
+ email: string;
4908
+ phone: string | null;
4909
+ firstName: string;
4910
+ lastName: string;
4911
+ name: string;
4912
+ fullName: string;
4913
+ avatar: null;
4914
+ role: string;
4915
+ emailVerified: boolean;
4916
+ storeId: null;
4917
+ }>;
4788
4918
  /** An identity call, with a 404 from a build without the module said in words. */
4789
4919
  protected account<T>(path: string, req?: Parameters<BaseService['engine']>[1]): Promise<T>;
4790
4920
  }
4791
4921
  /**
4792
- * Password resets and email confirmation. Phone sign-in by one-time code is a
4793
- * Litekart flow; the engine has no such thing and says so.
4922
+ * Password resets, email confirmation, and phone sign-in. A store signs its
4923
+ * customers in one way (D116), read from `loginMethod`; the engine refuses
4924
+ * the other.
4794
4925
  */
4795
4926
  declare class AuthService extends UserService {
4927
+ private readonly facts;
4928
+ /**
4929
+ * How this store signs customers in: `email_password` or `phone_otp`.
4930
+ * A store whose accounts module says nothing signs in by email.
4931
+ */
4932
+ loginMethod(): Promise<'email_password' | 'phone_otp'>;
4796
4933
  forgotPassword({ email }: {
4797
4934
  email: string;
4798
4935
  referrer?: string;
@@ -4839,8 +4976,30 @@ declare class AuthService extends UserService {
4839
4976
  errorCode: string;
4840
4977
  message: string;
4841
4978
  }>;
4842
- getOtp(): Promise<never>;
4843
- verifyOtp(): Promise<never>;
4979
+ /** Texts a 4-digit sign-in code to `phone`, which needs its country code. */
4980
+ getOtp({ phone }: {
4981
+ phone: string;
4982
+ }): Promise<{
4983
+ expiresInMinutes: number;
4984
+ }>;
4985
+ /** Signs in the account on `phone` with the code it was sent, opening one the first time. */
4986
+ verifyOtp({ phone, otp }: {
4987
+ phone: string;
4988
+ otp: string;
4989
+ }): Promise<{
4990
+ id: string;
4991
+ userId: string;
4992
+ email: string;
4993
+ phone: string | null;
4994
+ firstName: string;
4995
+ lastName: string;
4996
+ name: string;
4997
+ fullName: string;
4998
+ avatar: null;
4999
+ role: string;
5000
+ emailVerified: boolean;
5001
+ storeId: null;
5002
+ }>;
4844
5003
  joinAsAdmin(): Promise<never>;
4845
5004
  }
4846
5005
  /** The `/my/profile` form: the same account, read and saved. */
package/dist/index.cjs CHANGED
@@ -2044,12 +2044,31 @@ var OrderService = class extends BaseService {
2044
2044
  async listPublic(_args = {}) {
2045
2045
  return emptyPage();
2046
2046
  }
2047
- async getOrderByEmailAndOTP() {
2048
- throw new NotSupportedError(
2049
- "OrderService",
2050
- "getOrderByEmailAndOTP",
2051
- "the engine sends no one-time codes; a guest reads an order with its access token"
2047
+ /**
2048
+ * Sends a 4-digit code to the email or phone on the order, when `contact`
2049
+ * is that email or phone. The engine answers the same either way, so this
2050
+ * resolves whether or not anything was sent.
2051
+ */
2052
+ async requestOrderCode({ orderNo, contact }) {
2053
+ const res = await this.data(
2054
+ `/api/orders/${encodeURIComponent(orderNo.trim())}/code`,
2055
+ { method: "POST", body: { contact: contact.trim() } }
2056
+ );
2057
+ return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2058
+ }
2059
+ /**
2060
+ * Opens an order with the code `requestOrderCode` sent. The token it answers
2061
+ * is kept like an order placed in this browser, so the order page and
2062
+ * `getOrder` read it again without another code.
2063
+ */
2064
+ async getOrderByEmailAndOTP({ orderNo, otp }) {
2065
+ const number = orderNo.trim();
2066
+ const res = await this.data(
2067
+ `/api/orders/${encodeURIComponent(number)}/code/verify`,
2068
+ { method: "POST", body: { code: String(otp).trim() } }
2052
2069
  );
2070
+ rememberOrder({ number: res.order.number, token: res.access_token, cartId: "" });
2071
+ return { data: [toOrder(res.order)] };
2053
2072
  }
2054
2073
  };
2055
2074
  var clean2 = (v) => v && v !== "undefined" && v !== "null" ? v : void 0;
@@ -2186,6 +2205,19 @@ var UserService = class extends BaseService {
2186
2205
  }
2187
2206
  };
2188
2207
  var AuthService = class extends UserService {
2208
+ facts = new StoreFacts(this._fetch);
2209
+ /**
2210
+ * How this store signs customers in: `email_password` or `phone_otp`.
2211
+ * A store whose accounts module says nothing signs in by email.
2212
+ */
2213
+ async loginMethod() {
2214
+ try {
2215
+ const method = (await this.facts.plugins()).get("identity")?.settings?.login_method;
2216
+ return method === "phone_otp" ? "phone_otp" : "email_password";
2217
+ } catch {
2218
+ return "email_password";
2219
+ }
2220
+ }
2189
2221
  async forgotPassword({ email }) {
2190
2222
  return this.account("/x/identity/password-reset", {
2191
2223
  method: "POST",
@@ -2212,11 +2244,21 @@ var AuthService = class extends UserService {
2212
2244
  return { errorCode: err.code ?? "invalid_token", message: err.message };
2213
2245
  }
2214
2246
  }
2215
- async getOtp() {
2216
- throw new NotSupportedError("AuthService", "getOtp", "sign in with an email and password");
2247
+ /** Texts a 4-digit sign-in code to `phone`, which needs its country code. */
2248
+ async getOtp({ phone }) {
2249
+ const res = await this.account("/x/identity/otp", {
2250
+ method: "POST",
2251
+ body: { phone: String(phone ?? "").trim() }
2252
+ });
2253
+ return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2217
2254
  }
2218
- async verifyOtp() {
2219
- throw new NotSupportedError("AuthService", "verifyOtp", "sign in with an email and password");
2255
+ /** Signs in the account on `phone` with the code it was sent, opening one the first time. */
2256
+ async verifyOtp({ phone, otp }) {
2257
+ const auth = await this.account("/x/identity/otp/verify", {
2258
+ method: "POST",
2259
+ body: { phone: String(phone ?? "").trim(), code: String(otp ?? "").trim() }
2260
+ });
2261
+ return this.signedIn(auth);
2220
2262
  }
2221
2263
  async joinAsAdmin() {
2222
2264
  throw new NotSupportedError("AuthService", "joinAsAdmin", "operators are invited from the admin panel");
@@ -2568,7 +2610,11 @@ var StoreService = class extends BaseService {
2568
2610
  ...flag(plugins.has("product-reviews"))
2569
2611
  }
2570
2612
  },
2571
- ...menus?.length ? { menu: menus } : {}
2613
+ ...menus?.length ? { menu: menus } : {},
2614
+ // The one way this store signs customers in (D116), which the sign-in
2615
+ // form reads as PHONE or EMAIL. Without the accounts module the static
2616
+ // record says.
2617
+ ...plugins.has("identity") ? { loginType: plugins.get("identity")?.settings?.login_method === "phone_otp" ? "PHONE" : "EMAIL" } : {}
2572
2618
  };
2573
2619
  }
2574
2620
  };