@ikas/storefront-api 4.0.0-alpha.38 → 4.0.0-alpha.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.
Files changed (61) hide show
  1. package/package.json +7 -7
  2. package/src/__api/models/Cart.ts +0 -2
  3. package/src/__api/models/CartStorefrontRoutingDynamicCurrencySettings.ts +0 -2
  4. package/src/__api/models/CartV2.ts +0 -2
  5. package/src/__api/models/CheckoutSettingsPrice.ts +0 -2
  6. package/src/__api/models/Country.ts +0 -4
  7. package/src/__api/models/CurrencyRate.ts +0 -4
  8. package/src/__api/models/OrderLineItem.ts +0 -2
  9. package/src/__api/models/OrderLineVariantPrice.ts +0 -2
  10. package/src/__api/models/ProductBackInStockRemind.ts +0 -2
  11. package/src/__api/models/ProductOptionSelectValueOtherPrice.ts +0 -2
  12. package/src/__api/models/ProductPrice.ts +0 -4
  13. package/src/__api/models/{StorefrontRaffle.ts → Raffle.ts} +16 -5
  14. package/src/__api/models/RafflePaginationResponse.ts +3 -5
  15. package/src/__api/models/RaffleParticipants.ts +10 -8
  16. package/src/__api/models/RaffleParticipantsInput.ts +4 -1
  17. package/src/__api/models/RaffleParticipantsUpdateInput.ts +24 -0
  18. package/src/__api/models/SearchProductPrice.ts +0 -4
  19. package/src/__api/models/StorefrontDynamicCurrencySettings.ts +0 -2
  20. package/src/__api/models/StorefrontOrder.ts +0 -2
  21. package/src/__api/models/StorefrontTransaction.ts +0 -2
  22. package/src/__api/models/_base.ts +1 -2
  23. package/src/__api/mutations/addCouponCodeToCheckout.ts +1 -5
  24. package/src/__api/mutations/addItemToCart.ts +1 -4
  25. package/src/__api/mutations/createOrderRefundRequest.ts +1 -4
  26. package/src/__api/mutations/saveCart.ts +1 -4
  27. package/src/__api/mutations/saveCartCouponCode.ts +1 -4
  28. package/src/__api/mutations/saveCheckout.ts +1 -5
  29. package/src/__api/mutations/saveItemToCart.ts +1 -5
  30. package/src/__api/mutations/saveProductBackInStockRemind.ts +1 -2
  31. package/src/__api/mutations/saveRaffleParticipant.ts +3 -25
  32. package/src/__api/mutations/updateCartCampaignOffer.ts +1 -4
  33. package/src/__api/mutations/updateRaffleParticipant.ts +72 -0
  34. package/src/__api/queries/getCart.ts +1 -5
  35. package/src/__api/queries/getCartById.ts +1 -4
  36. package/src/__api/queries/getCheckoutByCartId.ts +1 -5
  37. package/src/__api/queries/getCheckoutById.ts +1 -5
  38. package/src/__api/queries/getCurrencyRate.ts +1 -3
  39. package/src/__api/queries/getCustomerOrders.ts +1 -4
  40. package/src/__api/queries/getOrder.ts +1 -4
  41. package/src/__api/queries/getOrderByEmail.ts +1 -4
  42. package/src/__api/queries/getRaffleParticipants.ts +59 -0
  43. package/src/__api/queries/getRafflesByCustomerId.ts +74 -0
  44. package/src/__api/queries/getStorefront.ts +1 -2
  45. package/src/__api/queries/listCheckoutSettings.ts +1 -2
  46. package/src/__api/queries/listCountry.ts +1 -3
  47. package/src/__api/queries/listOrderTransactions.ts +1 -2
  48. package/src/__api/queries/listProduct.ts +1 -3
  49. package/src/__api/queries/listProductBackInStockRemind.ts +1 -2
  50. package/src/__api/queries/listProductOptionSet.ts +1 -3
  51. package/src/__api/queries/{listStorefrontRaffle.ts → listRaffle.ts} +10 -10
  52. package/src/__api/queries/searchProducts.ts +1 -3
  53. package/src/__api/types/index.ts +35 -43
  54. package/src/api/checkout/index.ts +1 -1
  55. package/src/api/customer/index.ts +0 -9
  56. package/src/api/file-upload/index.ts +29 -35
  57. package/src/api/masterpass/index.ts +7 -7
  58. package/src/api/product/index.ts +0 -1
  59. package/src/api/raffle/index.ts +14 -12
  60. package/src/index.ts +7 -9
  61. package/src/__api/queries/listRaffleParticipants.ts +0 -81
