Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
add typedefs and tweak config
Browse files Browse the repository at this point in the history
  • Loading branch information
nerrad committed Mar 5, 2020
1 parent ea99485 commit 2e9bf11
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 1 deletion.
37 changes: 37 additions & 0 deletions assets/js/type-defs/checkout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @typedef {Object} CheckoutDispatchActions
*
* @property {function()} resetCheckout Dispatches an action that resets
* the checkout to a pristine state.
* @property {function()} setRedirectUrl Dispatches an action that sets the
* redirectUrl to the given value.
* @property {function()} setHasError Dispatches an action that sets the
* checkout status to having an error.
* @property {function()} clearError Dispatches an action that clears
* the hasError status for the
* checkout.
* @property {function()} incrementCalculating Dispatches an action that
* increments the calculating state
* for checkout by one.
* @property {function()} decrementCalculating Dispatches an action that
* decrements the calculating state
* for checkout by one.
*/

/**
* @typedef {Object} CheckoutStatusConstants
*
* @property {string} PRISTINE Checkout is in it's initialized state.
* @property {string} IDLE When checkout state has changed but there is
* no activity happening.
* @property {string} CALCULATING When something in the checkout results in the
* totals being recalculated, this will be the
* state while calculating is happening.
* @property {string} PROCESSING This is the state when the checkout button has
* been pressed and the checkout data has been
* sent to the server for processing.
* @property {string} COMPLETE This is the status when the server has
* completed processing the data successfully.
*/

export {};
206 changes: 206 additions & 0 deletions assets/js/type-defs/contexts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/**
* @typedef {import('./cart').CartShippingOption} CartShippingOption
* @typedef {import('./cart').CartShippingAddress} CartShippingAddress
* @typedef {import('./cart').CartBillingAddress} CartBillingAddress
* @typedef {import('./checkout').CheckoutDispatchActions} CheckoutDispatchActions
*/

/**
* @typedef {Object} ShippingMethodDataContext
*
* @property {string} shippingErrorStatus The current error
* status for shipping
* rates if present.
* @property {Function} dispatchErrorStatus A function for
* dispatching a shipping
* rate error status.
* @property {ShippingErrorTypes} shippingErrorTypes The error type
* constants for the
* shipping rate error
* status.
* @property {CartShippingOption[]} shippingRates An array of available
* shipping rates.
* @property {Function} setShippingRates Used to set the
* available shipping
* rates.
* @property {boolean} shippingRatesLoading Whether or not the
* shipping rates are
* being loaded.
* @property {string[]} selectedRates The ids of the rates
* that are selected.
* @property {Function} setSelectedRates A function for setting
* the selected rates.
* @property {CartShippingAddress} shippingAddress The current set
* address for shipping.
* @property {function()} setShippingAddress A function for setting
* the shipping address.
* @property {function()} onShippingRateSuccess Used to register a
* callback to be invoked
* when shipping rates
* are retrieved
* successfully.
* @property {function()} onShippingRateSelectSuccess Used to register
* a callback to be
* invoked when shipping
* rate is selected
* successfully.
* @property {function()} onShippingRateSelectFail Used to register a
* callback to be invoked
* when shipping rate is
* selected unsuccessfully
* @property {function()} onShippingRateFail Used to register a
* callback to be invoked
* when there is an
* error with retrieving
* shipping rates.
* @property {boolean} needsShipping True if the cart has
* items requiring
* shipping.
*/

/**
* @typedef {Object} ShippingErrorTypes
*
* @property {string} NONE No shipping error.
* @property {string} INVALID_ADDRESS Error due to an invalid address for
* calculating shipping.
* @property {string} UNKNOWN When an unknown error has occurred in
* calculating/retrieving shipping rates.
*/

/**
* @typedef {Object} PaymentMethodCurrentStatus
*
* This contains status information for the current active payment method in
* the checkout.
*
* @property {boolean} isPristine If true then the payment method state in
* checkout is pristine.
* @property {boolean} isStarted If true then the payment method has been
* initialized and has started.
* @property {boolean} isProcessing If true then the payment method is
* processing payment.
* @property {boolean} isFinished If true then the payment method is in a
* finished state (which may mean it's status
* is either error, failed, or success)
* @property {boolean} hasError If true then the payment method is in an
* error state.
* @property {boolean} hasFailed If true then the payment method has failed
* (usually indicates a problem with the
* payment method used, not logic error)
* @property {boolean} isSuccessful If true then the payment method has
* completed it's processing successfully.
*/

/**
* @typedef {Object} PaymentStatusDispatchers
*
* @property {function()} started
* @property {function()} processing
* @property {function()} completed
* @property {function(string)} error
* @property {function(string, CartBillingAddress, Object)} failed
* @property {function(CartBillingAddress, Object)} success
*/

