@vorlaxen-labs/kargomucuz-sdk 1.0.1 → 1.0.2

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/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var R=Object.create;var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var T=(o,r)=>{for(var e in r)m(o,e,{get:r[e],enumerable:!0})},A=(o,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of S(r))!K.call(o,t)&&t!==e&&m(o,t,{get:()=>r[t],enumerable:!(s=I(r,t))||s.enumerable});return o};var _=(o,r,e)=>(e=o!=null?R(C(o)):{},A(r||!o||!o.__esModule?m(e,"default",{value:o,enumerable:!0}):e,o)),w=o=>A(m({},"__esModule",{value:!0}),o);var z={};T(z,{APIError:()=>c,AuthError:()=>d,Currency:()=>v,Kargomucuz:()=>f,KargomucuzError:()=>i,ProviderServiceCode:()=>b});module.exports=w(z);var x=_(require("axios"),1);var l=class{constructor(r){this.logger=null;r===console||r===!0?this.logger=console:typeof r=="object"&&r!==null&&"info"in r&&"error"in r&&(this.logger=r)}info(r,e){this.logger&&this.logger.info(`\x1B[36m[KM-SDK]\x1B[0m ${r}`,e??"")}error(r,e){this.logger&&this.logger.error(`\x1B[31m[KM-SDK-ERROR]\x1B[0m ${r}`,e??"")}};var i=class extends Error{constructor(r){super(r),this.name="KargomucuzError"}};var c=class extends i{constructor(e,s,t){super(e);this.statusCode=s;this.response=t;this.name="APIError"}};var d=class extends i{constructor(r="Authentication failed."){super(r),this.name="AuthError"}};var a=class{constructor(r){this.config=r;let e="https://api.kargomucuz.com";this.logger=new l(r.logger),this.instance=x.default.create({baseURL:e,timeout:r.timeout||1e4,headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.auth.apiKey}`,"X-SDK-Client":!0}}),this.initializeInterceptors()}initializeInterceptors(){this.instance.interceptors.request.use(r=>{if(this.config.environment!=="production"){let e=`${r.baseURL}${r.url||""}`;this.logger.info(`\x1B[36m[KM-SDK] ${r.method?.toUpperCase()} -> ${e}\x1B[0m`),r.params&&this.logger.info("Query Params:",JSON.stringify(r.params,null,2)),r.data&&this.logger.info("Body:",JSON.stringify(r.data,null,2))}return r}),this.instance.interceptors.response.use(r=>{let e=r.data;if(this.logger.info("Request Success",e),e.status===!1){let s=e.code||r.status;throw new c(e.message||"API Error",s,e)}return e},r=>{let e=r.response?.data,s=e?.code||r.response?.status;return this.logger.error("Request Failed",e||{message:r.message}),s===401||s===403?Promise.reject(new d(e?.message)):Promise.reject(new c(e?.message||r.message,s,e))})}async httpGet(r,e){return this.instance.get(r,e)}async httpPost(r,e,s){return this.instance.post(r,e,s)}};var g=class extends a{constructor(e){super(e.getConfig());this.client=e}async create(e){let s={type:e.role,title:e.title,location:{country:{id:e.location.countryId},city:{id:e.location.cityId},district:{id:e.location.districtId},address:{line1:e.location.addressLine1},postCode:e.location.postCode},by:{entity:e.contact.fullName,phone1:{phoneCountryCode:e.contact.phoneCountryCode,number:e.contact.phoneNumber},email:e.contact.email}},n=(await this.httpPost("/v1/addresses/0",s))?.payload?.data;if(!n)throw new Error("Address data missing in API response.");return this.mapAddress(n)}async list(){let e=this.client.getUserId(),t=(await this.httpGet(`/v1/addresses/${e}`))?.payload?.data;if(!Array.isArray(t))return{senders:[],receivers:[]};let n=t.map(u=>this.mapAddress(u));return{senders:n.filter(u=>u.role==="sender"),receivers:n.filter(u=>u.role==="receiver")}}async retrieve(e){let s=this.client.getUserId(),n=(await this.httpGet(`/v1/addresses/${s}/${e}`))?.payload?.data;if(!n)throw new Error(`Address with ID ${e} not found.`);return this.mapAddress(n)}async resolve(e){let t=(await this.httpPost("/others/convert-address-id",{id:e.toString()}))?.payload?.data;return Array.isArray(t)?t[0]||null:t||null}mapAddress(e){return{id:e._id,role:e.type,title:e.title,contact:{fullName:e.by?.entity,phone:{number:e.by?.phone1?.number??"",country:e.by?.phone1?.phoneCountryCode??""},email:e.by?.email},location:{country:e.location?.country?.title??"T\xFCrkiye",city:e.location?.city?.title,district:e.location?.district?.title,addressLine:e.location?.address?.line1,postCode:e.location?.postCode},createdAt:e.others?.created}}};var y=class extends a{constructor(e){super(e.getConfig());this.client=e}async get(e){let t=(await this.httpGet("/v1/shipments/desi-or-kgs",{params:{providerServiceCode:e.serviceCode,desiOrKg:e.weightOrDesi}}))?.payload?.data,n=Array.isArray(t)?t[0]:t;if(!n)throw new Error("Pricing data not found for the given parameters.");return{amount:Number(n.amount),currency:(n.currency||"TRY").toUpperCase(),providerCode:e.serviceCode}}};var h=class extends a{constructor(e){super(e.getConfig());this.client=e}async getDetail(e){let s=await this.httpGet(`/v1/shipments/0/${e}`);if(!s.payload?.data)throw new Error(s.message??`Shipment not found: ${e}`);let t=s.payload.data;return{id:t._id,providerServiceCode:t.shipmentInfo?.provider?.serviceCode,trackingNumber:t.shipmentInfo?.shipmentReferenceCode??t.labelData?.barcodeValue,status:t.shipmentInfo?.status,createdAt:t.others?.created,savedSenderAddress:null,savedReceiverAddress:null}}async create(e){let s={title:e.title??"Shipment",explanation:e.explanation??"",providerServiceCode:e.providerServiceCode,packageInfo:e.packageInfo,selectedSenderAddressId:e.sender.id,selectedReceiverAddressId:e.receiver.id,buyerPayShipping:e.buyerPayShipping??!1,buyerPayProduct:e.buyerPayProduct??!1},t=await this.httpPost("/v1/shipments/0",s);if(!t.payload)throw new Error(t.message??"Shipment could not be created.");let n=t.payload;return{id:n.shipmentTransactionId,providerServiceCode:n.providerServiceCode,trackingNumber:void 0,savedSenderAddress:n.savedSenderAddress,savedReceiverAddress:n.savedReceieverAddress}}};var f=class{constructor(r){this.userId="0";this.config=Object.freeze({environment:"production",timeout:1e4,...r})}asUser(r){return this.userId=r,this}getUserId(){return this.userId}getConfig(){return this.config}get addresses(){return new g(this)}get rates(){return new y(this)}get shipments(){return new h(this)}getBaseUrl(){return"https://api.kargomucuz.com/v1"}};var v=(s=>(s.TRY="try",s.USD="usd",s.EUR="eur",s))(v||{}),b=(p=>(p.PTT_FIXED_PRICE="ptt_fixed_price",p.PTT_STANDART_2="ptt_standart_2",p.HEPSIJET_STANDART_2="hepsijet_standart_2",p.SURAT_STANDART_2="surat_standart_2",p.UPS_STANDART_2="ups_standart_2",p.KOLAYGELSIN_STANDART_2="kolaygelsin_standart_2",p.YURTICI_STANDART_2="yurtici_standart_2",p))(b||{});0&&(module.exports={APIError,AuthError,Currency,Kargomucuz,KargomucuzError,ProviderServiceCode});
1
+ "use strict";var R=Object.create;var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var T=(o,r)=>{for(var e in r)m(o,e,{get:r[e],enumerable:!0})},A=(o,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of S(r))!K.call(o,t)&&t!==e&&m(o,t,{get:()=>r[t],enumerable:!(s=I(r,t))||s.enumerable});return o};var _=(o,r,e)=>(e=o!=null?R(C(o)):{},A(r||!o||!o.__esModule?m(e,"default",{value:o,enumerable:!0}):e,o)),w=o=>A(m({},"__esModule",{value:!0}),o);var z={};T(z,{APIError:()=>p,AuthError:()=>d,Currency:()=>v,Kargomucuz:()=>f,KargomucuzError:()=>i,ProviderServiceCode:()=>b});module.exports=w(z);var x=_(require("axios"),1);var l=class{constructor(r){this.logger=null;r===console||r===!0?this.logger=console:typeof r=="object"&&r!==null&&"info"in r&&"error"in r&&(this.logger=r)}info(r,e){this.logger&&this.logger.info(`\x1B[36m[KM-SDK]\x1B[0m ${r}`,e??"")}error(r,e){this.logger&&this.logger.error(`\x1B[31m[KM-SDK-ERROR]\x1B[0m ${r}`,e??"")}};var i=class extends Error{constructor(r){super(r),this.name="KargomucuzError"}};var p=class extends i{constructor(e,s,t){super(e);this.statusCode=s;this.response=t;this.name="APIError"}};var d=class extends i{constructor(r="Authentication failed."){super(r),this.name="AuthError"}};var a=class{constructor(r){this.config=r;let e="https://api.kargomucuz.com";this.logger=new l(r.logger),this.instance=x.default.create({baseURL:e,timeout:r.timeout||1e4,headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.auth.apiKey}`,"X-SDK-Client":!0}}),this.initializeInterceptors()}initializeInterceptors(){this.instance.interceptors.request.use(r=>{if(this.config.environment!=="production"){let e=`${r.baseURL}${r.url||""}`;this.logger.info(`\x1B[36m[KM-SDK] ${r.method?.toUpperCase()} -> ${e}\x1B[0m`),r.params&&this.logger.info("Query Params:",JSON.stringify(r.params,null,2)),r.data&&this.logger.info("Body:",JSON.stringify(r.data,null,2))}return r}),this.instance.interceptors.response.use(r=>{let e=r.data;if(this.logger.info("Request Success",e),e.status===!1){let s=e.code||r.status;throw new p(e.message||"API Error",s,e)}return e},r=>{let e=r.response?.data,s=e?.code||r.response?.status;return this.logger.error("Request Failed",e||{message:r.message}),s===401||s===403?Promise.reject(new d(e?.message)):Promise.reject(new p(e?.message||r.message,s,e))})}async httpGet(r,e){return this.instance.get(r,e)}async httpPost(r,e,s){return this.instance.post(r,e,s)}};var g=class extends a{constructor(e){super(e.getConfig());this.client=e}async create(e){let s={type:e.role,title:e.title,location:{country:{id:e.location.countryId},city:{id:e.location.cityId},district:{id:e.location.districtId},address:{line1:e.location.addressLine1},postCode:e.location.postCode},by:{entity:e.contact.fullName,phone1:{phoneCountryCode:e.contact.phoneCountryCode,number:e.contact.phoneNumber},email:e.contact.email}},n=(await this.httpPost("/v1/addresses/0",s))?.payload?.data;if(!n)throw new Error("Address data missing in API response.");return this.mapAddress(n)}async list(){let e=this.client.getUserId(),t=(await this.httpGet(`/v1/addresses/${e}`))?.payload?.data;if(!Array.isArray(t))return{senders:[],receivers:[]};let n=t.map(u=>this.mapAddress(u));return{senders:n.filter(u=>u.role==="sender"),receivers:n.filter(u=>u.role==="receiver")}}async retrieve(e){let s=this.client.getUserId(),n=(await this.httpGet(`/v1/addresses/${s}/${e}`))?.payload?.data;if(!n)throw new Error(`Address with ID ${e} not found.`);return this.mapAddress(n)}async resolve(e){let t=(await this.httpPost("/others/convert-address-id",{id:e.toString()}))?.payload?.data;if(!t)return null;let n=Array.isArray(t)?t[0]:t;return n?{id:n.id,referenceId:n.kargopaneliId,city:n.cityName,district:n.districtName}:null}mapAddress(e){return{id:e._id,role:e.type,title:e.title,contact:{fullName:e.by?.entity,phone:{number:e.by?.phone1?.number??"",country:e.by?.phone1?.phoneCountryCode??""},email:e.by?.email},location:{country:e.location?.country?.title??"T\xFCrkiye",city:e.location?.city?.title,district:e.location?.district?.title,addressLine:e.location?.address?.line1,postCode:e.location?.postCode},createdAt:e.others?.created}}};var y=class extends a{constructor(e){super(e.getConfig());this.client=e}async get(e){let t=(await this.httpGet("/v1/shipments/desi-or-kgs",{params:{providerServiceCode:e.serviceCode,desiOrKg:e.weightOrDesi}}))?.payload?.data,n=Array.isArray(t)?t[0]:t;if(!n)throw new Error("Pricing data not found for the given parameters.");return{amount:Number(n.amount),currency:(n.currency||"TRY").toUpperCase(),providerCode:e.serviceCode}}};var h=class extends a{constructor(e){super(e.getConfig());this.client=e}async getDetail(e){let s=await this.httpGet(`/v1/shipments/0/${e}`);if(!s.payload?.data)throw new Error(s.message??`Shipment not found: ${e}`);let t=s.payload.data;return{id:t._id,providerServiceCode:t.shipmentInfo?.provider?.serviceCode,trackingNumber:t.shipmentInfo?.shipmentReferenceCode??t.labelData?.barcodeValue,status:t.shipmentInfo?.status,createdAt:t.others?.created,savedSenderAddress:null,savedReceiverAddress:null}}async create(e){let s={title:e.title??"Shipment",explanation:e.explanation??"",providerServiceCode:e.providerServiceCode,packageInfo:e.packageInfo,selectedSenderAddressId:e.sender.id,selectedReceiverAddressId:e.receiver.id,buyerPayShipping:e.buyerPayShipping??!1,buyerPayProduct:e.buyerPayProduct??!1},t=await this.httpPost("/v1/shipments/0",s);if(!t.payload)throw new Error(t.message??"Shipment could not be created.");let n=t.payload;return{id:n.shipmentTransactionId,providerServiceCode:n.providerServiceCode,trackingNumber:void 0,savedSenderAddress:n.savedSenderAddress,savedReceiverAddress:n.savedReceieverAddress}}};var f=class{constructor(r){this.userId="0";this.config=Object.freeze({environment:"production",timeout:1e4,...r})}asUser(r){return this.userId=r,this}getUserId(){return this.userId}getConfig(){return this.config}get addresses(){return new g(this)}get rates(){return new y(this)}get shipments(){return new h(this)}getBaseUrl(){return"https://api.kargomucuz.com/v1"}};var v=(s=>(s.TRY="try",s.USD="usd",s.EUR="eur",s))(v||{}),b=(c=>(c.PTT_FIXED_PRICE="ptt_fixed_price",c.PTT_STANDART_2="ptt_standart_2",c.HEPSIJET_STANDART_2="hepsijet_standart_2",c.SURAT_STANDART_2="surat_standart_2",c.UPS_STANDART_2="ups_standart_2",c.KOLAYGELSIN_STANDART_2="kolaygelsin_standart_2",c.YURTICI_STANDART_2="yurtici_standart_2",c))(b||{});0&&(module.exports={APIError,AuthError,Currency,Kargomucuz,KargomucuzError,ProviderServiceCode});
2
2
  /**
3
3
  * @file index.ts
4
4
  * @description Official Kargomucuz SDK Entry Point
package/dist/index.d.cts CHANGED
@@ -57,6 +57,12 @@ interface AddressCreateOptions {
57
57
  postCode: string;
58
58
  };
59
59
  }
60
+ interface AddressResolution {
61
+ id: number;
62
+ referenceId: number;
63
+ city: string;
64
+ district: string;
65
+ }
60
66
  interface Address {
61
67
  id: string;
62
68
  role: "sender" | "receiver";
@@ -88,7 +94,7 @@ declare class AddressesService extends HttpClient {
88
94
  receivers: Address[];
89
95
  }>;
90
96
  retrieve(id: string): Promise<Address>;
91
- resolve(id: string | number): Promise<any | null>;
97
+ resolve(id: string | number): Promise<AddressResolution | null>;
92
98
  private mapAddress;
93
99
  }
94
100
 
package/dist/index.d.ts CHANGED
@@ -57,6 +57,12 @@ interface AddressCreateOptions {
57
57
  postCode: string;
58
58
  };
59
59
  }
60
+ interface AddressResolution {
61
+ id: number;
62
+ referenceId: number;
63
+ city: string;
64
+ district: string;
65
+ }
60
66
  interface Address {
61
67
  id: string;
62
68
  role: "sender" | "receiver";
@@ -88,7 +94,7 @@ declare class AddressesService extends HttpClient {
88
94
  receivers: Address[];
89
95
  }>;
90
96
  retrieve(id: string): Promise<Address>;
91
- resolve(id: string | number): Promise<any | null>;
97
+ resolve(id: string | number): Promise<AddressResolution | null>;
92
98
  private mapAddress;
93
99
  }
94
100
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import f from"axios";var m=class{constructor(r){this.logger=null;r===console||r===!0?this.logger=console:typeof r=="object"&&r!==null&&"info"in r&&"error"in r&&(this.logger=r)}info(r,e){this.logger&&this.logger.info(`\x1B[36m[KM-SDK]\x1B[0m ${r}`,e??"")}error(r,e){this.logger&&this.logger.error(`\x1B[31m[KM-SDK-ERROR]\x1B[0m ${r}`,e??"")}};var p=class extends Error{constructor(r){super(r),this.name="KargomucuzError"}};var c=class extends p{constructor(e,t,s){super(e);this.statusCode=t;this.response=s;this.name="APIError"}};var u=class extends p{constructor(r="Authentication failed."){super(r),this.name="AuthError"}};var i=class{constructor(r){this.config=r;let e="https://api.kargomucuz.com";this.logger=new m(r.logger),this.instance=f.create({baseURL:e,timeout:r.timeout||1e4,headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.auth.apiKey}`,"X-SDK-Client":!0}}),this.initializeInterceptors()}initializeInterceptors(){this.instance.interceptors.request.use(r=>{if(this.config.environment!=="production"){let e=`${r.baseURL}${r.url||""}`;this.logger.info(`\x1B[36m[KM-SDK] ${r.method?.toUpperCase()} -> ${e}\x1B[0m`),r.params&&this.logger.info("Query Params:",JSON.stringify(r.params,null,2)),r.data&&this.logger.info("Body:",JSON.stringify(r.data,null,2))}return r}),this.instance.interceptors.response.use(r=>{let e=r.data;if(this.logger.info("Request Success",e),e.status===!1){let t=e.code||r.status;throw new c(e.message||"API Error",t,e)}return e},r=>{let e=r.response?.data,t=e?.code||r.response?.status;return this.logger.error("Request Failed",e||{message:r.message}),t===401||t===403?Promise.reject(new u(e?.message)):Promise.reject(new c(e?.message||r.message,t,e))})}async httpGet(r,e){return this.instance.get(r,e)}async httpPost(r,e,t){return this.instance.post(r,e,t)}};var l=class extends i{constructor(e){super(e.getConfig());this.client=e}async create(e){let t={type:e.role,title:e.title,location:{country:{id:e.location.countryId},city:{id:e.location.cityId},district:{id:e.location.districtId},address:{line1:e.location.addressLine1},postCode:e.location.postCode},by:{entity:e.contact.fullName,phone1:{phoneCountryCode:e.contact.phoneCountryCode,number:e.contact.phoneNumber},email:e.contact.email}},o=(await this.httpPost("/v1/addresses/0",t))?.payload?.data;if(!o)throw new Error("Address data missing in API response.");return this.mapAddress(o)}async list(){let e=this.client.getUserId(),s=(await this.httpGet(`/v1/addresses/${e}`))?.payload?.data;if(!Array.isArray(s))return{senders:[],receivers:[]};let o=s.map(d=>this.mapAddress(d));return{senders:o.filter(d=>d.role==="sender"),receivers:o.filter(d=>d.role==="receiver")}}async retrieve(e){let t=this.client.getUserId(),o=(await this.httpGet(`/v1/addresses/${t}/${e}`))?.payload?.data;if(!o)throw new Error(`Address with ID ${e} not found.`);return this.mapAddress(o)}async resolve(e){let s=(await this.httpPost("/others/convert-address-id",{id:e.toString()}))?.payload?.data;return Array.isArray(s)?s[0]||null:s||null}mapAddress(e){return{id:e._id,role:e.type,title:e.title,contact:{fullName:e.by?.entity,phone:{number:e.by?.phone1?.number??"",country:e.by?.phone1?.phoneCountryCode??""},email:e.by?.email},location:{country:e.location?.country?.title??"T\xFCrkiye",city:e.location?.city?.title,district:e.location?.district?.title,addressLine:e.location?.address?.line1,postCode:e.location?.postCode},createdAt:e.others?.created}}};var g=class extends i{constructor(e){super(e.getConfig());this.client=e}async get(e){let s=(await this.httpGet("/v1/shipments/desi-or-kgs",{params:{providerServiceCode:e.serviceCode,desiOrKg:e.weightOrDesi}}))?.payload?.data,o=Array.isArray(s)?s[0]:s;if(!o)throw new Error("Pricing data not found for the given parameters.");return{amount:Number(o.amount),currency:(o.currency||"TRY").toUpperCase(),providerCode:e.serviceCode}}};var y=class extends i{constructor(e){super(e.getConfig());this.client=e}async getDetail(e){let t=await this.httpGet(`/v1/shipments/0/${e}`);if(!t.payload?.data)throw new Error(t.message??`Shipment not found: ${e}`);let s=t.payload.data;return{id:s._id,providerServiceCode:s.shipmentInfo?.provider?.serviceCode,trackingNumber:s.shipmentInfo?.shipmentReferenceCode??s.labelData?.barcodeValue,status:s.shipmentInfo?.status,createdAt:s.others?.created,savedSenderAddress:null,savedReceiverAddress:null}}async create(e){let t={title:e.title??"Shipment",explanation:e.explanation??"",providerServiceCode:e.providerServiceCode,packageInfo:e.packageInfo,selectedSenderAddressId:e.sender.id,selectedReceiverAddressId:e.receiver.id,buyerPayShipping:e.buyerPayShipping??!1,buyerPayProduct:e.buyerPayProduct??!1},s=await this.httpPost("/v1/shipments/0",t);if(!s.payload)throw new Error(s.message??"Shipment could not be created.");let o=s.payload;return{id:o.shipmentTransactionId,providerServiceCode:o.providerServiceCode,trackingNumber:void 0,savedSenderAddress:o.savedSenderAddress,savedReceiverAddress:o.savedReceieverAddress}}};var h=class{constructor(r){this.userId="0";this.config=Object.freeze({environment:"production",timeout:1e4,...r})}asUser(r){return this.userId=r,this}getUserId(){return this.userId}getConfig(){return this.config}get addresses(){return new l(this)}get rates(){return new g(this)}get shipments(){return new y(this)}getBaseUrl(){return"https://api.kargomucuz.com/v1"}};var A=(t=>(t.TRY="try",t.USD="usd",t.EUR="eur",t))(A||{}),x=(a=>(a.PTT_FIXED_PRICE="ptt_fixed_price",a.PTT_STANDART_2="ptt_standart_2",a.HEPSIJET_STANDART_2="hepsijet_standart_2",a.SURAT_STANDART_2="surat_standart_2",a.UPS_STANDART_2="ups_standart_2",a.KOLAYGELSIN_STANDART_2="kolaygelsin_standart_2",a.YURTICI_STANDART_2="yurtici_standart_2",a))(x||{});export{c as APIError,u as AuthError,A as Currency,h as Kargomucuz,p as KargomucuzError,x as ProviderServiceCode};
1
+ import f from"axios";var m=class{constructor(r){this.logger=null;r===console||r===!0?this.logger=console:typeof r=="object"&&r!==null&&"info"in r&&"error"in r&&(this.logger=r)}info(r,e){this.logger&&this.logger.info(`\x1B[36m[KM-SDK]\x1B[0m ${r}`,e??"")}error(r,e){this.logger&&this.logger.error(`\x1B[31m[KM-SDK-ERROR]\x1B[0m ${r}`,e??"")}};var c=class extends Error{constructor(r){super(r),this.name="KargomucuzError"}};var p=class extends c{constructor(e,t,s){super(e);this.statusCode=t;this.response=s;this.name="APIError"}};var u=class extends c{constructor(r="Authentication failed."){super(r),this.name="AuthError"}};var i=class{constructor(r){this.config=r;let e="https://api.kargomucuz.com";this.logger=new m(r.logger),this.instance=f.create({baseURL:e,timeout:r.timeout||1e4,headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.auth.apiKey}`,"X-SDK-Client":!0}}),this.initializeInterceptors()}initializeInterceptors(){this.instance.interceptors.request.use(r=>{if(this.config.environment!=="production"){let e=`${r.baseURL}${r.url||""}`;this.logger.info(`\x1B[36m[KM-SDK] ${r.method?.toUpperCase()} -> ${e}\x1B[0m`),r.params&&this.logger.info("Query Params:",JSON.stringify(r.params,null,2)),r.data&&this.logger.info("Body:",JSON.stringify(r.data,null,2))}return r}),this.instance.interceptors.response.use(r=>{let e=r.data;if(this.logger.info("Request Success",e),e.status===!1){let t=e.code||r.status;throw new p(e.message||"API Error",t,e)}return e},r=>{let e=r.response?.data,t=e?.code||r.response?.status;return this.logger.error("Request Failed",e||{message:r.message}),t===401||t===403?Promise.reject(new u(e?.message)):Promise.reject(new p(e?.message||r.message,t,e))})}async httpGet(r,e){return this.instance.get(r,e)}async httpPost(r,e,t){return this.instance.post(r,e,t)}};var l=class extends i{constructor(e){super(e.getConfig());this.client=e}async create(e){let t={type:e.role,title:e.title,location:{country:{id:e.location.countryId},city:{id:e.location.cityId},district:{id:e.location.districtId},address:{line1:e.location.addressLine1},postCode:e.location.postCode},by:{entity:e.contact.fullName,phone1:{phoneCountryCode:e.contact.phoneCountryCode,number:e.contact.phoneNumber},email:e.contact.email}},o=(await this.httpPost("/v1/addresses/0",t))?.payload?.data;if(!o)throw new Error("Address data missing in API response.");return this.mapAddress(o)}async list(){let e=this.client.getUserId(),s=(await this.httpGet(`/v1/addresses/${e}`))?.payload?.data;if(!Array.isArray(s))return{senders:[],receivers:[]};let o=s.map(d=>this.mapAddress(d));return{senders:o.filter(d=>d.role==="sender"),receivers:o.filter(d=>d.role==="receiver")}}async retrieve(e){let t=this.client.getUserId(),o=(await this.httpGet(`/v1/addresses/${t}/${e}`))?.payload?.data;if(!o)throw new Error(`Address with ID ${e} not found.`);return this.mapAddress(o)}async resolve(e){let s=(await this.httpPost("/others/convert-address-id",{id:e.toString()}))?.payload?.data;if(!s)return null;let o=Array.isArray(s)?s[0]:s;return o?{id:o.id,referenceId:o.kargopaneliId,city:o.cityName,district:o.districtName}:null}mapAddress(e){return{id:e._id,role:e.type,title:e.title,contact:{fullName:e.by?.entity,phone:{number:e.by?.phone1?.number??"",country:e.by?.phone1?.phoneCountryCode??""},email:e.by?.email},location:{country:e.location?.country?.title??"T\xFCrkiye",city:e.location?.city?.title,district:e.location?.district?.title,addressLine:e.location?.address?.line1,postCode:e.location?.postCode},createdAt:e.others?.created}}};var g=class extends i{constructor(e){super(e.getConfig());this.client=e}async get(e){let s=(await this.httpGet("/v1/shipments/desi-or-kgs",{params:{providerServiceCode:e.serviceCode,desiOrKg:e.weightOrDesi}}))?.payload?.data,o=Array.isArray(s)?s[0]:s;if(!o)throw new Error("Pricing data not found for the given parameters.");return{amount:Number(o.amount),currency:(o.currency||"TRY").toUpperCase(),providerCode:e.serviceCode}}};var y=class extends i{constructor(e){super(e.getConfig());this.client=e}async getDetail(e){let t=await this.httpGet(`/v1/shipments/0/${e}`);if(!t.payload?.data)throw new Error(t.message??`Shipment not found: ${e}`);let s=t.payload.data;return{id:s._id,providerServiceCode:s.shipmentInfo?.provider?.serviceCode,trackingNumber:s.shipmentInfo?.shipmentReferenceCode??s.labelData?.barcodeValue,status:s.shipmentInfo?.status,createdAt:s.others?.created,savedSenderAddress:null,savedReceiverAddress:null}}async create(e){let t={title:e.title??"Shipment",explanation:e.explanation??"",providerServiceCode:e.providerServiceCode,packageInfo:e.packageInfo,selectedSenderAddressId:e.sender.id,selectedReceiverAddressId:e.receiver.id,buyerPayShipping:e.buyerPayShipping??!1,buyerPayProduct:e.buyerPayProduct??!1},s=await this.httpPost("/v1/shipments/0",t);if(!s.payload)throw new Error(s.message??"Shipment could not be created.");let o=s.payload;return{id:o.shipmentTransactionId,providerServiceCode:o.providerServiceCode,trackingNumber:void 0,savedSenderAddress:o.savedSenderAddress,savedReceiverAddress:o.savedReceieverAddress}}};var h=class{constructor(r){this.userId="0";this.config=Object.freeze({environment:"production",timeout:1e4,...r})}asUser(r){return this.userId=r,this}getUserId(){return this.userId}getConfig(){return this.config}get addresses(){return new l(this)}get rates(){return new g(this)}get shipments(){return new y(this)}getBaseUrl(){return"https://api.kargomucuz.com/v1"}};var A=(t=>(t.TRY="try",t.USD="usd",t.EUR="eur",t))(A||{}),x=(a=>(a.PTT_FIXED_PRICE="ptt_fixed_price",a.PTT_STANDART_2="ptt_standart_2",a.HEPSIJET_STANDART_2="hepsijet_standart_2",a.SURAT_STANDART_2="surat_standart_2",a.UPS_STANDART_2="ups_standart_2",a.KOLAYGELSIN_STANDART_2="kolaygelsin_standart_2",a.YURTICI_STANDART_2="yurtici_standart_2",a))(x||{});export{p as APIError,u as AuthError,A as Currency,h as Kargomucuz,c as KargomucuzError,x as ProviderServiceCode};
2
2
  /**
3
3
  * @file index.ts
4
4
  * @description Official Kargomucuz SDK Entry Point
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vorlaxen-labs/kargomucuz-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Official SDK for Kargomucuz. Unified cargo operations, shipment automation, and enterprise-grade logistics infrastructure.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",