@@ -1,44 +1,38 @@
1
1
  import { IkasProductOption } from "@ikas/storefront-models";
2
- import { QueryParams as GetProductOptionFileUrlQueryParams } from "../../__api/queries/getProductOptionFileUrl";
3
- import { IkasProductOptionFileUrl } from "@ikas/storefront-models";
4
- import { APIResponse } from "@ikas/fe-api-client";
5
- import axios from "axios";
2
+ import { IkasStorefrontConfig } from "@ikas/storefront-config";
6
3
 
7
- export type { GetProductOptionFileUrlQueryParams };
8
-
9
- export async function getProductOptionFileUrl(
10
- params: GetProductOptionFileUrlQueryParams,
11
- file: File
4
+ export async function uploadProductOptionFile(
5
+ file: File,
6
+ option: IkasProductOption
12
7
  ) {
13
- const _getProductOptionFileUrl = (
14
- await import("../../__api/queries/getProductOptionFileUrl")
15
- ).default;
16
- const response = await _getProductOptionFileUrl(params);
17
- return new APIResponse(
18
- response.data
19
- ? {
20
- ...(response.data as unknown as IkasProductOptionFileUrl),
21
- file: file,
22
- }
23
- : null,
24
- response.graphQLErrors
25
- );
26
- }
27
-
28
- export async function uploadFile(params: IkasProductOptionFileUrl, file: File) {
29
- const config = {
8
+ const URL = `${IkasStorefrontConfig.getAdminApiUrl()}/upload-product-option-file`;
9
+ const response = await fetch(URL, {
10
+ method: "POST",
30
11
  headers: {
31
- "Content-Type": "multipart/form-data",
12
+ "x-api-key": IkasStorefrontConfig.getApiKey() || "",
13
+ "x-sfid": IkasStorefrontConfig.getStorefrontId() || "",
14
+ "x-sfrid": IkasStorefrontConfig.getStorefrontRoutingId() || "",
15
+ "Content-Type": "application/json",
16
+ Accept: "application/json",
32
17
  },
33
- };
34
- const data = new FormData();
35
- Object.entries(params.fields).forEach(([key, value]) => {
36
- //@ts-ignore
37
- data.append(key, value);
18
+ body: JSON.stringify({
19
+ base64: await getBase64(file),
20
+ fileName: file.name,
21
+ productOptionSetId: option.productOptionSetId,
22
+ productOptionId: option.id,
23
+ }),
38
24
  });
39
25
 
40
- data.append("file", file);
26
+ if (!response.ok) {
27
+ return null;
28
+ }
29
+ return await response.text();
30
+ }
41
31
 
42
- const res = await axios.post(params.url, data, config);
43
- return res.status === 200 || res.status === 204;
32
+ export function getBase64(file: File): Promise<string | null> {
33
+ return new Promise((resolve) => {
34
+ const reader = new FileReader();
35
+ reader.addEventListener("load", () => resolve(reader.result as string));
36
+ reader.readAsDataURL(file);
37
+ });
44
38
  }
@@ -1,12 +1,12 @@
1
- import { QueryParams as GetMasterPassRequestTokenQueryParams } from "../../__api/queries/getMasterPassRequestToken";
1
+ import { QueryParams as GetMasterpassRequestTokenQueryParams } from "../../__api/queries/getMasterpassRequestToken";
2
2
 
3
- export type { GetMasterPassRequestTokenQueryParams };
3
+ export type { GetMasterpassRequestTokenQueryParams };
4
4
 
5
- export async function getMasterPassRequestToken(
6
- data: GetMasterPassRequestTokenQueryParams
5
+ export async function getMasterpassRequestToken(
6
+ data: GetMasterpassRequestTokenQueryParams
7
7
  ) {
8
- const _getMasterPassRequestToken = (
9
- await import("../../__api/queries/getMasterPassRequestToken")
8
+ const _getMasterpassRequestToken = (
9
+ await import("../../__api/queries/getMasterpassRequestToken")
10
10
  ).default;
11
- return await _getMasterPassRequestToken(data);
11
+ return await _getMasterpassRequestToken(data);
12
12
  }
@@ -266,7 +266,6 @@ function simpleToProduct(simple: SearchProduct): IkasProduct {
266
266
  shortDescription: simple.shortDescription || "",
267
267
  productOptionSetId: simple.productOptionSetId,
268
268
  variantTypes: simple.productVariantTypes.map((pvt) => ({
269
- order: pvt.order,
270
269
  variantType: {
271
270
  id: pvt.variantType.id,
272
271
  name: pvt.variantType.name,
@@ -7,21 +7,21 @@ import {
7
7
  } from "@ikas/storefront-models";
8
8
  import { IkasStorefrontConfig } from "@ikas/storefront-config";
9
9
 
10
- import { QueryParams as ListStorefrontRaffleParams } from "../../__api/queries/listStorefrontRaffle";
10
+ import { QueryParams as ListRaffleQueryParams } from "../../__api/queries/listRaffle";
11
11
  import { QueryParams as SaveRaffleParticipantQueryParams } from "../../__api/mutations/saveRaffleParticipant";
12
12
  import { QueryParams as ListRaffleMetadataQueryParams } from "../../__api/queries/listRaffleMetadata";
13
+ import { QueryParams as GetRafflesByCustomerIdQueryParams } from "../../__api/queries/getRafflesByCustomerId";
13
14
 
14
15
  export type {
15
- ListStorefrontRaffleParams,
16
+ ListRaffleQueryParams,
16
17
  SaveRaffleParticipantQueryParams,
17
18
  ListRaffleMetadataQueryParams,
19
+ GetRafflesByCustomerIdQueryParams,
18
20
  };
19
21
 
20
- export async function listStorefrontRaffle(params: ListStorefrontRaffleParams) {
21
- const _listStorefrontRaffle = (
22
- await import("../../__api/queries/listStorefrontRaffle")
23
- ).default;
24
- const response = await _listStorefrontRaffle(params);
22
+ export async function listRaffle(params: ListRaffleQueryParams) {
23
+ const _listRaffle = (await import("../../__api/queries/listRaffle")).default;
24
+ const response = await _listRaffle(params);
25
25
  const data: IkasRaffle[] | undefined = response.data as any;
26
26
 
27
27
  data?.forEach((r) =>
@@ -45,7 +45,7 @@ export async function saveRaffleParticipant(
45
45
  ).default;
46
46
  const response = await _saveRaffleParticipant(params);
47
47
  return new APIResponse(
48
- response.data ? (response.data as unknown as IkasRaffleParticipant) : null,
48
+ response.data ? (response.data as IkasRaffleParticipant) : null,
49
49
  response.graphQLErrors
50
50
  );
51
51
  }
@@ -63,11 +63,13 @@ export async function listRaffleMetaData(
63
63
  );
64
64
  }
65
65
 
66
- export async function listRaffleParticipants() {
67
- const _listRaffleParticipants = (
68
- await import("../../__api/queries/listRaffleParticipants")
66
+ export async function getRafflesByCustomerId(
67
+ params: GetRafflesByCustomerIdQueryParams
68
+ ) {
69
+ const _getRafflesByCustomerId = (
70
+ await import("../../__api/queries/getRafflesByCustomerId")
69
71
  ).default;
70
- const response = await _listRaffleParticipants();
72
+ const response = await _getRafflesByCustomerId(params);
71
73
  const data: IkasRaffle[] | undefined = response.data as any;
72
74
 
73
75
  data?.forEach((r) =>
package/src/index.ts CHANGED
@@ -1,19 +1,12 @@
1
1
  import { APIErrorCode, Config } from "@ikas/fe-api-client";
2
2
  import { IkasStorefrontConfig } from "@ikas/storefront-config";
3
3
 
4
- IkasStorefrontConfig.addObserver({
5
- id: "ikas-storefront-api",
6
- callback: setAPIClientConfig,
7
- });
8
-
9
- export function setAPIClientConfig() {
4
+ const onConfigChange = () => {
10
5
  Config.URL = IkasStorefrontConfig.getApiUrl() || "";
11
6
  Config.HEADERS = {
12
7
  "x-api-key": IkasStorefrontConfig.getApiKey() || "",
13
8
  "x-sfid": IkasStorefrontConfig.getStorefrontId() || "",
14
9
  "x-sfrid": IkasStorefrontConfig.getStorefrontRoutingId() || "",
15
- "x-sid": IkasStorefrontConfig.getSessionId() || "",
16
- "x-vid": IkasStorefrontConfig.getVisitorId() || "",
17
10
  };
18
11
 
19
12
  if (IkasStorefrontConfig.getCustomerToken()) {
@@ -30,7 +23,12 @@ export function setAPIClientConfig() {
30
23
  ],
31
24
  };
32
25
  }
33
- }
26
+ };
27
+
28
+ IkasStorefrontConfig.addObserver({
29
+ id: "ikas-storefront-api",
30
+ callback: onConfigChange,
31
+ });
34
32
 
35
33
  export * from "./api/blog";
36
34
  export * from "./api/brand";
@@ -1,81 +0,0 @@
1
- import {
2
- fetchQuery,
3
- ConfigType,
4
- APIResponse,
5
- handleAPIError,
6
- } from "@ikas/fe-api-client";
7
- import { RaffleParticipants } from "../types";
8
-
9
- const listRaffleParticipants = async (
10
- fields?: string[],
11
- config?: ConfigType
12
- ) => {
13
- try {
14
- const { data, errors } = await fetchQuery({
15
- operationName: "listRaffleParticipants",
16
- config,
17
- allReturnFields,
18
- fields,
19
- query: (returnFields: string) => `
20
- query listRaffleParticipants {
21
- listRaffleParticipants ${returnFields}
22
- }
23
- `,
24
- });
25
-
26
- return new APIResponse<RaffleParticipants[]>(
27
- data?.listRaffleParticipants,
28
- errors
29
- );
30
- } catch (err) {
31
- return handleAPIError(err);
32
- }
33
- };
34
-
35
- export default listRaffleParticipants;
36
-
37
- const allReturnFields =
38
- "{applicationDate appliedProduct {productId variantId } createdAt customerId deleted email extraData firstName fullName id isDeliveredCargo lastName phone raffle {createdAt dateRange {end start } deleted id metadata {canonicals createdAt deleted description disableIndex id pageTitle slug targetId targetType updatedAt } name requiredCustomerAccount status updatedAt variants {productId variantId } verificationType } raffleId status updatedAt }";
39
-
40
- export enum ResponseField {
41
- APPLICATION_DATE = "applicationDate",
42
- APPLIED_PRODUCT__PRODUCT_ID = "appliedProduct.productId",
43
- APPLIED_PRODUCT__VARIANT_ID = "appliedProduct.variantId",
44
- CREATED_AT = "createdAt",
45
- CUSTOMER_ID = "customerId",
46
- DELETED = "deleted",
47
- EMAIL = "email",
48
- EXTRA_DATA = "extraData",
49
- FIRST_NAME = "firstName",
50
- FULL_NAME = "fullName",
51
- ID = "id",
52
- IS_DELIVERED_CARGO = "isDeliveredCargo",
53
- LAST_NAME = "lastName",
54
- PHONE = "phone",
55
- RAFFLE__CREATED_AT = "raffle.createdAt",
56
- RAFFLE__DATE_RANGE__END = "raffle.dateRange.end",
57
- RAFFLE__DATE_RANGE__START = "raffle.dateRange.start",
58
- RAFFLE__DELETED = "raffle.deleted",
59
- RAFFLE__ID = "raffle.id",
60
- RAFFLE__METADATA__CANONICALS = "raffle.metadata.canonicals",
61
- RAFFLE__METADATA__CREATED_AT = "raffle.metadata.createdAt",
62
- RAFFLE__METADATA__DELETED = "raffle.metadata.deleted",
63
- RAFFLE__METADATA__DESCRIPTION = "raffle.metadata.description",
64
- RAFFLE__METADATA__DISABLE_INDEX = "raffle.metadata.disableIndex",
65
- RAFFLE__METADATA__ID = "raffle.metadata.id",
66
- RAFFLE__METADATA__PAGE_TITLE = "raffle.metadata.pageTitle",
67
- RAFFLE__METADATA__SLUG = "raffle.metadata.slug",
68
- RAFFLE__METADATA__TARGET_ID = "raffle.metadata.targetId",
69
- RAFFLE__METADATA__TARGET_TYPE = "raffle.metadata.targetType",
70
- RAFFLE__METADATA__UPDATED_AT = "raffle.metadata.updatedAt",
71
- RAFFLE__NAME = "raffle.name",
72
- RAFFLE__REQUIRED_CUSTOMER_ACCOUNT = "raffle.requiredCustomerAccount",
73
- RAFFLE__STATUS = "raffle.status",
74
- RAFFLE__UPDATED_AT = "raffle.updatedAt",
75
- RAFFLE__VARIANTS__PRODUCT_ID = "raffle.variants.productId",
76
- RAFFLE__VARIANTS__VARIANT_ID = "raffle.variants.variantId",
77
- RAFFLE__VERIFICATION_TYPE = "raffle.verificationType",
78
- RAFFLE_ID = "raffleId",
79
- STATUS = "status",
80
- UPDATED_AT = "updatedAt",
81
- }