/**
* @typedef {function():PaymentStatusDispatchers} PaymentStatusDispatch
*/

/**
* @typedef {Object} PaymentMethodDataContext
*
* @property {PaymentStatusDispatch} setPaymentStatus Sets the
* payment status
* for the payment
* method.
* @property {PaymentMethodCurrentStatus} currentStatus The current
* payment status.
* @property {Object} paymentStatuses An object of
* payment status
* constants.
* @property {CartBillingAddress} billingData The current set
* billing data.
* @property {Object} paymentMethodData Arbitrary data
* to be passed
* along for
* processing by
* the payment
* method on the
* server.
* @property {string} errorMessage An error
* message provided
* by the payment
* method if there
* is an error.
* @property {string} activePaymentMethod The active
* payment method
* slug.
* @property {function()} setActivePaymentMethod A function for
* setting the
* active payment
* method.
* @property {function()} setBillingData A function for
* setting the
* billing data.
*/

/**
* @typedef {Object} CheckoutDataContext
*
* @property {string} submitLabel The label to use for
* the submit checkout
* button.
* @property {function()} onSubmit The callback to
* register with the
* checkout submit
* button.
* @property {boolean} isComplete True when checkout is
* complete and ready for
* redirect.
* @property {boolean} isIdle True when the checkout
* state has changed and
* checkout has no
* activity.
* @property {boolean} isProcessing True when checkout has
* been submitted and is
* being processed by the
* server.
* @property {boolean} isCalculating True when something in
* the checkout is
* resulting in totals
* being calculated.
* @property {boolean} hasError True when the checkout
* is in an error state.
* Whatever caused the
* error
* (validation/payment
* method) will likely
* have triggered a
* notice.
* @property {string} redirectUrl This is the url that
* checkout will redirect
* to when it's ready.
* @property {function()} onCheckoutCompleteSuccess Used to register a
* callback that will
* fire when the checkout
* is marked complete
* successfully.
* @property {function()} onCheckoutCompleteError Used to register
* a callback that will
* fire when the checkout
* is marked complete and
* has an error.
* @property {function()} onCheckoutProcessing Used to register a
* callback that will
* fire when the checkout
* has been submitted
* before being sent off
* to the server.
* @property {CheckoutDispatchActions} dispatchActions Various actions that
* can be dispatched for
* the checkout context
* data.
*/

export {};
56 changes: 56 additions & 0 deletions assets/js/type-defs/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @typedef {Object} WooCommerceSiteCurrency
*
* @property {string} code The ISO code for the currency.
* @property {number} precision The precision (decimal places).
* @property {string} symbol The symbol for the currency (eg '$')
* @property {string} symbolPosition The position for the symbol ('left',
* or 'right')
* @property {string} decimalSeparator The string used for the decimal
* separator.
* @property {string} thousandSeparator The string used for the thousands
* separator.
* @property {string} priceFormat The format string use for displaying
* an amount in this currency.
*/

/**
* @typedef {Object} WooCommerceSiteLocale
*
* @property {string} siteLocale The locale string for the current
* site.
* @property {string} userLocale The locale string for the current
* user.
* @property {Array<string>} weekdaysShort An array of short weekday strings
* in the current user's locale.
*/

/**
* @typedef {Object} WooCommerceSharedSettings
*
* @property {string} adminUrl The url for the current
* site's dashboard.
* @property {Object} countries An object of countries
* where the keys are
* Country codes and values
* are country names
* localized for the site's
* current language.
* @property {WooCommerceSiteCurrency} currency The current site
* currency object.
* @property {string} defaultDateRange The default date range
* query string to use.
* @property {WooCommerceSiteLocale} locale Locale information for
* the site.
* @property {Object} orderStatuses An object of order
* statuses indexed by
* status key and localized
* status value.
* @property {string} siteTitle The current title of the
* site.
* @property {string} wcAssetUrl The url to the assets
* directory for the
* WooCommerce plugin.
*/

export {};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"assets/js/base/atomic/components/*"
],
"@woocommerce/base-components/*": [ "assets/js/base/components/*" ],
"@woocommerce/base-context/*": [ "assets/js/base/context/*" ],
"@woocommerce/base-context": [ "assets/js/base/context" ],
"@woocommerce/base-hocs/*": [ "assets/js/base/hocs/*" ],
"@woocommerce/base-hooks": [ "assets/js/base/hooks" ],
"@woocommerce/base-utils": [ "assets/js/base/utils" ],
Expand Down

0 comments on commit 2e9bf11

Please sign in to comment.