commerce-kit 0.66.0 → 0.67.0

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.
package/README.md CHANGED
@@ -115,13 +115,46 @@ const cart = await commerce.cartUpsert({
115
115
  // Get cart
116
116
  const cart = await commerce.cartGet({ cartId: 'cart_123' });
117
117
 
118
- // Remove item from cart
118
+ // Remove item from cart (pass lineItemId to remove one personalised line of the variant)
119
119
  await commerce.cartRemoveItem({
120
120
  cartId: 'cart_123',
121
121
  variantId: 'variant_456',
122
122
  });
123
123
  ```
124
124
 
125
+ ### Personalised lines and shopper uploads
126
+
127
+ A line can carry `properties`: text (an engraving) or an uploaded file (a photo for a portrait).
128
+ The same variant with different properties becomes its own line.
129
+
130
+ ```typescript
131
+ await commerce.cartUpsert({
132
+ variantId: 'variant_456',
133
+ quantity: 1,
134
+ properties: [{ key: 'engraving', label: 'Engraving', type: 'text', value: 'For Ana' }],
135
+ });
136
+ ```
137
+
138
+ Files are uploaded from the browser with `commerce-kit/uploads` (needs the store's Customer Uploads
139
+ module). The platform endpoint is reached through the storefront's own `/checkout/api/**` proxy, so no
140
+ route or API key is needed in the storefront. Images (JPEG, PNG, WebP, GIF, HEIC, AVIF, TIFF) and PDF,
141
+ up to 20 MB, stored privately.
142
+
143
+ ```typescript
144
+ 'use client';
145
+ import { ACCEPTED_LINE_ITEM_UPLOAD_TYPES, lineItemFileProperty, uploadLineItemFile } from 'commerce-kit/uploads';
146
+
147
+ // <input type="file" accept={ACCEPTED_LINE_ITEM_UPLOAD_TYPES} onChange={...} />
148
+ const { uploadId } = await uploadLineItemFile(file, { variantId });
149
+ // then, on the server (server action):
150
+ await commerce.cartUpsert({
151
+ cartId,
152
+ variantId,
153
+ quantity: 1,
154
+ properties: [lineItemFileProperty({ key: 'photo', label: 'Photo', uploadId })],
155
+ });
156
+ ```
157
+
125
158
  ## Orders
126
159
 
127
160
  ```typescript
@@ -4635,6 +4635,12 @@ type APICartGetResult = {
4635
4635
  name: string;
4636
4636
  email: string | null;
4637
4637
  }[] | null;
4638
+ properties: {
4639
+ key: string;
4640
+ type: "text" | "file";
4641
+ value: string;
4642
+ label?: string | undefined;
4643
+ }[] | null;
4638
4644
  subscriptionPlan: {
4639
4645
  interval: number;
4640
4646
  id: string;
@@ -5419,6 +5425,12 @@ type APICartCreateBody = {
5419
5425
  groupId: string;
5420
5426
  quantity: number;
5421
5427
  }[] | undefined;
5428
+ properties?: {
5429
+ key: string;
5430
+ type: "text" | "file";
5431
+ value: string;
5432
+ label?: string | undefined;
5433
+ }[] | undefined;
5422
5434
  };
5423
5435
  type APICartCreateResult = {
5424
5436
  id: string;
@@ -5876,6 +5888,12 @@ type APICartCreateResult = {
5876
5888
  name: string;
5877
5889
  email: string | null;
5878
5890
  }[] | null;
5891
+ properties: {
5892
+ key: string;
5893
+ type: "text" | "file";
5894
+ value: string;
5895
+ label?: string | undefined;
5896
+ }[] | null;
5879
5897
  subscriptionPlan: {
5880
5898
  interval: number;
5881
5899
  id: string;
@@ -7101,6 +7119,12 @@ type APICartRemoveItemResult = {
7101
7119
  name: string;
7102
7120
  email: string | null;
7103
7121
  }[] | null;
7122
+ properties: {
7123
+ key: string;
7124
+ type: "text" | "file";
7125
+ value: string;
7126
+ label?: string | undefined;
7127
+ }[] | null;
7104
7128
  subscriptionPlan: {
7105
7129
  interval: number;
7106
7130
  id: string;
@@ -7872,6 +7896,7 @@ type APICartRemoveItemResult = {
7872
7896
  } | null | undefined;
7873
7897
  type APICartRemoveItemQueryParams = {
7874
7898
  subscriptionPlanId?: string | undefined;
7899
+ lineItemId?: string | undefined;
7875
7900
  };
7876
7901
  type APICartCouponApplyBody = {
7877
7902
  code: string;
@@ -8332,6 +8357,12 @@ type APICartCouponApplyResult = {
8332
8357
  name: string;
8333
8358
  email: string | null;
8334
8359
  }[] | null;
8360
+ properties: {
8361
+ key: string;
8362
+ type: "text" | "file";
8363
+ value: string;
8364
+ label?: string | undefined;
8365
+ }[] | null;
8335
8366
  subscriptionPlan: {
8336
8367
  interval: number;
8337
8368
  id: string;
@@ -9365,6 +9396,7 @@ type APIOrdersBrowseResult = Omit<{
9365
9396
  carrier: "gls";
9366
9397
  name: string;
9367
9398
  service: "gls";
9399
+ defaultServices?: ("s10" | "s12" | "sat")[] | undefined;
9368
9400
  } | null;
9369
9401
  deliverySlots: unknown;
9370
9402
  shippingTaxRate: {
@@ -9654,6 +9686,12 @@ type APIOrdersBrowseResult = Omit<{
9654
9686
  dietary: string | null;
9655
9687
  notes: string | null;
9656
9688
  }[] | null;
9689
+ properties: {
9690
+ key: string;
9691
+ type: "text" | "file";
9692
+ value: string;
9693
+ label?: string | undefined;
9694
+ }[] | null;
9657
9695
  setSelections: {
9658
9696
  id: string;
9659
9697
  lineItemId: string;
@@ -10022,6 +10060,7 @@ type APIOrdersBrowseResult = Omit<{
10022
10060
  carrier: "gls";
10023
10061
  name: string;
10024
10062
  service: "gls";
10063
+ defaultServices?: ("s10" | "s12" | "sat")[] | undefined;
10025
10064
  } | null;
10026
10065
  deliverySlots: unknown;
10027
10066
  shippingTaxRate: {
@@ -10311,6 +10350,12 @@ type APIOrdersBrowseResult = Omit<{
10311
10350
  dietary: string | null;
10312
10351
  notes: string | null;
10313
10352
  }[] | null;
10353
+ properties: {
10354
+ key: string;
10355
+ type: "text" | "file";
10356
+ value: string;
10357
+ label?: string | undefined;
10358
+ }[] | null;
10314
10359
  setSelections: {
10315
10360
  id: string;
10316
10361
  lineItemId: string;
@@ -10619,6 +10664,7 @@ type APIOrdersBrowseResult = Omit<{
10619
10664
  carrier: "gls";
10620
10665
  name: string;
10621
10666
  service: "gls";
10667
+ defaultServices?: ("s10" | "s12" | "sat")[] | undefined;
10622
10668
  } | null;
10623
10669
  deliverySlots: unknown;
10624
10670
  shippingTaxRate: {
@@ -10908,6 +10954,12 @@ type APIOrdersBrowseResult = Omit<{
10908
10954
  dietary: string | null;
10909
10955
  notes: string | null;
10910
10956
  }[] | null;
10957
+ properties: {
10958
+ key: string;
10959
+ type: "text" | "file";
10960
+ value: string;
10961
+ label?: string | undefined;
10962
+ }[] | null;
10911
10963
  setSelections: {
10912
10964
  id: string;
10913
10965
  lineItemId: string;
@@ -11276,6 +11328,7 @@ type APIOrdersBrowseResult = Omit<{
11276
11328
  carrier: "gls";
11277
11329
  name: string;
11278
11330
  service: "gls";
11331
+ defaultServices?: ("s10" | "s12" | "sat")[] | undefined;
11279
11332
  } | null;
11280
11333
  deliverySlots: unknown;
11281
11334
  shippingTaxRate: {
@@ -11565,6 +11618,12 @@ type APIOrdersBrowseResult = Omit<{
11565
11618
  dietary: string | null;
11566
11619
  notes: string | null;
11567
11620
  }[] | null;
11621
+ properties: {
11622
+ key: string;
11623
+ type: "text" | "file";
11624
+ value: string;
11625
+ label?: string | undefined;
11626
+ }[] | null;
11568
11627
  setSelections: {
11569
11628
  id: string;
11570
11629
  lineItemId: string;
@@ -11865,6 +11924,7 @@ type APIOrdersBrowseResult = Omit<{
11865
11924
  carrier: "gls";
11866
11925
  name: string;
11867
11926
  service: "gls";
11927
+ defaultServices?: ("s10" | "s12" | "sat")[] | undefined;
11868
11928
  } | null;
11869
11929
  deliverySlots: unknown;
11870
11930
  shippingTaxRate: {
@@ -12819,6 +12879,12 @@ type APIOrdersBrowseResult = Omit<{
12819
12879
  dietary: string | null;
12820
12880
  notes: string | null;
12821
12881
  }[] | null;
12882
+ properties: {
12883
+ key: string;
12884
+ type: "text" | "file";
12885
+ value: string;
12886
+ label?: string | undefined;
12887
+ }[] | null;
12822
12888
  setSelections: {
12823
12889
  id: string;
12824
12890
  lineItemId: string;
@@ -13085,6 +13151,7 @@ type APIOrdersBrowseResult = Omit<{
13085
13151
  type APIOrdersBrowseQueryParams = {
13086
13152
  offset?: number | undefined;
13087
13153
  limit?: number | undefined;
13154
+ source?: "counter" | "admin" | "storefront" | "baselinker" | "allegro" | "inpost-buy" | "wholesale" | undefined;
13088
13155
  };
13089
13156
  type APIOrderGetByIdResult = Omit<{
13090
13157
  id: string;
@@ -13151,6 +13218,7 @@ type APIOrderGetByIdResult = Omit<{
13151
13218
  carrier: "gls";
13152
13219
  name: string;
13153
13220
  service: "gls";
13221
+ defaultServices?: ("s10" | "s12" | "sat")[] | undefined;
13154
13222
  } | null;
13155
13223
  deliverySlots: unknown;
13156
13224
  shippingTaxRate: {
@@ -13440,6 +13508,12 @@ type APIOrderGetByIdResult = Omit<{
13440
13508
  dietary: string | null;
13441
13509
  notes: string | null;
13442
13510
  }[] | null;
13511
+ properties: {
13512
+ key: string;
13513
+ type: "text" | "file";
13514
+ value: string;
13515
+ label?: string | undefined;
13516
+ }[] | null;
13443
13517
  setSelections: {
13444
13518
  id: string;
13445
13519
  lineItemId: string;
@@ -13818,6 +13892,7 @@ type APIOrderGetByIdResult = Omit<{
13818
13892
  carrier: "gls";
13819
13893
  name: string;
13820
13894
  service: "gls";
13895
+ defaultServices?: ("s10" | "s12" | "sat")[] | undefined;
13821
13896
  } | null;
13822
13897
  deliverySlots: unknown;
13823
13898
  shippingTaxRate: {
@@ -14107,6 +14182,12 @@ type APIOrderGetByIdResult = Omit<{
14107
14182
  dietary: string | null;
14108
14183
  notes: string | null;
14109
14184
  }[] | null;
14185
+ properties: {
14186
+ key: string;
14187
+ type: "text" | "file";
14188
+ value: string;
14189
+ label?: string | undefined;
14190
+ }[] | null;
14110
14191
  setSelections: {
14111
14192
  id: string;
14112
14193
  lineItemId: string;
@@ -14403,6 +14484,7 @@ type APIOrderGetByIdResult = Omit<{
14403
14484
  carrier: "gls";
14404
14485
  name: string;
14405
14486
  service: "gls";
14487
+ defaultServices?: ("s10" | "s12" | "sat")[] | undefined;
14406
14488
  } | null;
14407
14489
  deliverySlots: unknown;
14408
14490
  shippingTaxRate: {
@@ -15357,6 +15439,12 @@ type APIOrderGetByIdResult = Omit<{
15357
15439
  dietary: string | null;
15358
15440
  notes: string | null;
15359
15441
  }[] | null;
15442
+ properties: {
15443
+ key: string;
15444
+ type: "text" | "file";
15445
+ value: string;
15446
+ label?: string | undefined;
15447
+ }[] | null;
15360
15448
  setSelections: {
15361
15449
  id: string;
15362
15450
  lineItemId: string;
@@ -16209,6 +16297,7 @@ type APIMeStore = {
16209
16297
  serialNumbers: boolean;
16210
16298
  wholesale: boolean;
16211
16299
  stockPricing: boolean;
16300
+ lineItemUploads: boolean;
16212
16301
  } | null;
16213
16302
  defaultLanguage: "en-US" | "fr-FR" | "it-IT" | "vi-VN" | "pl-PL" | "es-ES" | "de-DE" | null | undefined;
16214
16303
  enabledLanguages: {
package/dist/index.d.ts CHANGED
@@ -78,9 +78,15 @@ declare class YNSProvider {
78
78
  cartId?: string;
79
79
  currency?: string;
80
80
  }): Promise<APICartCreateResult>;
81
+ /**
82
+ * Remove a variant from the cart. A variant can sit on several lines when they carry different
83
+ * `properties` (personalisation); pass `lineItemId` to remove just that one line, otherwise all
84
+ * of the variant's one-time lines go.
85
+ */
81
86
  cartRemoveItem(params: {
82
87
  cartId: string;
83
88
  variantId: string;
89
+ lineItemId?: string;
84
90
  }): Promise<APICartGetResult>;
85
91
  cartGet(params: {
86
92
  cartId: string;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import"./chunk-PNKB6P4V.js";var C=process.env.YNS_API_KEY,B=process.env.YNS_STORE_ID,I={YNS_API_KEY:C,YNS_STORE_ID:B};var h=new Set(["/products","/collections","/categories","/brands"]),w=new Set(["/products/filters","/legal-pages"]),S=new Set(["products","collections","categories","brands","legal-pages"]),v=new Set(["batch","import","import-memberships","filters"]),$=(P,e)=>{if(w.has(P))return!0;if(h.has(P))return e.get("active")==="true";let[t,s,r,...o]=P.split("/").slice(1);return!t||!s||o.length>0||v.has(s)?!1:r===void 0?S.has(t):t==="products"&&r==="reviews"},p=(P,e)=>{let[t="",s=""]=P.split("?"),r=new URLSearchParams(s),o=r.get("active"),n=r.get("metafields")==="all";if(r.has("store")||o!==null&&o!=="true"||n||!$(t,r))return null;let u=[...r.entries()].sort(([i,f],[y,R])=>i===y?f.localeCompare(R):i.localeCompare(y)),a=new URLSearchParams([["store",e],...u]);return`/${t.slice(1)}?${a}`};var l={DEBUG:0,LOG:1,WARN:2,ERROR:3},T=process.env.NEXT_PUBLIC_LOG_LEVEL||"LOG",c=l[T],A="\x1B[0m",G="\x1B[34m",E="\x1B[32m",D="\x1B[33m",U="\x1B[31m",O="\u23F1\uFE0F",L="\u{1F41B}",M="\u2714\uFE0F",b="\u26A0\uFE0F",k="\u274C",g=`${O} `,q=`${G}${L}${A} `,Q=`${E}${M}${A} `,N=`${D}${b}${A} `,Y=`${U}${k}${A} `,m=P=>{let e=P?`[${P}] `:"";return{getLogger(t){return m([P,t].filter(Boolean).join(" > "))},time(t){c>l.DEBUG||console.time([g,e,t].filter(Boolean).join(" "))},timeEnd(t){c>l.DEBUG||console.timeEnd([g,e,t].filter(Boolean).join(" "))},debug(...t){c>l.DEBUG||console.log(...[q,e,...t].filter(Boolean))},log(...t){c>l.LOG||console.log(...[Q,e,...t].filter(Boolean))},dir(t,s){c>l.LOG||console.dir(t,s)},warn(...t){c>l.WARN||console.warn(...[N,e,...t].filter(Boolean))},error(...t){c>l.ERROR||console.error(...[Y,e,...t].filter(Boolean))}}},j=m();var _=new Set([400,401,403]),d=class{#t;#s=m("YNSProvider");#n=null;constructor(e={}){let t=e.token??I.YNS_API_KEY,s=I.YNS_API_KEY?.startsWith("sk-s-");if(!t)throw new Error("YNS API key is required. Set YNS_API_KEY environment variable or pass token in config.");let r=e.endpoint??(s?"https://yns.cx":"https://yns.store");this.#t={version:"v1",...e,token:t,endpoint:r},this.#s.debug("YNSProvider initialized",{endpoint:r,token:e.token?"from config":"from env"})}async#e(e,t="GET",s){let r=await this.#a(e,t,s);return this.#i(r,e,t)}async#r(e){let t=await this.#a(e,"GET");return t.status===404?null:this.#i(t,e,"GET")}#P(){let e=this.#t.store;return e===!1?Promise.resolve(null):(this.#n??=(async()=>{let t=e??I.YNS_STORE_ID;if(t)return t;try{let s=await this.#o("/me","GET");if(!s.ok)return null;let r=await s.json();return typeof r.store?.id=="string"?r.store.id:null}catch{return null}})(),this.#n)}async#a(e,t,s){if(t!=="GET")return this.#o(e,t,s);let r=await this.#P(),o=r?p(e,r):null;if(!o)return this.#o(e,t);let n=this.#s.getLogger("#restRequest"),u=`${this.#t.endpoint}/api/${this.#t.version}${o}`;n.debug(`Making keyless GET request to YNS API: ${u}`);let a=await fetch(u,{method:t,headers:{"Content-Type":"application/json"}});return _.has(a.status)?(a.status!==400&&(this.#n=Promise.resolve(null)),n.debug(`Keyless request answered ${a.status}, asking again with the key`),this.#o(e,t)):a}async#o(e,t,s){let r=this.#s.getLogger("#restRequest"),o=`${this.#t.endpoint}/api/${this.#t.version}${e}`;return r.debug(`Making ${t} request to YNS API: ${o}`),fetch(o,{method:t,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.#t.token}`},body:s?JSON.stringify(s):void 0})}async#i(e,t,s){let r=this.#s.getLogger("#restRequest"),o=`${this.#t.endpoint}/api/${this.#t.version}${t}`;if(!e.ok){let u=e.headers.get("content-type"),a=`YNS REST request failed: ${s} ${o} ${e.status} ${e.statusText}`;if(u?.includes("application/json"))try{let i=await e.json();a=i.error||i.message||a}catch(i){r.error("Failed to parse YNS error response as JSON",i)}else{let i=await e.text();r.error(`YNS API request failed: ${e.status} ${e.statusText}`,a,i)}throw new Error(a)}let n=e.headers.get("content-type");if(!n?.includes("application/json"))throw new Error(`YNS API returned ${n} instead of JSON for ${t}`);return e.json()}async#u(e,t){let s=this.#s.getLogger("#multipartRequest"),r=`${this.#t.endpoint}/api/${this.#t.version}${e}`;s.debug(`Making multipart POST to YNS API: ${r}`);let o=await fetch(r,{method:"POST",headers:{Authorization:`Bearer ${this.#t.token}`},body:t});if(!o.ok){let u=o.headers.get("content-type"),a=`YNS REST request failed: POST ${r} ${o.status} ${o.statusText}`;if(u?.includes("application/json"))try{let i=await o.json();a=i.error||i.message||a}catch(i){s.error("Failed to parse YNS error response as JSON",i)}else{let i=await o.text();s.error(`YNS API request failed: ${o.status} ${o.statusText}`,a,i)}throw new Error(a)}let n=o.headers.get("content-type");if(!n?.includes("application/json"))throw new Error(`YNS API returned ${n} instead of JSON for ${e}`);return o.json()}async meGet(){let e=this.#s.getLogger("meGet");e.debug("Fetching my information");let s=await this.#e("/me");return e.debug("Received my information:",s),s}async socialsGet(){let e=this.#s.getLogger("socialsGet");e.debug("Fetching store social links");let s=await this.#e("/socials");return e.debug("Received store social links:",s),s}async brandBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString()),e.lang&&t.append("lang",e.lang);let r=`/brands${t.size?`?${t}`:""}`;return this.#e(r)}async brandGet(e){let t=`/brands/${e.idOrSlug}`;return this.#e(t)}async brandCreate(e){return this.#e("/brands","POST",e)}async brandUpdate(e,t){let s=`/brands/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async brandDelete(e){let t=`/brands/${e.idOrSlug}`;return this.#e(t,"DELETE")}async brandAssignProducts(e,t){let s=`/brands/${e.idOrSlug}/products`;return this.#e(s,"POST",t)}async orderRefundsBrowse(e){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString());let s=t.size?`?${t}`:"",r=`/orders/${e.id}/refunds${s}`;return this.#e(r)}async orderRefundGet(e){let t=`/orders/${e.id}/refunds/${e.refundId}`;return this.#e(t)}async productBatch(e){return this.#e("/products/batch","POST",e)}async cartDelete(e){let t=`/carts/${e.cartId}`;return this.#e(t,"DELETE")}async productBrowse(e){let t=this.#s.getLogger("productBrowse");t.debug("Browsing products with params:",e);let s=new URLSearchParams;e.limit&&s.append("limit",e.limit.toString()),e.offset&&s.append("offset",e.offset.toString()),e.category&&s.append("category",e.category),e.collection&&s.append("collection",e.collection),e.brand&&s.append("brand",e.brand),e.priceMin!==void 0&&s.append("priceMin",e.priceMin.toString()),e.priceMax!==void 0&&s.append("priceMax",e.priceMax.toString()),e.vts&&s.append("vts",e.vts),e.query&&s.append("query",e.query),e.active!==void 0&&s.append("active",e.active.toString()),e.orderBy&&s.append("orderBy",e.orderBy),e.orderDirection&&s.append("orderDirection",e.orderDirection),e.currency&&s.append("currency",e.currency),e.lang&&s.append("lang",e.lang),e.filter&&s.append("filter",e.filter),e.include&&s.append("include",e.include),e.metafields&&s.append("metafields",e.metafields);let o=`/products${s.size?`?${s}`:""}`;t.debug("Constructed pathname:",o);let n=await this.#e(o);return t.debug("Received product browse result:",{meta:n.meta}),n}async productFilters(e={}){let t=new URLSearchParams;e.lang&&t.append("lang",e.lang);let r=`/products/filters${t.size?`?${t}`:""}`;return this.#e(r)}async productGet(e){let t=new URLSearchParams;e.lang&&t.append("lang",e.lang),e.currency&&t.append("currency",e.currency),e.metafields&&t.append("metafields",e.metafields);let s=t.size?`?${t}`:"",r=`/products/${e.idOrSlug}${s}`,o=await this.#e(r);return o||null}async orderBrowse(e){let t=this.#s.getLogger("orderBrowse");t.debug("Browsing orders with params:",e);let s=new URLSearchParams;e.limit&&s.append("limit",e.limit.toString()),e.offset&&s.append("offset",e.offset.toString());let o=`/orders${s.size?`?${s}`:""}`;t.debug("Constructed pathname:",o);let n=await this.#e(o);return t.debug("Received orders browse result:",{meta:n.meta}),n}async orderGet(e){let t=`/orders/${e.id}`,s=await this.#e(t);return s||null}async cartUpsert(e){return await this.#e("/carts","POST",e)}async cartAddBundle(e){let t={bundleId:e.bundleId,selections:e.selections,...e.cartId?{cartId:e.cartId}:{},...e.currency?{currency:e.currency}:{}};return await this.#e("/carts","POST",t)}async cartRemoveItem(e){let t=`/carts/${e.cartId}/line-items/${e.variantId}`;return this.#e(t,"DELETE")}async cartGet(e){let t=`/carts/${e.cartId}`;return await this.#e(t)}async cartCouponApply(e){let t=`/carts/${e.cartId}/coupon`;return this.#e(t,"POST",{code:e.code})}async cartCouponRemove(e){let t=`/carts/${e.cartId}/coupon`;return this.#e(t,"DELETE")}async couponBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query);let r=`/coupons${t.size?`?${t}`:""}`;return this.#e(r)}async couponGet(e){let t=`/coupons/${e.idOrCode}`;return this.#r(t)}async couponCreate(e){return this.#e("/coupons","POST",e)}async couponUpdate(e,t){let s=`/coupons/${e.idOrCode}`;return this.#e(s,"PATCH",t)}async couponDelete(e){let t=`/coupons/${e.idOrCode}`;return this.#e(t,"DELETE")}async supportCaseBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.status&&t.append("status",e.status),e.severity&&t.append("severity",e.severity);let r=`/support-cases${t.size?`?${t}`:""}`;return this.#e(r)}async supportCaseGet(e){let t=`/support-cases/${e.idOrNumber}`;return this.#r(t)}async supportCaseCreate(e){return this.#e("/support-cases","POST",e)}async supportCaseUpdate(e,t){let s=`/support-cases/${e.idOrNumber}`;return this.#e(s,"PATCH",t)}async supportCaseReply(e,t){let s=`/support-cases/${e.idOrNumber}/messages`;return this.#e(s,"POST",t)}async collectionGet(e){let t=`/collections/${e.idOrSlug}`;return await this.#e(t)}async collectionBrowse(e){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString()),e.group&&t.append("group",e.group);let r=`/collections${t.size?`?${t}`:""}`;return await this.#e(r)}async collectionCreate(e){return this.#e("/collections","POST",e)}async collectionUpdate(e,t){let s=`/collections/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async collectionDelete(e){let t=`/collections/${e.idOrSlug}`;return this.#e(t,"DELETE")}async collectionImportMemberships(e){let t=new FormData;return t.append("file",e.file),this.#u("/collections/import-memberships",t)}async categoryGet(e){let t=`/categories/${e.idOrSlug}`;return await this.#e(t)}async categoriesBrowse(e){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString());let r=`/categories${t.size?`?${t}`:""}`;return await this.#e(r)}async postBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString()),e.tag&&t.append("tag",e.tag),e.categoryId&&t.append("categoryId",e.categoryId);let r=`/posts${t.size?`?${t}`:""}`;return this.#e(r)}async postGet(e){let t=`/posts/${e.idOrSlug}`;return this.#e(t)}async postCreate(e){return this.#e("/posts","POST",e)}async postUpdate(e,t){let s=`/posts/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async postDelete(e){let t=`/posts/${e.idOrSlug}`;return this.#e(t,"DELETE")}async postCommentsBrowse(e,t={}){let s=new URLSearchParams;t.limit&&s.append("limit",t.limit.toString()),t.offset&&s.append("offset",t.offset.toString());let r=s.size?`?${s}`:"",o=`/posts/${e.idOrSlug}/comments${r}`;return this.#e(o)}async postCommentCreate(e,t){let s=`/posts/${e.idOrSlug}/comments`;return this.#e(s,"POST",t)}async blogCategoryBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString());let r=`/blog-categories${t.size?`?${t}`:""}`;return this.#e(r)}async blogCategoryGet(e){let t=`/blog-categories/${e.idOrSlug}`;return this.#e(t)}async blogCategoryCreate(e){return this.#e("/blog-categories","POST",e)}async blogCategoryUpdate(e,t){let s=`/blog-categories/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async blogCategoryDelete(e){let t=`/blog-categories/${e.idOrSlug}`;return this.#e(t,"DELETE")}async customerBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.search&&t.append("search",e.search);let r=`/customers${t.size?`?${t}`:""}`;return this.#e(r)}async customerGet(e){let t=`/customers/${e.id}`;return this.#e(t)}async customerUpdate(e,t){let s=`/customers/${e.id}`;return this.#e(s,"PATCH",t)}async customerAddressCreate(e,t){let s=`/customers/${e.id}/addresses`;return this.#e(s,"POST",t)}async customerAddressDelete(e){let t=`/customers/${e.customerId}/addresses/${e.addressId}`;await this.#e(t,"DELETE")}async customerOrdersBrowse(e,t={}){let s=new URLSearchParams;t.limit&&s.append("limit",t.limit.toString()),t.offset&&s.append("offset",t.offset.toString());let r=s.size?`?${s}`:"",o=`/customers/${e.id}/orders${r}`;return this.#e(o)}async inventoryBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.cursor&&t.append("cursor",e.cursor),e.lowStock!==void 0&&t.append("lowStock",e.lowStock.toString());let r=`/inventory${t.size?`?${t}`:""}`;return this.#e(r)}async inventoryAdjust(e,t){let s=`/inventory/${encodeURIComponent(e)}/adjust`;return this.#e(s,"POST",t)}async variantGet(e){let t=`/variants/${e.idOrSku}`;return this.#e(t)}async variantUpdate(e,t){let s=`/variants/${e.idOrSku}`;return this.#e(s,"PATCH",t)}async variantDelete(e){let t=`/variants/${e.idOrSku}`;await this.#e(t,"DELETE")}async variantCreate(e,t){let s=`/products/${e}/variants`;return this.#e(s,"POST",t)}async subscriberCreate(e){return this.#e("/subscribers","POST",e)}async subscriberDelete(e){let t=`/subscribers?email=${encodeURIComponent(e)}`;return this.#e(t,"DELETE")}async contactMessageCreate(e){return this.#e("/contact-messages","POST",e)}async productCreate(e){return this.#e("/products","POST",e)}async productUpdate(e,t){let s=`/products/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async productDelete(e){let t=`/products/${e.idOrSlug}`;return this.#e(t,"DELETE")}async metafieldDefinitionBrowse(e={}){let t=new URLSearchParams;e.ownerType&&t.append("ownerType",e.ownerType),e.includeArchived&&t.append("includeArchived",e.includeArchived),e.lang&&t.append("lang",e.lang),e.metafields&&t.append("metafields",e.metafields);let r=`/metafield-definitions${t.size?`?${t}`:""}`;return this.#e(r)}async metafieldDefinitionGet(e){let t=new URLSearchParams;e.lang&&t.append("lang",e.lang),e.metafields&&t.append("metafields",e.metafields);let s=t.size?`?${t}`:"",r=`/metafield-definitions/${e.idOrKey}${s}`;return this.#r(r)}async metafieldDefinitionCreate(e){return this.#e("/metafield-definitions","POST",e)}async metafieldDefinitionUpdate(e,t){let s=`/metafield-definitions/${e.idOrKey}`;return this.#e(s,"PATCH",t)}async metafieldDefinitionArchive(e){let t=`/metafield-definitions/${e.idOrKey}`;return this.#e(t,"DELETE")}async metafieldDefinitionRestore(e){let t=`/metafield-definitions/${e.idOrKey}/restore`;return this.#e(t,"POST")}async metafieldDefinitionDelete(e,t){let s=`/metafield-definitions/${e.idOrKey}/purge`;return this.#e(s,"POST",t)}async metafieldDefinitionConversionPreview(e){let t=`/metafield-definitions/${e.idOrKey}/convert-to-choice`;return this.#e(t)}async metafieldDefinitionConvertToChoice(e,t){let s=`/metafield-definitions/${e.idOrKey}/convert-to-choice`;return this.#e(s,"POST",t)}async metafieldDefinitionTranslationPut(e,t){let s=`/metafield-definitions/${e.idOrKey}/translations/${e.locale}`;return this.#e(s,"PUT",t)}async productMetafieldTranslationsPut(e,t){let s=`/products/${e.idOrSlug}/metafields/translations/${e.locale}`;return this.#e(s,"PUT",t)}async variantMetafieldTranslationsPut(e,t){let s=`/variants/${e.idOrSku}/metafields/translations/${e.locale}`;return this.#e(s,"PUT",t)}async metafieldsTranslateMissing(e={}){return this.#e("/metafields/translate-missing","POST",e)}async productReviewsBrowse(e,t={}){let s=new URLSearchParams;t.limit&&s.append("limit",t.limit.toString()),t.offset&&s.append("offset",t.offset.toString());let r=s.size?`?${s}`:"",o=`/products/${e.idOrSlug}/reviews${r}`;return this.#e(o)}async productReviewCreate(e,t){let s=`/products/${e.idOrSlug}/reviews`;return this.#e(s,"POST",t)}async eventBrowse(e={}){let t=this.#s.getLogger("eventBrowse"),s=new URLSearchParams;e.offset!==void 0&&s.append("offset",e.offset.toString()),e.limit!==void 0&&s.append("limit",e.limit.toString());let o=`/events${s.size?`?${s}`:""}`;return t.debug("Browsing events:",o),this.#e(o)}async eventGet(e){let t=`/events/${e.idOrSlug}`;return this.#e(t)}async eventCreate(e){return this.#e("/events","POST",e)}async eventUpdate(e,t){let s=`/events/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async eventAttendeesBrowse(e){let t=`/events/${e.idOrSlug}/attendees`;return this.#e(t)}async ticketsGet(e){let t=this.#s.getLogger("ticketsGet"),s=new URLSearchParams({email:e.email}),r=`/tickets/${encodeURIComponent(e.code)}?${s}`;return t.debug("Fetching ticket bundle:",r),this.#r(r)}async ticketsUpdate(e,t){let s=`/tickets/${encodeURIComponent(e.code)}`;return this.#e(s,"PATCH",t)}async ticketAttendeeGet(e){let t=`/tickets/attendee/${encodeURIComponent(e.token)}`;return this.#r(t)}async categoryCreate(e){return this.#e("/categories","POST",e)}async categoryUpdate(e,t){let s=`/categories/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async categoryDelete(e){let t=`/categories/${e.idOrSlug}`;return this.#e(t,"DELETE")}async orderUpdate(e,t){let s=`/orders/${e.id}`;return this.#e(s,"PATCH",t)}async legalPageBrowse(e={}){return this.request("/legal-pages",{query:e})}async legalPageGet(e,t={}){let s=e.startsWith("/")?e.slice(1):e,r=`/legal-pages/${encodeURIComponent(s)}`;return this.request(r,{query:t})}async legalPageCreate(e,t={}){return this.request("/legal-pages",{method:"POST",body:e,query:t})}async legalPageUpdate(e,t,s={}){let r=e.startsWith("/")?e.slice(1):e,o=`/legal-pages/${encodeURIComponent(r)}`;return this.request(o,{method:"PATCH",body:t,query:s})}async search(e){return this.request("/search",{query:e})}async instaviewImagesBrowse(e,t={}){let s=new URLSearchParams;t.limit&&s.append("limit",t.limit.toString()),t.cursor&&s.append("cursor",t.cursor);let r=s.size?`?${s}`:"",o=`/instaview/accounts/${e.handle}/images${r}`;return this.#e(o)}async request(e,t){let s=t?.query?Object.entries(t.query).filter(o=>{let[,n]=o;return n!=null}):[],r=s.length>0?`?${new URLSearchParams(s.map(([o,n])=>[o,String(n)]))}`:"";return this.#e(`${e}${r}`,t?.method??"GET",t?.body)}};function x(P={}){return new d(P)}export{x as Commerce,d as YNSProvider};
1
+ import"./chunk-PNKB6P4V.js";var C=process.env.YNS_API_KEY,B=process.env.YNS_STORE_ID,I={YNS_API_KEY:C,YNS_STORE_ID:B};var h=new Set(["/products","/collections","/categories","/brands"]),w=new Set(["/products/filters","/legal-pages"]),S=new Set(["products","collections","categories","brands","legal-pages"]),$=new Set(["batch","import","import-memberships","filters"]),v=(P,e)=>{if(w.has(P))return!0;if(h.has(P))return e.get("active")==="true";let[t,s,r,...o]=P.split("/").slice(1);return!t||!s||o.length>0||$.has(s)?!1:r===void 0?S.has(t):t==="products"&&r==="reviews"},p=(P,e)=>{let[t="",s=""]=P.split("?"),r=new URLSearchParams(s),o=r.get("active"),n=r.get("metafields")==="all";if(r.has("store")||o!==null&&o!=="true"||n||!v(t,r))return null;let l=[...r.entries()].sort(([i,f],[y,R])=>i===y?f.localeCompare(R):i.localeCompare(y)),a=new URLSearchParams([["store",e],...l]);return`/${t.slice(1)}?${a}`};var u={DEBUG:0,LOG:1,WARN:2,ERROR:3},T=process.env.NEXT_PUBLIC_LOG_LEVEL||"LOG",c=u[T],A="\x1B[0m",G="\x1B[34m",E="\x1B[32m",D="\x1B[33m",U="\x1B[31m",O="\u23F1\uFE0F",L="\u{1F41B}",M="\u2714\uFE0F",b="\u26A0\uFE0F",k="\u274C",g=`${O} `,q=`${G}${L}${A} `,Q=`${E}${M}${A} `,N=`${D}${b}${A} `,Y=`${U}${k}${A} `,m=P=>{let e=P?`[${P}] `:"";return{getLogger(t){return m([P,t].filter(Boolean).join(" > "))},time(t){c>u.DEBUG||console.time([g,e,t].filter(Boolean).join(" "))},timeEnd(t){c>u.DEBUG||console.timeEnd([g,e,t].filter(Boolean).join(" "))},debug(...t){c>u.DEBUG||console.log(...[q,e,...t].filter(Boolean))},log(...t){c>u.LOG||console.log(...[Q,e,...t].filter(Boolean))},dir(t,s){c>u.LOG||console.dir(t,s)},warn(...t){c>u.WARN||console.warn(...[N,e,...t].filter(Boolean))},error(...t){c>u.ERROR||console.error(...[Y,e,...t].filter(Boolean))}}},j=m();var _=new Set([400,401,403]),d=class{#t;#s=m("YNSProvider");#n=null;constructor(e={}){let t=e.token??I.YNS_API_KEY,s=I.YNS_API_KEY?.startsWith("sk-s-");if(!t)throw new Error("YNS API key is required. Set YNS_API_KEY environment variable or pass token in config.");let r=e.endpoint??(s?"https://yns.cx":"https://yns.store");this.#t={version:"v1",...e,token:t,endpoint:r},this.#s.debug("YNSProvider initialized",{endpoint:r,token:e.token?"from config":"from env"})}async#e(e,t="GET",s){let r=await this.#a(e,t,s);return this.#i(r,e,t)}async#r(e){let t=await this.#a(e,"GET");return t.status===404?null:this.#i(t,e,"GET")}#P(){let e=this.#t.store;return e===!1?Promise.resolve(null):(this.#n??=(async()=>{let t=e??I.YNS_STORE_ID;if(t)return t;try{let s=await this.#o("/me","GET");if(!s.ok)return null;let r=await s.json();return typeof r.store?.id=="string"?r.store.id:null}catch{return null}})(),this.#n)}async#a(e,t,s){if(t!=="GET")return this.#o(e,t,s);let r=await this.#P(),o=r?p(e,r):null;if(!o)return this.#o(e,t);let n=this.#s.getLogger("#restRequest"),l=`${this.#t.endpoint}/api/${this.#t.version}${o}`;n.debug(`Making keyless GET request to YNS API: ${l}`);let a=await fetch(l,{method:t,headers:{"Content-Type":"application/json"}});return _.has(a.status)?(a.status!==400&&(this.#n=Promise.resolve(null)),n.debug(`Keyless request answered ${a.status}, asking again with the key`),this.#o(e,t)):a}async#o(e,t,s){let r=this.#s.getLogger("#restRequest"),o=`${this.#t.endpoint}/api/${this.#t.version}${e}`;return r.debug(`Making ${t} request to YNS API: ${o}`),fetch(o,{method:t,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.#t.token}`},body:s?JSON.stringify(s):void 0})}async#i(e,t,s){let r=this.#s.getLogger("#restRequest"),o=`${this.#t.endpoint}/api/${this.#t.version}${t}`;if(!e.ok){let l=e.headers.get("content-type"),a=`YNS REST request failed: ${s} ${o} ${e.status} ${e.statusText}`;if(l?.includes("application/json"))try{let i=await e.json();a=i.error||i.message||a}catch(i){r.error("Failed to parse YNS error response as JSON",i)}else{let i=await e.text();r.error(`YNS API request failed: ${e.status} ${e.statusText}`,a,i)}throw new Error(a)}let n=e.headers.get("content-type");if(!n?.includes("application/json"))throw new Error(`YNS API returned ${n} instead of JSON for ${t}`);return e.json()}async#l(e,t){let s=this.#s.getLogger("#multipartRequest"),r=`${this.#t.endpoint}/api/${this.#t.version}${e}`;s.debug(`Making multipart POST to YNS API: ${r}`);let o=await fetch(r,{method:"POST",headers:{Authorization:`Bearer ${this.#t.token}`},body:t});if(!o.ok){let l=o.headers.get("content-type"),a=`YNS REST request failed: POST ${r} ${o.status} ${o.statusText}`;if(l?.includes("application/json"))try{let i=await o.json();a=i.error||i.message||a}catch(i){s.error("Failed to parse YNS error response as JSON",i)}else{let i=await o.text();s.error(`YNS API request failed: ${o.status} ${o.statusText}`,a,i)}throw new Error(a)}let n=o.headers.get("content-type");if(!n?.includes("application/json"))throw new Error(`YNS API returned ${n} instead of JSON for ${e}`);return o.json()}async meGet(){let e=this.#s.getLogger("meGet");e.debug("Fetching my information");let s=await this.#e("/me");return e.debug("Received my information:",s),s}async socialsGet(){let e=this.#s.getLogger("socialsGet");e.debug("Fetching store social links");let s=await this.#e("/socials");return e.debug("Received store social links:",s),s}async brandBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString()),e.lang&&t.append("lang",e.lang);let r=`/brands${t.size?`?${t}`:""}`;return this.#e(r)}async brandGet(e){let t=`/brands/${e.idOrSlug}`;return this.#e(t)}async brandCreate(e){return this.#e("/brands","POST",e)}async brandUpdate(e,t){let s=`/brands/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async brandDelete(e){let t=`/brands/${e.idOrSlug}`;return this.#e(t,"DELETE")}async brandAssignProducts(e,t){let s=`/brands/${e.idOrSlug}/products`;return this.#e(s,"POST",t)}async orderRefundsBrowse(e){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString());let s=t.size?`?${t}`:"",r=`/orders/${e.id}/refunds${s}`;return this.#e(r)}async orderRefundGet(e){let t=`/orders/${e.id}/refunds/${e.refundId}`;return this.#e(t)}async productBatch(e){return this.#e("/products/batch","POST",e)}async cartDelete(e){let t=`/carts/${e.cartId}`;return this.#e(t,"DELETE")}async productBrowse(e){let t=this.#s.getLogger("productBrowse");t.debug("Browsing products with params:",e);let s=new URLSearchParams;e.limit&&s.append("limit",e.limit.toString()),e.offset&&s.append("offset",e.offset.toString()),e.category&&s.append("category",e.category),e.collection&&s.append("collection",e.collection),e.brand&&s.append("brand",e.brand),e.priceMin!==void 0&&s.append("priceMin",e.priceMin.toString()),e.priceMax!==void 0&&s.append("priceMax",e.priceMax.toString()),e.vts&&s.append("vts",e.vts),e.query&&s.append("query",e.query),e.active!==void 0&&s.append("active",e.active.toString()),e.orderBy&&s.append("orderBy",e.orderBy),e.orderDirection&&s.append("orderDirection",e.orderDirection),e.currency&&s.append("currency",e.currency),e.lang&&s.append("lang",e.lang),e.filter&&s.append("filter",e.filter),e.include&&s.append("include",e.include),e.metafields&&s.append("metafields",e.metafields);let o=`/products${s.size?`?${s}`:""}`;t.debug("Constructed pathname:",o);let n=await this.#e(o);return t.debug("Received product browse result:",{meta:n.meta}),n}async productFilters(e={}){let t=new URLSearchParams;e.lang&&t.append("lang",e.lang);let r=`/products/filters${t.size?`?${t}`:""}`;return this.#e(r)}async productGet(e){let t=new URLSearchParams;e.lang&&t.append("lang",e.lang),e.currency&&t.append("currency",e.currency),e.metafields&&t.append("metafields",e.metafields);let s=t.size?`?${t}`:"",r=`/products/${e.idOrSlug}${s}`,o=await this.#e(r);return o||null}async orderBrowse(e){let t=this.#s.getLogger("orderBrowse");t.debug("Browsing orders with params:",e);let s=new URLSearchParams;e.limit&&s.append("limit",e.limit.toString()),e.offset&&s.append("offset",e.offset.toString());let o=`/orders${s.size?`?${s}`:""}`;t.debug("Constructed pathname:",o);let n=await this.#e(o);return t.debug("Received orders browse result:",{meta:n.meta}),n}async orderGet(e){let t=`/orders/${e.id}`,s=await this.#e(t);return s||null}async cartUpsert(e){return await this.#e("/carts","POST",e)}async cartAddBundle(e){let t={bundleId:e.bundleId,selections:e.selections,...e.cartId?{cartId:e.cartId}:{},...e.currency?{currency:e.currency}:{}};return await this.#e("/carts","POST",t)}async cartRemoveItem(e){let t=e.lineItemId?`?${new URLSearchParams({lineItemId:e.lineItemId})}`:"",s=`/carts/${e.cartId}/line-items/${e.variantId}${t}`;return this.#e(s,"DELETE")}async cartGet(e){let t=`/carts/${e.cartId}`;return await this.#e(t)}async cartCouponApply(e){let t=`/carts/${e.cartId}/coupon`;return this.#e(t,"POST",{code:e.code})}async cartCouponRemove(e){let t=`/carts/${e.cartId}/coupon`;return this.#e(t,"DELETE")}async couponBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query);let r=`/coupons${t.size?`?${t}`:""}`;return this.#e(r)}async couponGet(e){let t=`/coupons/${e.idOrCode}`;return this.#r(t)}async couponCreate(e){return this.#e("/coupons","POST",e)}async couponUpdate(e,t){let s=`/coupons/${e.idOrCode}`;return this.#e(s,"PATCH",t)}async couponDelete(e){let t=`/coupons/${e.idOrCode}`;return this.#e(t,"DELETE")}async supportCaseBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.status&&t.append("status",e.status),e.severity&&t.append("severity",e.severity);let r=`/support-cases${t.size?`?${t}`:""}`;return this.#e(r)}async supportCaseGet(e){let t=`/support-cases/${e.idOrNumber}`;return this.#r(t)}async supportCaseCreate(e){return this.#e("/support-cases","POST",e)}async supportCaseUpdate(e,t){let s=`/support-cases/${e.idOrNumber}`;return this.#e(s,"PATCH",t)}async supportCaseReply(e,t){let s=`/support-cases/${e.idOrNumber}/messages`;return this.#e(s,"POST",t)}async collectionGet(e){let t=`/collections/${e.idOrSlug}`;return await this.#e(t)}async collectionBrowse(e){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString()),e.group&&t.append("group",e.group);let r=`/collections${t.size?`?${t}`:""}`;return await this.#e(r)}async collectionCreate(e){return this.#e("/collections","POST",e)}async collectionUpdate(e,t){let s=`/collections/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async collectionDelete(e){let t=`/collections/${e.idOrSlug}`;return this.#e(t,"DELETE")}async collectionImportMemberships(e){let t=new FormData;return t.append("file",e.file),this.#l("/collections/import-memberships",t)}async categoryGet(e){let t=`/categories/${e.idOrSlug}`;return await this.#e(t)}async categoriesBrowse(e){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString());let r=`/categories${t.size?`?${t}`:""}`;return await this.#e(r)}async postBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString()),e.tag&&t.append("tag",e.tag),e.categoryId&&t.append("categoryId",e.categoryId);let r=`/posts${t.size?`?${t}`:""}`;return this.#e(r)}async postGet(e){let t=`/posts/${e.idOrSlug}`;return this.#e(t)}async postCreate(e){return this.#e("/posts","POST",e)}async postUpdate(e,t){let s=`/posts/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async postDelete(e){let t=`/posts/${e.idOrSlug}`;return this.#e(t,"DELETE")}async postCommentsBrowse(e,t={}){let s=new URLSearchParams;t.limit&&s.append("limit",t.limit.toString()),t.offset&&s.append("offset",t.offset.toString());let r=s.size?`?${s}`:"",o=`/posts/${e.idOrSlug}/comments${r}`;return this.#e(o)}async postCommentCreate(e,t){let s=`/posts/${e.idOrSlug}/comments`;return this.#e(s,"POST",t)}async blogCategoryBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.query&&t.append("query",e.query),e.active!==void 0&&t.append("active",e.active.toString());let r=`/blog-categories${t.size?`?${t}`:""}`;return this.#e(r)}async blogCategoryGet(e){let t=`/blog-categories/${e.idOrSlug}`;return this.#e(t)}async blogCategoryCreate(e){return this.#e("/blog-categories","POST",e)}async blogCategoryUpdate(e,t){let s=`/blog-categories/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async blogCategoryDelete(e){let t=`/blog-categories/${e.idOrSlug}`;return this.#e(t,"DELETE")}async customerBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.offset&&t.append("offset",e.offset.toString()),e.search&&t.append("search",e.search);let r=`/customers${t.size?`?${t}`:""}`;return this.#e(r)}async customerGet(e){let t=`/customers/${e.id}`;return this.#e(t)}async customerUpdate(e,t){let s=`/customers/${e.id}`;return this.#e(s,"PATCH",t)}async customerAddressCreate(e,t){let s=`/customers/${e.id}/addresses`;return this.#e(s,"POST",t)}async customerAddressDelete(e){let t=`/customers/${e.customerId}/addresses/${e.addressId}`;await this.#e(t,"DELETE")}async customerOrdersBrowse(e,t={}){let s=new URLSearchParams;t.limit&&s.append("limit",t.limit.toString()),t.offset&&s.append("offset",t.offset.toString());let r=s.size?`?${s}`:"",o=`/customers/${e.id}/orders${r}`;return this.#e(o)}async inventoryBrowse(e={}){let t=new URLSearchParams;e.limit&&t.append("limit",e.limit.toString()),e.cursor&&t.append("cursor",e.cursor),e.lowStock!==void 0&&t.append("lowStock",e.lowStock.toString());let r=`/inventory${t.size?`?${t}`:""}`;return this.#e(r)}async inventoryAdjust(e,t){let s=`/inventory/${encodeURIComponent(e)}/adjust`;return this.#e(s,"POST",t)}async variantGet(e){let t=`/variants/${e.idOrSku}`;return this.#e(t)}async variantUpdate(e,t){let s=`/variants/${e.idOrSku}`;return this.#e(s,"PATCH",t)}async variantDelete(e){let t=`/variants/${e.idOrSku}`;await this.#e(t,"DELETE")}async variantCreate(e,t){let s=`/products/${e}/variants`;return this.#e(s,"POST",t)}async subscriberCreate(e){return this.#e("/subscribers","POST",e)}async subscriberDelete(e){let t=`/subscribers?email=${encodeURIComponent(e)}`;return this.#e(t,"DELETE")}async contactMessageCreate(e){return this.#e("/contact-messages","POST",e)}async productCreate(e){return this.#e("/products","POST",e)}async productUpdate(e,t){let s=`/products/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async productDelete(e){let t=`/products/${e.idOrSlug}`;return this.#e(t,"DELETE")}async metafieldDefinitionBrowse(e={}){let t=new URLSearchParams;e.ownerType&&t.append("ownerType",e.ownerType),e.includeArchived&&t.append("includeArchived",e.includeArchived),e.lang&&t.append("lang",e.lang),e.metafields&&t.append("metafields",e.metafields);let r=`/metafield-definitions${t.size?`?${t}`:""}`;return this.#e(r)}async metafieldDefinitionGet(e){let t=new URLSearchParams;e.lang&&t.append("lang",e.lang),e.metafields&&t.append("metafields",e.metafields);let s=t.size?`?${t}`:"",r=`/metafield-definitions/${e.idOrKey}${s}`;return this.#r(r)}async metafieldDefinitionCreate(e){return this.#e("/metafield-definitions","POST",e)}async metafieldDefinitionUpdate(e,t){let s=`/metafield-definitions/${e.idOrKey}`;return this.#e(s,"PATCH",t)}async metafieldDefinitionArchive(e){let t=`/metafield-definitions/${e.idOrKey}`;return this.#e(t,"DELETE")}async metafieldDefinitionRestore(e){let t=`/metafield-definitions/${e.idOrKey}/restore`;return this.#e(t,"POST")}async metafieldDefinitionDelete(e,t){let s=`/metafield-definitions/${e.idOrKey}/purge`;return this.#e(s,"POST",t)}async metafieldDefinitionConversionPreview(e){let t=`/metafield-definitions/${e.idOrKey}/convert-to-choice`;return this.#e(t)}async metafieldDefinitionConvertToChoice(e,t){let s=`/metafield-definitions/${e.idOrKey}/convert-to-choice`;return this.#e(s,"POST",t)}async metafieldDefinitionTranslationPut(e,t){let s=`/metafield-definitions/${e.idOrKey}/translations/${e.locale}`;return this.#e(s,"PUT",t)}async productMetafieldTranslationsPut(e,t){let s=`/products/${e.idOrSlug}/metafields/translations/${e.locale}`;return this.#e(s,"PUT",t)}async variantMetafieldTranslationsPut(e,t){let s=`/variants/${e.idOrSku}/metafields/translations/${e.locale}`;return this.#e(s,"PUT",t)}async metafieldsTranslateMissing(e={}){return this.#e("/metafields/translate-missing","POST",e)}async productReviewsBrowse(e,t={}){let s=new URLSearchParams;t.limit&&s.append("limit",t.limit.toString()),t.offset&&s.append("offset",t.offset.toString());let r=s.size?`?${s}`:"",o=`/products/${e.idOrSlug}/reviews${r}`;return this.#e(o)}async productReviewCreate(e,t){let s=`/products/${e.idOrSlug}/reviews`;return this.#e(s,"POST",t)}async eventBrowse(e={}){let t=this.#s.getLogger("eventBrowse"),s=new URLSearchParams;e.offset!==void 0&&s.append("offset",e.offset.toString()),e.limit!==void 0&&s.append("limit",e.limit.toString());let o=`/events${s.size?`?${s}`:""}`;return t.debug("Browsing events:",o),this.#e(o)}async eventGet(e){let t=`/events/${e.idOrSlug}`;return this.#e(t)}async eventCreate(e){return this.#e("/events","POST",e)}async eventUpdate(e,t){let s=`/events/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async eventAttendeesBrowse(e){let t=`/events/${e.idOrSlug}/attendees`;return this.#e(t)}async ticketsGet(e){let t=this.#s.getLogger("ticketsGet"),s=new URLSearchParams({email:e.email}),r=`/tickets/${encodeURIComponent(e.code)}?${s}`;return t.debug("Fetching ticket bundle:",r),this.#r(r)}async ticketsUpdate(e,t){let s=`/tickets/${encodeURIComponent(e.code)}`;return this.#e(s,"PATCH",t)}async ticketAttendeeGet(e){let t=`/tickets/attendee/${encodeURIComponent(e.token)}`;return this.#r(t)}async categoryCreate(e){return this.#e("/categories","POST",e)}async categoryUpdate(e,t){let s=`/categories/${e.idOrSlug}`;return this.#e(s,"PATCH",t)}async categoryDelete(e){let t=`/categories/${e.idOrSlug}`;return this.#e(t,"DELETE")}async orderUpdate(e,t){let s=`/orders/${e.id}`;return this.#e(s,"PATCH",t)}async legalPageBrowse(e={}){return this.request("/legal-pages",{query:e})}async legalPageGet(e,t={}){let s=e.startsWith("/")?e.slice(1):e,r=`/legal-pages/${encodeURIComponent(s)}`;return this.request(r,{query:t})}async legalPageCreate(e,t={}){return this.request("/legal-pages",{method:"POST",body:e,query:t})}async legalPageUpdate(e,t,s={}){let r=e.startsWith("/")?e.slice(1):e,o=`/legal-pages/${encodeURIComponent(r)}`;return this.request(o,{method:"PATCH",body:t,query:s})}async search(e){return this.request("/search",{query:e})}async instaviewImagesBrowse(e,t={}){let s=new URLSearchParams;t.limit&&s.append("limit",t.limit.toString()),t.cursor&&s.append("cursor",t.cursor);let r=s.size?`?${s}`:"",o=`/instaview/accounts/${e.handle}/images${r}`;return this.#e(o)}async request(e,t){let s=t?.query?Object.entries(t.query).filter(o=>{let[,n]=o;return n!=null}):[],r=s.length>0?`?${new URLSearchParams(s.map(([o,n])=>[o,String(n)]))}`:"";return this.#e(`${e}${r}`,t?.method??"GET",t?.body)}};function x(P={}){return new d(P)}export{x as Commerce,d as YNSProvider};
2
2
  //# sourceMappingURL=index.js.map