spree_core 3.6.6 → 3.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree.js +60 -0
- data/app/finders/spree/countries/find.rb +31 -0
- data/app/finders/spree/credit_cards/find.rb +12 -0
- data/app/finders/spree/line_items/find_by_variant.rb +13 -0
- data/app/finders/spree/orders/find_current.rb +34 -0
- data/app/finders/spree/products/find.rb +93 -0
- data/app/finders/spree/taxons/find.rb +79 -0
- data/app/helpers/spree/base_helper.rb +7 -3
- data/app/helpers/spree/products_helper.rb +2 -1
- data/app/models/concerns/spree/adjustment_source.rb +11 -6
- data/app/models/concerns/spree/user_address.rb +2 -2
- data/app/models/concerns/spree/vat_price_calculation.rb +2 -1
- data/app/models/spree/ability.rb +2 -2
- data/app/models/spree/address.rb +23 -14
- data/app/models/spree/adjustable/adjustments_updater.rb +1 -1
- data/app/models/spree/adjustable/promotion_accumulator.rb +2 -1
- data/app/models/spree/adjustment.rb +18 -3
- data/app/models/spree/asset/support/active_storage.rb +1 -1
- data/app/models/spree/calculator.rb +1 -4
- data/app/models/spree/calculator/flexi_rate.rb +8 -11
- data/app/models/spree/calculator/returns/default_refund_amount.rb +3 -1
- data/app/models/spree/calculator/shipping/flexi_rate.rb +13 -13
- data/app/models/spree/country.rb +4 -0
- data/app/models/spree/credit_card.rb +8 -2
- data/app/models/spree/customer_return.rb +1 -0
- data/app/models/spree/fulfilment_changer.rb +117 -0
- data/app/models/spree/gateway.rb +1 -0
- data/app/models/spree/gateway/bogus.rb +3 -2
- data/app/models/spree/image.rb +13 -0
- data/app/models/spree/image/configuration/active_storage.rb +3 -3
- data/app/models/spree/inventory_unit.rb +1 -1
- data/app/models/spree/line_item.rb +3 -2
- data/app/models/spree/order.rb +72 -28
- data/app/models/spree/order/checkout.rb +10 -0
- data/app/models/spree/order/store_credit.rb +14 -35
- data/app/models/spree/order_contents.rb +22 -118
- data/app/models/spree/order_inventory.rb +6 -2
- data/app/models/spree/order_merger.rb +1 -3
- data/app/models/spree/order_promotion.rb +10 -0
- data/app/models/spree/order_updater.rb +11 -8
- data/app/models/spree/payment.rb +9 -3
- data/app/models/spree/payment/processing.rb +4 -4
- data/app/models/spree/preferences/store.rb +3 -3
- data/app/models/spree/product.rb +32 -0
- data/app/models/spree/product/scopes.rb +13 -34
- data/app/models/spree/product_property.rb +1 -1
- data/app/models/spree/promotion.rb +2 -0
- data/app/models/spree/promotion/actions/create_adjustment.rb +6 -1
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +10 -2
- data/app/models/spree/promotion/actions/create_line_items.rb +3 -2
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
- data/app/models/spree/promotion/rules/item_total.rb +2 -2
- data/app/models/spree/promotion_handler/coupon.rb +10 -6
- data/app/models/spree/promotion_handler/page.rb +1 -1
- data/app/models/spree/promotion_handler/promotion_duplicator.rb +4 -4
- data/app/models/spree/refund.rb +1 -1
- data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -0
- data/app/models/spree/reimbursement_tax_calculator.rb +2 -2
- data/app/models/spree/return_item.rb +7 -4
- data/app/models/spree/return_item/eligibility_validator/default.rb +6 -6
- data/app/models/spree/return_item/exchange_variant_eligibility/same_product.rb +1 -1
- data/app/models/spree/shipment.rb +27 -34
- data/app/models/spree/shipping_method.rb +2 -0
- data/app/models/spree/shipping_rate.rb +31 -16
- data/app/models/spree/stock/adjuster.rb +1 -0
- data/app/models/spree/stock/estimator.rb +2 -0
- data/app/models/spree/stock/inventory_unit_builder.rb +5 -5
- data/app/models/spree/stock/packer.rb +1 -0
- data/app/models/spree/stock/quantifier.rb +16 -4
- data/app/models/spree/stock_item.rb +1 -0
- data/app/models/spree/stock_location.rb +1 -1
- data/app/models/spree/stock_movement.rb +1 -0
- data/app/models/spree/stock_transfer.rb +1 -1
- data/app/models/spree/store_credit.rb +5 -10
- data/app/models/spree/tax_rate.rb +3 -0
- data/app/models/spree/taxon.rb +2 -2
- data/app/models/spree/taxon_image.rb +18 -0
- data/app/models/spree/{taxon_icon → taxon_image}/configuration/active_storage.rb +2 -2
- data/app/models/spree/{taxon_icon → taxon_image}/configuration/paperclip.rb +1 -1
- data/app/models/spree/variant.rb +28 -2
- data/app/models/spree/zone.rb +5 -5
- data/app/paginators/spree/shared/paginate.rb +19 -0
- data/app/services/spree/cart/add_item.rb +43 -0
- data/app/services/spree/cart/create.rb +21 -0
- data/app/services/spree/cart/recalculate.rb +32 -0
- data/app/services/spree/cart/remove_item.rb +37 -0
- data/app/services/spree/cart/remove_line_item.rb +16 -0
- data/app/services/spree/cart/set_quantity.rb +22 -0
- data/app/services/spree/cart/update.rb +37 -0
- data/app/services/spree/checkout/add_store_credit.rb +51 -0
- data/app/services/spree/checkout/advance.rb +18 -0
- data/app/services/spree/checkout/complete.rb +23 -0
- data/app/services/spree/checkout/get_shipping_rates.rb +48 -0
- data/app/services/spree/checkout/next.rb +13 -0
- data/app/services/spree/checkout/remove_store_credit.rb +17 -0
- data/app/services/spree/checkout/update.rb +13 -0
- data/app/services/spree/compare_line_items.rb +21 -0
- data/app/services/spree/generate_token.rb +20 -0
- data/app/sorters/spree/products/sort.rb +58 -0
- data/config/locales/en.yml +20 -1
- data/db/default/spree/countries.rb +1 -1
- data/db/default/spree/default_reimbursement_type.rb +1 -1
- data/db/default/spree/roles.rb +2 -2
- data/db/default/spree/states.rb +2 -1
- data/db/default/spree/stores.rb +1 -1
- data/db/default/spree/zones.rb +5 -6
- data/db/migrate/20120831092320_spree_one_two.rb +36 -36
- data/db/migrate/20120831092359_spree_promo_one_two.rb +1 -1
- data/db/migrate/20130211190146_create_spree_stock_items.rb +1 -1
- data/db/migrate/20130211191120_create_spree_stock_locations.rb +1 -1
- data/db/migrate/20130301162924_create_shipping_method_categories.rb +1 -1
- data/db/migrate/20130304162240_create_spree_shipping_rates.rb +1 -1
- data/db/migrate/20130305143310_create_stock_movements.rb +1 -1
- data/db/migrate/20130418125341_create_spree_stock_transfers.rb +1 -1
- data/db/migrate/20140205120320_create_spree_payment_capture_events.rb +1 -1
- data/db/migrate/20140309023735_migrate_old_preferences.rb +5 -1
- data/db/migrate/20140309024355_create_spree_stores.rb +1 -1
- data/db/migrate/20140625214618_create_spree_refunds.rb +1 -1
- data/db/migrate/20140702140656_create_spree_return_authorization_inventory_unit.rb +1 -1
- data/db/migrate/20140713140455_create_spree_return_authorization_reasons.rb +1 -1
- data/db/migrate/20140713140527_create_spree_refund_reasons.rb +1 -1
- data/db/migrate/20140715182625_create_spree_promotion_categories.rb +1 -1
- data/db/migrate/20140718133010_create_spree_customer_returns.rb +1 -1
- data/db/migrate/20140725131539_create_spree_reimbursements.rb +1 -1
- data/db/migrate/20140731150017_create_spree_reimbursement_types.rb +1 -1
- data/db/migrate/20150118210639_create_spree_store_credits.rb +1 -1
- data/db/migrate/20150118211500_create_spree_store_credit_categories.rb +1 -1
- data/db/migrate/20150118212051_create_spree_store_credit_events.rb +1 -1
- data/db/migrate/20150118212101_create_spree_store_credit_types.rb +1 -1
- data/db/migrate/20150309161154_ensure_payments_have_numbers.rb +6 -2
- data/db/migrate/20180613080857_rename_guest_token_to_token_in_orders.rb +5 -0
- data/db/migrate/20180915160001_add_timestamps_to_spree_prices.rb +12 -0
- data/db/migrate/20181024100754_add_deleted_at_to_spree_credit_cards.rb +6 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +1 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +30 -33
- data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
- data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
- data/lib/generators/spree/dummy_model/dummy_model_generator.rb +1 -1
- data/lib/generators/spree/install/install_generator.rb +2 -1
- data/lib/spree/core.rb +2 -4
- data/lib/spree/core/controller_helpers/auth.rb +15 -5
- data/lib/spree/core/controller_helpers/common.rb +0 -11
- data/lib/spree/core/controller_helpers/order.rb +6 -6
- data/lib/spree/core/controller_helpers/respond_with.rb +3 -1
- data/lib/spree/core/controller_helpers/strong_parameters.rb +1 -0
- data/lib/spree/core/engine.rb +9 -3
- data/lib/spree/core/importer/order.rb +8 -12
- data/lib/spree/core/product_duplicator.rb +6 -1
- data/lib/spree/core/product_filters.rb +15 -14
- data/lib/spree/core/query_filters.rb +11 -0
- data/lib/spree/core/query_filters/comparable.rb +46 -0
- data/lib/spree/core/query_filters/date.rb +8 -0
- data/lib/spree/core/query_filters/number.rb +8 -0
- data/lib/spree/core/query_filters/text.rb +32 -0
- data/lib/spree/core/token_generator.rb +2 -2
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/i18n.rb +1 -1
- data/lib/spree/migrations.rb +2 -0
- data/lib/spree/money.rb +12 -12
- data/lib/spree/permitted_attributes.rb +11 -6
- data/lib/spree/service_module.rb +98 -0
- data/lib/spree/testing_support/capybara_config.rb +20 -0
- data/lib/spree/testing_support/capybara_ext.rb +6 -3
- data/lib/spree/testing_support/factories.rb +1 -1
- data/lib/spree/testing_support/factories/address_factory.rb +10 -9
- data/lib/spree/testing_support/factories/adjustment_factory.rb +8 -6
- data/lib/spree/testing_support/factories/country_factory.rb +4 -4
- data/lib/spree/testing_support/factories/credit_card_factory.rb +7 -5
- data/lib/spree/testing_support/factories/customer_return_factory.rb +1 -1
- data/lib/spree/testing_support/factories/image_factory.rb +7 -1
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +5 -4
- data/lib/spree/testing_support/factories/line_item_factory.rb +3 -2
- data/lib/spree/testing_support/factories/options_factory.rb +2 -3
- data/lib/spree/testing_support/factories/order_factory.rb +16 -12
- data/lib/spree/testing_support/factories/order_promotion_factory.rb +6 -0
- data/lib/spree/testing_support/factories/payment_factory.rb +9 -7
- data/lib/spree/testing_support/factories/payment_method_factory.rb +8 -8
- data/lib/spree/testing_support/factories/price_factory.rb +2 -2
- data/lib/spree/testing_support/factories/product_factory.rb +10 -10
- data/lib/spree/testing_support/factories/promotion_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +14 -4
- data/lib/spree/testing_support/factories/property_factory.rb +2 -2
- data/lib/spree/testing_support/factories/prototype_factory.rb +3 -3
- data/lib/spree/testing_support/factories/refund_factory.rb +6 -6
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +2 -2
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +4 -3
- data/lib/spree/testing_support/factories/role_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipment_factory.rb +3 -3
- data/lib/spree/testing_support/factories/shipping_method_factory.rb +4 -4
- data/lib/spree/testing_support/factories/state_factory.rb +2 -5
- data/lib/spree/testing_support/factories/stock_factory.rb +3 -3
- data/lib/spree/testing_support/factories/stock_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_location_factory.rb +7 -7
- data/lib/spree/testing_support/factories/stock_movement_factory.rb +3 -3
- data/lib/spree/testing_support/factories/store_credit_category_factory.rb +2 -2
- data/lib/spree/testing_support/factories/store_credit_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_factory.rb +5 -4
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +2 -1
- data/lib/spree/testing_support/factories/user_factory.rb +4 -4
- data/lib/spree/testing_support/factories/variant_factory.rb +15 -15
- data/lib/spree/testing_support/factories/zone_factory.rb +3 -3
- data/lib/spree/testing_support/image_helpers.rb +19 -0
- data/lib/tasks/core.rake +21 -4
- data/lib/tasks/exchanges.rake +4 -4
- data/spree_core.gemspec +3 -3
- data/vendor/assets/javascripts/fetch.umd.js +531 -0
- data/vendor/assets/javascripts/polyfill.min.js +1 -0
- metadata +50 -17
- data/app/assets/javascripts/spree.js.coffee +0 -59
- data/app/models/spree/taxon_icon.rb +0 -5
- data/lib/generators/spree/dummy/templates/initializers/custom_user.rb +0 -1
- data/lib/spree/core/environment.rb +0 -15
- data/lib/spree/core/environment/calculators.rb +0 -11
- data/lib/spree/core/environment_extension.rb +0 -28
- data/lib/spree/core/validators/email.rb +0 -8
- data/lib/spree/promo/environment.rb +0 -9
@@ -1,22 +1,22 @@
|
|
1
1
|
FactoryBot.define do
|
2
|
-
sequence(:random_float) { BigDecimal
|
2
|
+
sequence(:random_float) { BigDecimal("#{rand(200)}.#{rand(99)}") }
|
3
3
|
|
4
4
|
factory :base_variant, class: Spree::Variant do
|
5
|
-
price 19.99
|
6
|
-
cost_price 17.00
|
7
|
-
sku
|
8
|
-
weight
|
9
|
-
height
|
10
|
-
width
|
11
|
-
depth
|
12
|
-
is_master 0
|
13
|
-
track_inventory true
|
5
|
+
price { 19.99 }
|
6
|
+
cost_price { 17.00 }
|
7
|
+
sku { generate(:sku) }
|
8
|
+
weight { generate(:random_float) }
|
9
|
+
height { generate(:random_float) }
|
10
|
+
width { generate(:random_float) }
|
11
|
+
depth { generate(:random_float) }
|
12
|
+
is_master { 0 }
|
13
|
+
track_inventory { true }
|
14
14
|
|
15
|
-
product
|
15
|
+
product { |p| p.association(:base_product) }
|
16
16
|
option_values { [create(:option_value)] }
|
17
17
|
|
18
18
|
# ensure stock item will be created for this variant
|
19
|
-
before(:create) { create(:stock_location)
|
19
|
+
before(:create) { create(:stock_location) unless Spree::StockLocation.any? }
|
20
20
|
|
21
21
|
factory :variant do
|
22
22
|
# on_hand 5
|
@@ -24,14 +24,14 @@ FactoryBot.define do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
factory :master_variant do
|
27
|
-
is_master 1
|
27
|
+
is_master { 1 }
|
28
28
|
end
|
29
29
|
|
30
30
|
factory :on_demand_variant do
|
31
|
-
track_inventory false
|
31
|
+
track_inventory { false }
|
32
32
|
|
33
33
|
factory :on_demand_master_variant do
|
34
|
-
is_master 1
|
34
|
+
is_master { 1 }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :global_zone, class: Spree::Zone do
|
3
|
-
name 'GlobalZone'
|
3
|
+
name { 'GlobalZone' }
|
4
4
|
description { generate(:random_string) }
|
5
5
|
zone_members do |proxy|
|
6
6
|
zone = proxy.instance_eval { @instance }
|
7
7
|
Spree::Country.all.map do |c|
|
8
|
-
|
8
|
+
Spree::ZoneMember.create(zoneable: c, zone: zone)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
factory :zone, class: Spree::Zone do
|
14
|
-
name
|
14
|
+
name { generate(:random_string) }
|
15
15
|
description { generate(:random_string) }
|
16
16
|
|
17
17
|
factory :zone_with_country do
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module TestingSupport
|
3
|
+
module ImageHelpers
|
4
|
+
def create_image(attachable, file)
|
5
|
+
# user paperclip to attach an image
|
6
|
+
if Rails.application.config.use_paperclip
|
7
|
+
attachable.images.create!(attachment: file)
|
8
|
+
# use ActiveStorage (default)
|
9
|
+
else
|
10
|
+
image = attachable.images.new
|
11
|
+
image.attachment.attach(io: file, filename: File.basename(file))
|
12
|
+
image.save!
|
13
|
+
file.rewind
|
14
|
+
image
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/tasks/core.rake
CHANGED
@@ -73,16 +73,14 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]}
|
|
73
73
|
ActiveRecord::Base.send(:subclasses).each(&:reset_column_information)
|
74
74
|
|
75
75
|
load_defaults = Spree::Country.count == 0
|
76
|
-
|
77
|
-
load_defaults = agree('Countries present, load sample data anyways? [y/n]: ')
|
78
|
-
end
|
76
|
+
load_defaults ||= agree('Countries present, load sample data anyways? [y/n]: ')
|
79
77
|
Rake::Task['db:seed'].invoke if load_defaults
|
80
78
|
|
81
79
|
if Rails.env.production? && Spree::Product.count > 0
|
82
80
|
load_sample = agree('WARNING: In Production and products exist in database, load sample data anyways? [y/n]:')
|
83
81
|
else
|
84
82
|
load_sample = true if ENV['AUTO_ACCEPT']
|
85
|
-
load_sample
|
83
|
+
load_sample ||= agree('Load Sample Data? [y/n]: ')
|
86
84
|
end
|
87
85
|
|
88
86
|
if load_sample
|
@@ -167,4 +165,23 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]}
|
|
167
165
|
attachment_updated_at: taxon.icon_updated_at)
|
168
166
|
end
|
169
167
|
end
|
168
|
+
|
169
|
+
desc 'Migrates taxon icons to taxon images after upgrading to Spree 3.7: only needed if you used taxons icons.'
|
170
|
+
task migrate_taxon_icons_to_images: :environment do |_t, _args|
|
171
|
+
Spree::Asset.where(type: 'Spree::TaxonIcon').update_all(type: 'Spree::TaxonImage')
|
172
|
+
end
|
173
|
+
|
174
|
+
desc 'Ensure all Order associated with Store after upgrading to Spree 3.7'
|
175
|
+
task associate_orders_with_store: :environment do |_t, _args|
|
176
|
+
Spree::Order.where(store_id: nil).update_all(store_id: Spree::Store.default.id)
|
177
|
+
end
|
178
|
+
|
179
|
+
desc 'Ensure all Order has currency present after upgrading to Spree 3.7'
|
180
|
+
task ensure_order_currency_presence: :environment do |_t, _args|
|
181
|
+
Spree::Order.where(currency: nil).find_in_batches do |orders|
|
182
|
+
orders.each do |order|
|
183
|
+
order.update!(currency: order.store.default_currency || Spree::Config[:currency])
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
170
187
|
end
|
data/lib/tasks/exchanges.rake
CHANGED
@@ -4,9 +4,9 @@ namespace :exchanges do
|
|
4
4
|
task charge_unreturned_items: :environment do
|
5
5
|
unreturned_return_items_scope = Spree::ReturnItem.awaiting_return.exchange_processed
|
6
6
|
unreturned_return_items = unreturned_return_items_scope.joins(:exchange_inventory_units).where([
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
'spree_inventory_units.created_at < :days_ago AND spree_inventory_units.state = :iu_state',
|
8
|
+
days_ago: Spree::Config[:expedited_exchanges_days_window].days.ago, iu_state: 'shipped'
|
9
|
+
]).distinct.to_a
|
10
10
|
|
11
11
|
# Determine that a return item has already been deemed unreturned and therefore charged
|
12
12
|
# by the fact that its exchange inventory unit has popped off to a different order
|
@@ -56,7 +56,7 @@ namespace :exchanges do
|
|
56
56
|
order.finalize!
|
57
57
|
|
58
58
|
failed_orders << order unless order.completed? && order.valid?
|
59
|
-
rescue
|
59
|
+
rescue StandardError
|
60
60
|
failed_orders << order
|
61
61
|
end
|
62
62
|
end
|
data/spree_core.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.summary = 'The bare bones necessary for Spree.'
|
10
10
|
s.description = 'The bare bones necessary for Spree.'
|
11
11
|
|
12
|
-
s.required_ruby_version = '>= 2.
|
12
|
+
s.required_ruby_version = '>= 2.3.0'
|
13
13
|
s.required_rubygems_version = '>= 1.8.23'
|
14
14
|
|
15
15
|
s.author = 'Sean Schofield'
|
@@ -28,11 +28,11 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_dependency 'deface', '~> 1.0'
|
29
29
|
s.add_dependency 'ffaker', '~> 2.2'
|
30
30
|
s.add_dependency 'friendly_id', '~> 5.2.1'
|
31
|
-
s.add_dependency 'highline', '~>
|
31
|
+
s.add_dependency 'highline', '~> 2.0.0' # Necessary for the install generator
|
32
32
|
s.add_dependency 'kaminari', '~> 1.0.1'
|
33
33
|
s.add_dependency 'money', '~> 6.13'
|
34
34
|
s.add_dependency 'monetize', '~> 1.9'
|
35
|
-
s.add_dependency 'paperclip', '~> 6.
|
35
|
+
s.add_dependency 'paperclip', '~> 6.1.0'
|
36
36
|
s.add_dependency 'paranoia', '~> 2.4.1'
|
37
37
|
s.add_dependency 'premailer-rails'
|
38
38
|
s.add_dependency 'acts-as-taggable-on', '~> 6.0'
|
@@ -0,0 +1,531 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
4
|
+
(factory((global.WHATWGFetch = {})));
|
5
|
+
}(this, (function (exports) { 'use strict';
|
6
|
+
|
7
|
+
var support = {
|
8
|
+
searchParams: 'URLSearchParams' in self,
|
9
|
+
iterable: 'Symbol' in self && 'iterator' in Symbol,
|
10
|
+
blob:
|
11
|
+
'FileReader' in self &&
|
12
|
+
'Blob' in self &&
|
13
|
+
(function() {
|
14
|
+
try {
|
15
|
+
new Blob();
|
16
|
+
return true
|
17
|
+
} catch (e) {
|
18
|
+
return false
|
19
|
+
}
|
20
|
+
})(),
|
21
|
+
formData: 'FormData' in self,
|
22
|
+
arrayBuffer: 'ArrayBuffer' in self
|
23
|
+
};
|
24
|
+
|
25
|
+
function isDataView(obj) {
|
26
|
+
return obj && DataView.prototype.isPrototypeOf(obj)
|
27
|
+
}
|
28
|
+
|
29
|
+
if (support.arrayBuffer) {
|
30
|
+
var viewClasses = [
|
31
|
+
'[object Int8Array]',
|
32
|
+
'[object Uint8Array]',
|
33
|
+
'[object Uint8ClampedArray]',
|
34
|
+
'[object Int16Array]',
|
35
|
+
'[object Uint16Array]',
|
36
|
+
'[object Int32Array]',
|
37
|
+
'[object Uint32Array]',
|
38
|
+
'[object Float32Array]',
|
39
|
+
'[object Float64Array]'
|
40
|
+
];
|
41
|
+
|
42
|
+
var isArrayBufferView =
|
43
|
+
ArrayBuffer.isView ||
|
44
|
+
function(obj) {
|
45
|
+
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
|
46
|
+
};
|
47
|
+
}
|
48
|
+
|
49
|
+
function normalizeName(name) {
|
50
|
+
if (typeof name !== 'string') {
|
51
|
+
name = String(name);
|
52
|
+
}
|
53
|
+
if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
|
54
|
+
throw new TypeError('Invalid character in header field name')
|
55
|
+
}
|
56
|
+
return name.toLowerCase()
|
57
|
+
}
|
58
|
+
|
59
|
+
function normalizeValue(value) {
|
60
|
+
if (typeof value !== 'string') {
|
61
|
+
value = String(value);
|
62
|
+
}
|
63
|
+
return value
|
64
|
+
}
|
65
|
+
|
66
|
+
// Build a destructive iterator for the value list
|
67
|
+
function iteratorFor(items) {
|
68
|
+
var iterator = {
|
69
|
+
next: function() {
|
70
|
+
var value = items.shift();
|
71
|
+
return {done: value === undefined, value: value}
|
72
|
+
}
|
73
|
+
};
|
74
|
+
|
75
|
+
if (support.iterable) {
|
76
|
+
iterator[Symbol.iterator] = function() {
|
77
|
+
return iterator
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
81
|
+
return iterator
|
82
|
+
}
|
83
|
+
|
84
|
+
function Headers(headers) {
|
85
|
+
this.map = {};
|
86
|
+
|
87
|
+
if (headers instanceof Headers) {
|
88
|
+
headers.forEach(function(value, name) {
|
89
|
+
this.append(name, value);
|
90
|
+
}, this);
|
91
|
+
} else if (Array.isArray(headers)) {
|
92
|
+
headers.forEach(function(header) {
|
93
|
+
this.append(header[0], header[1]);
|
94
|
+
}, this);
|
95
|
+
} else if (headers) {
|
96
|
+
Object.getOwnPropertyNames(headers).forEach(function(name) {
|
97
|
+
this.append(name, headers[name]);
|
98
|
+
}, this);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
Headers.prototype.append = function(name, value) {
|
103
|
+
name = normalizeName(name);
|
104
|
+
value = normalizeValue(value);
|
105
|
+
var oldValue = this.map[name];
|
106
|
+
this.map[name] = oldValue ? oldValue + ', ' + value : value;
|
107
|
+
};
|
108
|
+
|
109
|
+
Headers.prototype['delete'] = function(name) {
|
110
|
+
delete this.map[normalizeName(name)];
|
111
|
+
};
|
112
|
+
|
113
|
+
Headers.prototype.get = function(name) {
|
114
|
+
name = normalizeName(name);
|
115
|
+
return this.has(name) ? this.map[name] : null
|
116
|
+
};
|
117
|
+
|
118
|
+
Headers.prototype.has = function(name) {
|
119
|
+
return this.map.hasOwnProperty(normalizeName(name))
|
120
|
+
};
|
121
|
+
|
122
|
+
Headers.prototype.set = function(name, value) {
|
123
|
+
this.map[normalizeName(name)] = normalizeValue(value);
|
124
|
+
};
|
125
|
+
|
126
|
+
Headers.prototype.forEach = function(callback, thisArg) {
|
127
|
+
for (var name in this.map) {
|
128
|
+
if (this.map.hasOwnProperty(name)) {
|
129
|
+
callback.call(thisArg, this.map[name], name, this);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
};
|
133
|
+
|
134
|
+
Headers.prototype.keys = function() {
|
135
|
+
var items = [];
|
136
|
+
this.forEach(function(value, name) {
|
137
|
+
items.push(name);
|
138
|
+
});
|
139
|
+
return iteratorFor(items)
|
140
|
+
};
|
141
|
+
|
142
|
+
Headers.prototype.values = function() {
|
143
|
+
var items = [];
|
144
|
+
this.forEach(function(value) {
|
145
|
+
items.push(value);
|
146
|
+
});
|
147
|
+
return iteratorFor(items)
|
148
|
+
};
|
149
|
+
|
150
|
+
Headers.prototype.entries = function() {
|
151
|
+
var items = [];
|
152
|
+
this.forEach(function(value, name) {
|
153
|
+
items.push([name, value]);
|
154
|
+
});
|
155
|
+
return iteratorFor(items)
|
156
|
+
};
|
157
|
+
|
158
|
+
if (support.iterable) {
|
159
|
+
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
|
160
|
+
}
|
161
|
+
|
162
|
+
function consumed(body) {
|
163
|
+
if (body.bodyUsed) {
|
164
|
+
return Promise.reject(new TypeError('Already read'))
|
165
|
+
}
|
166
|
+
body.bodyUsed = true;
|
167
|
+
}
|
168
|
+
|
169
|
+
function fileReaderReady(reader) {
|
170
|
+
return new Promise(function(resolve, reject) {
|
171
|
+
reader.onload = function() {
|
172
|
+
resolve(reader.result);
|
173
|
+
};
|
174
|
+
reader.onerror = function() {
|
175
|
+
reject(reader.error);
|
176
|
+
};
|
177
|
+
})
|
178
|
+
}
|
179
|
+
|
180
|
+
function readBlobAsArrayBuffer(blob) {
|
181
|
+
var reader = new FileReader();
|
182
|
+
var promise = fileReaderReady(reader);
|
183
|
+
reader.readAsArrayBuffer(blob);
|
184
|
+
return promise
|
185
|
+
}
|
186
|
+
|
187
|
+
function readBlobAsText(blob) {
|
188
|
+
var reader = new FileReader();
|
189
|
+
var promise = fileReaderReady(reader);
|
190
|
+
reader.readAsText(blob);
|
191
|
+
return promise
|
192
|
+
}
|
193
|
+
|
194
|
+
function readArrayBufferAsText(buf) {
|
195
|
+
var view = new Uint8Array(buf);
|
196
|
+
var chars = new Array(view.length);
|
197
|
+
|
198
|
+
for (var i = 0; i < view.length; i++) {
|
199
|
+
chars[i] = String.fromCharCode(view[i]);
|
200
|
+
}
|
201
|
+
return chars.join('')
|
202
|
+
}
|
203
|
+
|
204
|
+
function bufferClone(buf) {
|
205
|
+
if (buf.slice) {
|
206
|
+
return buf.slice(0)
|
207
|
+
} else {
|
208
|
+
var view = new Uint8Array(buf.byteLength);
|
209
|
+
view.set(new Uint8Array(buf));
|
210
|
+
return view.buffer
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
function Body() {
|
215
|
+
this.bodyUsed = false;
|
216
|
+
|
217
|
+
this._initBody = function(body) {
|
218
|
+
this._bodyInit = body;
|
219
|
+
if (!body) {
|
220
|
+
this._bodyText = '';
|
221
|
+
} else if (typeof body === 'string') {
|
222
|
+
this._bodyText = body;
|
223
|
+
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
|
224
|
+
this._bodyBlob = body;
|
225
|
+
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
|
226
|
+
this._bodyFormData = body;
|
227
|
+
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
228
|
+
this._bodyText = body.toString();
|
229
|
+
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
|
230
|
+
this._bodyArrayBuffer = bufferClone(body.buffer);
|
231
|
+
// IE 10-11 can't handle a DataView body.
|
232
|
+
this._bodyInit = new Blob([this._bodyArrayBuffer]);
|
233
|
+
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
|
234
|
+
this._bodyArrayBuffer = bufferClone(body);
|
235
|
+
} else {
|
236
|
+
this._bodyText = body = Object.prototype.toString.call(body);
|
237
|
+
}
|
238
|
+
|
239
|
+
if (!this.headers.get('content-type')) {
|
240
|
+
if (typeof body === 'string') {
|
241
|
+
this.headers.set('content-type', 'text/plain;charset=UTF-8');
|
242
|
+
} else if (this._bodyBlob && this._bodyBlob.type) {
|
243
|
+
this.headers.set('content-type', this._bodyBlob.type);
|
244
|
+
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
245
|
+
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
|
246
|
+
}
|
247
|
+
}
|
248
|
+
};
|
249
|
+
|
250
|
+
if (support.blob) {
|
251
|
+
this.blob = function() {
|
252
|
+
var rejected = consumed(this);
|
253
|
+
if (rejected) {
|
254
|
+
return rejected
|
255
|
+
}
|
256
|
+
|
257
|
+
if (this._bodyBlob) {
|
258
|
+
return Promise.resolve(this._bodyBlob)
|
259
|
+
} else if (this._bodyArrayBuffer) {
|
260
|
+
return Promise.resolve(new Blob([this._bodyArrayBuffer]))
|
261
|
+
} else if (this._bodyFormData) {
|
262
|
+
throw new Error('could not read FormData body as blob')
|
263
|
+
} else {
|
264
|
+
return Promise.resolve(new Blob([this._bodyText]))
|
265
|
+
}
|
266
|
+
};
|
267
|
+
|
268
|
+
this.arrayBuffer = function() {
|
269
|
+
if (this._bodyArrayBuffer) {
|
270
|
+
return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
|
271
|
+
} else {
|
272
|
+
return this.blob().then(readBlobAsArrayBuffer)
|
273
|
+
}
|
274
|
+
};
|
275
|
+
}
|
276
|
+
|
277
|
+
this.text = function() {
|
278
|
+
var rejected = consumed(this);
|
279
|
+
if (rejected) {
|
280
|
+
return rejected
|
281
|
+
}
|
282
|
+
|
283
|
+
if (this._bodyBlob) {
|
284
|
+
return readBlobAsText(this._bodyBlob)
|
285
|
+
} else if (this._bodyArrayBuffer) {
|
286
|
+
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
|
287
|
+
} else if (this._bodyFormData) {
|
288
|
+
throw new Error('could not read FormData body as text')
|
289
|
+
} else {
|
290
|
+
return Promise.resolve(this._bodyText)
|
291
|
+
}
|
292
|
+
};
|
293
|
+
|
294
|
+
if (support.formData) {
|
295
|
+
this.formData = function() {
|
296
|
+
return this.text().then(decode)
|
297
|
+
};
|
298
|
+
}
|
299
|
+
|
300
|
+
this.json = function() {
|
301
|
+
return this.text().then(JSON.parse)
|
302
|
+
};
|
303
|
+
|
304
|
+
return this
|
305
|
+
}
|
306
|
+
|
307
|
+
// HTTP methods whose capitalization should be normalized
|
308
|
+
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
|
309
|
+
|
310
|
+
function normalizeMethod(method) {
|
311
|
+
var upcased = method.toUpperCase();
|
312
|
+
return methods.indexOf(upcased) > -1 ? upcased : method
|
313
|
+
}
|
314
|
+
|
315
|
+
function Request(input, options) {
|
316
|
+
options = options || {};
|
317
|
+
var body = options.body;
|
318
|
+
|
319
|
+
if (input instanceof Request) {
|
320
|
+
if (input.bodyUsed) {
|
321
|
+
throw new TypeError('Already read')
|
322
|
+
}
|
323
|
+
this.url = input.url;
|
324
|
+
this.credentials = input.credentials;
|
325
|
+
if (!options.headers) {
|
326
|
+
this.headers = new Headers(input.headers);
|
327
|
+
}
|
328
|
+
this.method = input.method;
|
329
|
+
this.mode = input.mode;
|
330
|
+
this.signal = input.signal;
|
331
|
+
if (!body && input._bodyInit != null) {
|
332
|
+
body = input._bodyInit;
|
333
|
+
input.bodyUsed = true;
|
334
|
+
}
|
335
|
+
} else {
|
336
|
+
this.url = String(input);
|
337
|
+
}
|
338
|
+
|
339
|
+
this.credentials = options.credentials || this.credentials || 'same-origin';
|
340
|
+
if (options.headers || !this.headers) {
|
341
|
+
this.headers = new Headers(options.headers);
|
342
|
+
}
|
343
|
+
this.method = normalizeMethod(options.method || this.method || 'GET');
|
344
|
+
this.mode = options.mode || this.mode || null;
|
345
|
+
this.signal = options.signal || this.signal;
|
346
|
+
this.referrer = null;
|
347
|
+
|
348
|
+
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
|
349
|
+
throw new TypeError('Body not allowed for GET or HEAD requests')
|
350
|
+
}
|
351
|
+
this._initBody(body);
|
352
|
+
}
|
353
|
+
|
354
|
+
Request.prototype.clone = function() {
|
355
|
+
return new Request(this, {body: this._bodyInit})
|
356
|
+
};
|
357
|
+
|
358
|
+
function decode(body) {
|
359
|
+
var form = new FormData();
|
360
|
+
body
|
361
|
+
.trim()
|
362
|
+
.split('&')
|
363
|
+
.forEach(function(bytes) {
|
364
|
+
if (bytes) {
|
365
|
+
var split = bytes.split('=');
|
366
|
+
var name = split.shift().replace(/\+/g, ' ');
|
367
|
+
var value = split.join('=').replace(/\+/g, ' ');
|
368
|
+
form.append(decodeURIComponent(name), decodeURIComponent(value));
|
369
|
+
}
|
370
|
+
});
|
371
|
+
return form
|
372
|
+
}
|
373
|
+
|
374
|
+
function parseHeaders(rawHeaders) {
|
375
|
+
var headers = new Headers();
|
376
|
+
// Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
|
377
|
+
// https://tools.ietf.org/html/rfc7230#section-3.2
|
378
|
+
var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
|
379
|
+
preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
|
380
|
+
var parts = line.split(':');
|
381
|
+
var key = parts.shift().trim();
|
382
|
+
if (key) {
|
383
|
+
var value = parts.join(':').trim();
|
384
|
+
headers.append(key, value);
|
385
|
+
}
|
386
|
+
});
|
387
|
+
return headers
|
388
|
+
}
|
389
|
+
|
390
|
+
Body.call(Request.prototype);
|
391
|
+
|
392
|
+
function Response(bodyInit, options) {
|
393
|
+
if (!options) {
|
394
|
+
options = {};
|
395
|
+
}
|
396
|
+
|
397
|
+
this.type = 'default';
|
398
|
+
this.status = options.status === undefined ? 200 : options.status;
|
399
|
+
this.ok = this.status >= 200 && this.status < 300;
|
400
|
+
this.statusText = 'statusText' in options ? options.statusText : 'OK';
|
401
|
+
this.headers = new Headers(options.headers);
|
402
|
+
this.url = options.url || '';
|
403
|
+
this._initBody(bodyInit);
|
404
|
+
}
|
405
|
+
|
406
|
+
Body.call(Response.prototype);
|
407
|
+
|
408
|
+
Response.prototype.clone = function() {
|
409
|
+
return new Response(this._bodyInit, {
|
410
|
+
status: this.status,
|
411
|
+
statusText: this.statusText,
|
412
|
+
headers: new Headers(this.headers),
|
413
|
+
url: this.url
|
414
|
+
})
|
415
|
+
};
|
416
|
+
|
417
|
+
Response.error = function() {
|
418
|
+
var response = new Response(null, {status: 0, statusText: ''});
|
419
|
+
response.type = 'error';
|
420
|
+
return response
|
421
|
+
};
|
422
|
+
|
423
|
+
var redirectStatuses = [301, 302, 303, 307, 308];
|
424
|
+
|
425
|
+
Response.redirect = function(url, status) {
|
426
|
+
if (redirectStatuses.indexOf(status) === -1) {
|
427
|
+
throw new RangeError('Invalid status code')
|
428
|
+
}
|
429
|
+
|
430
|
+
return new Response(null, {status: status, headers: {location: url}})
|
431
|
+
};
|
432
|
+
|
433
|
+
exports.DOMException = self.DOMException;
|
434
|
+
try {
|
435
|
+
new exports.DOMException();
|
436
|
+
} catch (err) {
|
437
|
+
exports.DOMException = function(message, name) {
|
438
|
+
this.message = message;
|
439
|
+
this.name = name;
|
440
|
+
var error = Error(message);
|
441
|
+
this.stack = error.stack;
|
442
|
+
};
|
443
|
+
exports.DOMException.prototype = Object.create(Error.prototype);
|
444
|
+
exports.DOMException.prototype.constructor = exports.DOMException;
|
445
|
+
}
|
446
|
+
|
447
|
+
function fetch(input, init) {
|
448
|
+
return new Promise(function(resolve, reject) {
|
449
|
+
var request = new Request(input, init);
|
450
|
+
|
451
|
+
if (request.signal && request.signal.aborted) {
|
452
|
+
return reject(new exports.DOMException('Aborted', 'AbortError'))
|
453
|
+
}
|
454
|
+
|
455
|
+
var xhr = new XMLHttpRequest();
|
456
|
+
|
457
|
+
function abortXhr() {
|
458
|
+
xhr.abort();
|
459
|
+
}
|
460
|
+
|
461
|
+
xhr.onload = function() {
|
462
|
+
var options = {
|
463
|
+
status: xhr.status,
|
464
|
+
statusText: xhr.statusText,
|
465
|
+
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
|
466
|
+
};
|
467
|
+
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
|
468
|
+
var body = 'response' in xhr ? xhr.response : xhr.responseText;
|
469
|
+
resolve(new Response(body, options));
|
470
|
+
};
|
471
|
+
|
472
|
+
xhr.onerror = function() {
|
473
|
+
reject(new TypeError('Network request failed'));
|
474
|
+
};
|
475
|
+
|
476
|
+
xhr.ontimeout = function() {
|
477
|
+
reject(new TypeError('Network request failed'));
|
478
|
+
};
|
479
|
+
|
480
|
+
xhr.onabort = function() {
|
481
|
+
reject(new exports.DOMException('Aborted', 'AbortError'));
|
482
|
+
};
|
483
|
+
|
484
|
+
xhr.open(request.method, request.url, true);
|
485
|
+
|
486
|
+
if (request.credentials === 'include') {
|
487
|
+
xhr.withCredentials = true;
|
488
|
+
} else if (request.credentials === 'omit') {
|
489
|
+
xhr.withCredentials = false;
|
490
|
+
}
|
491
|
+
|
492
|
+
if ('responseType' in xhr && support.blob) {
|
493
|
+
xhr.responseType = 'blob';
|
494
|
+
}
|
495
|
+
|
496
|
+
request.headers.forEach(function(value, name) {
|
497
|
+
xhr.setRequestHeader(name, value);
|
498
|
+
});
|
499
|
+
|
500
|
+
if (request.signal) {
|
501
|
+
request.signal.addEventListener('abort', abortXhr);
|
502
|
+
|
503
|
+
xhr.onreadystatechange = function() {
|
504
|
+
// DONE (success or failure)
|
505
|
+
if (xhr.readyState === 4) {
|
506
|
+
request.signal.removeEventListener('abort', abortXhr);
|
507
|
+
}
|
508
|
+
};
|
509
|
+
}
|
510
|
+
|
511
|
+
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
|
512
|
+
})
|
513
|
+
}
|
514
|
+
|
515
|
+
fetch.polyfill = true;
|
516
|
+
|
517
|
+
if (!self.fetch) {
|
518
|
+
self.fetch = fetch;
|
519
|
+
self.Headers = Headers;
|
520
|
+
self.Request = Request;
|
521
|
+
self.Response = Response;
|
522
|
+
}
|
523
|
+
|
524
|
+
exports.Headers = Headers;
|
525
|
+
exports.Request = Request;
|
526
|
+
exports.Response = Response;
|
527
|
+
exports.fetch = fetch;
|
528
|
+
|
529
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
530
|
+
|
531
|
+
})));
|