@ikas/storefront 4.2.0-beta.1 → 4.2.0-beta.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.
@@ -53,6 +53,8 @@ export default class CountrySettingsModel {
53
53
  isFreeTextDistrict(country: string): boolean | undefined;
54
54
  getAddressFormCountrySettings: () => Promise<void>;
55
55
  getAddressFormCountryLabels: () => Promise<void>;
56
+ validatePhoneNumber: (str: string) => boolean;
57
+ validateByRegexString: (str: string, regexStr: string) => boolean;
56
58
  }
57
59
  export declare const countryFormsLocales: string[];
58
60
  export declare type IkasAddressFormCountrySettings = {
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import{IkasStorefrontConfig as n}from"@ikas/storefront-config";import{IkasCheckoutRequirement as r}from"@ikas/storefront-models";import s from"lodash/difference";import o from"lodash/mapValues";import{validatePhoneNumber as u,validateByRegexString as d}from"@ikas/storefront-model-functions/src/utils/helper";var a,l=function(){function l(a){var l=this;this._initialized=!1,this.init=function(){return t(l,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.getAddressFormCountrySettings()];case 1:return t.sent(),[4,this.getAddressFormCountryLabels()];case 2:return t.sent(),this._initialized=!0,[2]}}))}))},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){l.initialized&&(clearInterval(e),t(null))}),100)}))},this.getCountrySettings=function(t){return l._addressFormCountrySettings.countrySettings[t]},this.getCountryLabels=function(t){return l._addressFormCountryLabels.countryLabels[t]},this.getFieldSettings=function(t){return l.getCountrySettings(t).fields},this.getFieldLabels=function(t){var e=l.getCountryLabels(t);if(e)return o(e.fields,(function(t,e){return null==t?void 0:t.label}))},this.getAddressFormatView=function(t){return l._addressFormCountrySettings.addressFormats[t]},this.getBillingFormatView=function(t){return l._addressFormCountrySettings.billingFormats[t]},this.getAddressFormat=function(t){var e=l.getCountrySettings(t),i=l.getAddressFormatView(e.addressFormat);if(l.checkoutSettings&&i){var n=[];return l.checkoutSettings.identityNumberRequirement===r.INVISIBLE&&n.push("identityNumber"),l.checkoutSettings.postalCodeRequirement===r.INVISIBLE&&n.push("postalCode"),l.checkoutSettings.phoneRequirement===r.INVISIBLE&&n.push("phone"),i.map((function(t){return s(t,n)}))||[]}return i},this.getBillingFormat=function(t){var e=l.getCountrySettings(t);return l.getBillingFormatView(e.billingFormat)},this.getAddressFormatIgnoreCountry=function(t){return l.getAddressFormat(t).map((function(t){return s(t,["country"])}))},this.getValidationResult=function(t){var e,i,n,s,o,d,a=l.getFieldSettings((null===(e=t.country)||void 0===e?void 0:e.iso2)||"TR");if(l.checkoutSettings&&a){var c=!!t.phone&&t.phone.length>=10&&u(t.phone);return{firstName:l.isValidField(t.firstName,a.firstName),lastName:l.isValidField(t.lastName,a.lastName),addressLine1:l.isValidField(t.addressLine1,a.addressLine1),country:l.isValidField((null===(i=t.country)||void 0===i?void 0:i.name)||"",a.country),state:l.isValidField((null===(n=t.state)||void 0===n?void 0:n.name)||"",a.state),city:l.isValidField((null===(s=t.city)||void 0===s?void 0:s.name)||"",a.city),district:l.isValidField((null===(o=t.district)||void 0===o?void 0:o.name)||"",a.district),phone:(null===(d=a.phone)||void 0===d?void 0:d.regex)?l.isValidField(t.phone||"",a.phone,l.checkoutSettings.phoneRequirement):!(l.checkoutSettings.phoneRequirement===r.MANDATORY||l.checkoutSettings.phoneRequirement===r.OPTIONAL&&t.phone)||c,postalCode:l.isValidField(t.postalCode||"",a.postalCode,l.checkoutSettings.postalCodeRequirement),identityNumber:l.isValidField(t.identityNumber||"",a.identityNumber,l.checkoutSettings.identityNumberRequirement)}}},this.isValidField=function(t,e,i){var n=!0,s=i?i===r.MANDATORY:(null==e?void 0:e.required)||!1,o=!!(null==e?void 0:e.regex)||!1;return s&&!o&&(n=!!t),s&&o&&(n=!!t||d(t,e.regex)),!s&&o&&t&&(n=d(t,e.regex)),n},this.getAddressFormCountrySettings=function(){return t(l,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return"https://cdn.myikas.com/sf/static/location/settings.json",[4,fetch("https://cdn.myikas.com/sf/static/location/settings.json")];case 1:return[4,e.sent().json()];case 2:return t=e.sent(),this._addressFormCountrySettings=t,[2]}}))}))},this.getAddressFormCountryLabels=function(){return t(l,void 0,void 0,(function(){var t,i,r;return e(this,(function(e){switch(e.label){case 0:return t=n.getCurrentLocale(),c.find((function(e){return e===t}))||(t="en"),i="https://cdn.myikas.com/sf/static/location/".concat(t,".json"),[4,fetch(i)];case 1:return[4,e.sent().json()];case 2:return r=e.sent(),this._addressFormCountryLabels=r,[2]}}))}))},this.checkoutSettings=a.checkoutSettings,this.init(),i(this)}return Object.defineProperty(l.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),l.prototype.isValidAddress=function(t){var e=this.getValidationResult(t);return!!e&&Object.values(e).every((function(t){return t}))},l.prototype.isFreeTextCity=function(t){var e=this.getFieldSettings(t);return e&&e.city&&e.city.type===a.TEXT},l.prototype.isFreeTextDistrict=function(t){var e=this.getFieldSettings(t);return e&&e.district&&e.district.type===a.TEXT},l}(),c=["tr","de","en","it","es","fr","ru"];!function(t){t.TEXT="text",t.DROPDOWN="dropdown"}(a||(a={}));export{c as countryFormsLocales,l as default};
1
+ import{__awaiter as t,__generator as e}from'./../../ext/tslib/tslib.es6.js';import{makeAutoObservable as i}from"mobx";import{IkasStorefrontConfig as n}from"@ikas/storefront-config";import{IkasCheckoutRequirement as r}from"@ikas/storefront-models";import s from"lodash/difference";import o from"lodash/mapValues";var u,a=function(){function a(u){var a=this;this._initialized=!1,this.init=function(){return t(a,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return[4,this.getAddressFormCountrySettings()];case 1:return t.sent(),[4,this.getAddressFormCountryLabels()];case 2:return t.sent(),this._initialized=!0,[2]}}))}))},this.waitUntilInitialized=function(){return new Promise((function(t){var e=setInterval((function(){a.initialized&&(clearInterval(e),t(null))}),100)}))},this.getCountrySettings=function(t){return a._addressFormCountrySettings.countrySettings[t]},this.getCountryLabels=function(t){return a._addressFormCountryLabels.countryLabels[t]},this.getFieldSettings=function(t){return a.getCountrySettings(t).fields},this.getFieldLabels=function(t){var e=a.getCountryLabels(t);if(e)return o(e.fields,(function(t,e){return null==t?void 0:t.label}))},this.getAddressFormatView=function(t){return a._addressFormCountrySettings.addressFormats[t]},this.getBillingFormatView=function(t){return a._addressFormCountrySettings.billingFormats[t]},this.getAddressFormat=function(t){var e=a.getCountrySettings(t),i=a.getAddressFormatView(e.addressFormat);if(a.checkoutSettings&&i){var n=[];return a.checkoutSettings.identityNumberRequirement===r.INVISIBLE&&n.push("identityNumber"),a.checkoutSettings.postalCodeRequirement===r.INVISIBLE&&n.push("postalCode"),a.checkoutSettings.phoneRequirement===r.INVISIBLE&&n.push("phone"),i.map((function(t){return s(t,n)}))||[]}return i},this.getBillingFormat=function(t){var e=a.getCountrySettings(t);return a.getBillingFormatView(e.billingFormat)},this.getAddressFormatIgnoreCountry=function(t){return a.getAddressFormat(t).map((function(t){return s(t,["country"])}))},this.getValidationResult=function(t){var e,i,n,s,o,u,d=a.getFieldSettings((null===(e=t.country)||void 0===e?void 0:e.iso2)||"TR");if(a.checkoutSettings&&d){var l=!!t.phone&&t.phone.length>=10&&a.validatePhoneNumber(t.phone);return{firstName:a.isValidField(t.firstName,d.firstName),lastName:a.isValidField(t.lastName,d.lastName),addressLine1:a.isValidField(t.addressLine1,d.addressLine1),country:a.isValidField((null===(i=t.country)||void 0===i?void 0:i.name)||"",d.country),state:a.isValidField((null===(n=t.state)||void 0===n?void 0:n.name)||"",d.state),city:a.isValidField((null===(s=t.city)||void 0===s?void 0:s.name)||"",d.city),district:a.isValidField((null===(o=t.district)||void 0===o?void 0:o.name)||"",d.district),phone:(null===(u=d.phone)||void 0===u?void 0:u.regex)?a.isValidField(t.phone||"",d.phone,a.checkoutSettings.phoneRequirement):!(a.checkoutSettings.phoneRequirement===r.MANDATORY||a.checkoutSettings.phoneRequirement===r.OPTIONAL&&t.phone)||l,postalCode:a.isValidField(t.postalCode||"",d.postalCode,a.checkoutSettings.postalCodeRequirement),identityNumber:a.isValidField(t.identityNumber||"",d.identityNumber,a.checkoutSettings.identityNumberRequirement)}}},this.isValidField=function(t,e,i){var n=!0,s=i?i===r.MANDATORY:(null==e?void 0:e.required)||!1,o=!!(null==e?void 0:e.regex)||!1;return s&&!o&&(n=!!t),s&&o&&(n=!!t||a.validateByRegexString(t,e.regex)),!s&&o&&t&&(n=a.validateByRegexString(t,e.regex)),n},this.getAddressFormCountrySettings=function(){return t(a,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return"https://cdn.myikas.com/sf/static/location/settings.json",[4,fetch("https://cdn.myikas.com/sf/static/location/settings.json")];case 1:return[4,e.sent().json()];case 2:return t=e.sent(),this._addressFormCountrySettings=t,[2]}}))}))},this.getAddressFormCountryLabels=function(){return t(a,void 0,void 0,(function(){var t,i,r;return e(this,(function(e){switch(e.label){case 0:return t=n.getCurrentLocale(),d.find((function(e){return e===t}))||(t="en"),i="https://cdn.myikas.com/sf/static/location/".concat(t,".json"),[4,fetch(i)];case 1:return[4,e.sent().json()];case 2:return r=e.sent(),this._addressFormCountryLabels=r,[2]}}))}))},this.validatePhoneNumber=function(t){return/^\+?\d+$/.test(t)},this.validateByRegexString=function(t,e){return new RegExp(e).test(t)},this.checkoutSettings=u.checkoutSettings,this.init(),i(this)}return Object.defineProperty(a.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),a.prototype.isValidAddress=function(t){var e=this.getValidationResult(t);return!!e&&Object.values(e).every((function(t){return t}))},a.prototype.isFreeTextCity=function(t){var e=this.getFieldSettings(t);return e&&e.city&&e.city.type===u.TEXT},a.prototype.isFreeTextDistrict=function(t){var e=this.getFieldSettings(t);return e&&e.district&&e.district.type===u.TEXT},a}(),d=["tr","de","en","it","es","fr","ru"];!function(t){t.TEXT="text",t.DROPDOWN="dropdown"}(u||(u={}));export{d as countryFormsLocales,a as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "4.2.0-beta.1",
3
+ "version": "4.2.0-beta.2",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "dependencies": {},
20
20
  "devDependencies": {
21
- "@ikas/storefront-api": "^4.2.0-beta.1",
22
- "@ikas/storefront-config": "^4.2.0-beta.1",
23
- "@ikas/storefront-model-functions": "^4.2.0-beta.1",
24
- "@ikas/storefront-models": "^4.2.0-beta.1",
25
- "@ikas/storefront-providers": "^4.2.0-beta.1",
21
+ "@ikas/storefront-api": "^4.2.0-beta.2",
22
+ "@ikas/storefront-config": "^4.2.0-beta.2",
23
+ "@ikas/storefront-model-functions": "^4.2.0-beta.2",
24
+ "@ikas/storefront-models": "^4.2.0-beta.2",
25
+ "@ikas/storefront-providers": "^4.2.0-beta.2",
26
26
  "@rollup/plugin-commonjs": "^22.0.0",
27
27
  "@rollup/plugin-json": "^4.1.0",
28
28
  "@rollup/plugin-node-resolve": "^13.3.0",
@@ -52,11 +52,11 @@
52
52
  "libphonenumber-js": "^1.10.6"
53
53
  },
54
54
  "peerDependencies": {
55
- "@ikas/storefront-api": "^4.2.0-beta.1",
56
- "@ikas/storefront-config": "^4.2.0-beta.1",
57
- "@ikas/storefront-model-functions": "^4.2.0-beta.1",
58
- "@ikas/storefront-models": "^4.2.0-beta.1",
59
- "@ikas/storefront-providers": "^4.2.0-beta.1",
55
+ "@ikas/storefront-api": "^4.2.0-beta.2",
56
+ "@ikas/storefront-config": "^4.2.0-beta.2",
57
+ "@ikas/storefront-model-functions": "^4.2.0-beta.2",
58
+ "@ikas/storefront-models": "^4.2.0-beta.2",
59
+ "@ikas/storefront-providers": "^4.2.0-beta.2",
60
60
  "mobx": "^6.1.3",
61
61
  "mobx-react-lite": "^3.1.5",
62
62
  "next": "12.2.0",