workarea-api-storefront 4.4.6 → 4.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +52 -0
- data/README.md +4 -7
- data/app/controllers/workarea/api/storefront/analytics_controller.rb +31 -19
- data/app/controllers/workarea/api/storefront/application_controller.rb +15 -2
- data/app/controllers/workarea/api/storefront/authentication.rb +6 -9
- data/app/controllers/workarea/api/storefront/categories_controller.rb +3 -1
- data/app/controllers/workarea/api/storefront/checkouts_controller.rb +0 -1
- data/app/controllers/workarea/api/storefront/menus_controller.rb +3 -1
- data/app/controllers/workarea/api/storefront/pages_controller.rb +3 -1
- data/app/controllers/workarea/api/storefront/products_controller.rb +3 -1
- data/app/controllers/workarea/api/storefront/recent_views_controller.rb +13 -26
- data/app/controllers/workarea/api/storefront/recommendations_controller.rb +2 -8
- data/app/controllers/workarea/api/storefront/searches_controller.rb +0 -12
- data/app/views/workarea/api/storefront/categories/show.json.jbuilder +1 -1
- data/app/views/workarea/api/storefront/email_signups/show.json.jbuilder +1 -1
- data/app/views/workarea/api/storefront/menus/_menu.json.jbuilder +1 -1
- data/app/views/workarea/api/storefront/pages/show.json.jbuilder +1 -1
- data/app/views/workarea/api/storefront/recent_views/show.json.jbuilder +0 -1
- data/app/views/workarea/api/storefront/searches/show.json.jbuilder +1 -1
- data/app/views/workarea/api/storefront/system_content/show.json.jbuilder +1 -1
- data/config/initializers/config.rb +19 -0
- data/lib/workarea/api/storefront.rb +1 -0
- data/lib/workarea/api/storefront/visit.decorator +52 -0
- data/test/documentation/workarea/api/storefront/checkouts_documentation_test.rb +21 -0
- data/test/documentation/workarea/api/storefront/segmentation_documentation_test.rb +104 -0
- data/test/documentation/workarea/api/storefront/validation_documentation_test.rb +1 -1
- data/test/dummy/config/initializers/session_store.rb +3 -1
- data/test/integration/workarea/api/storefront/analytics_integration_test.rb +12 -7
- data/test/integration/workarea/api/storefront/recent_views_integration_test.rb +38 -33
- data/test/integration/workarea/api/storefront/recommendations_integration_test.rb +1 -1
- data/test/integration/workarea/api/storefront/searches_integration_test.rb +0 -36
- data/test/integration/workarea/api/storefront/segments_integration_test.rb +218 -0
- data/workarea-api-storefront.gemspec +8 -7
- metadata +19 -15
- data/app/controllers/workarea/api/storefront/user_activity.rb +0 -36
- data/app/view_models/workarea/api/storefront/search_suggestion_view_model.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46c493a6520203dddfec3bcc9ae914a661040f550c3bc896c2650f2a7756e8f3
|
4
|
+
data.tar.gz: a20ce0a23aa70ad2ca94331a5c14dcbe28e76199428d35a4a34d384a8e1efd56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80f9aeca36c57411fbade7179e0029f572fa7af309177b936b3153dcbc5bb36bd83bc5bb35e951770f70130804e72c2581fc2b0b874499dd1549e3f59cba533b
|
7
|
+
data.tar.gz: f5bba158201651ab1bd964cf494363f9e2ccedc0ab44529af467c50b9b0d7eea0a3adcdb3dc48fe588055d16defd9b8de9360a55e2cb7500e932b7713fb8a443
|
data/LICENSE
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
WebLinc
|
2
|
+
Business Source License
|
3
|
+
|
4
|
+
Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
|
5
|
+
|
6
|
+
Licensed Work: Workarea Commerce Platform
|
7
|
+
The Licensed Work is (c) 2019 WebLinc Corporation
|
8
|
+
|
9
|
+
Additional Use Grant:
|
10
|
+
You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
|
11
|
+
|
12
|
+
A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
|
13
|
+
|
14
|
+
For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
|
15
|
+
|
16
|
+
Change Date: 2019-08-20
|
17
|
+
|
18
|
+
Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
|
19
|
+
|
20
|
+
Terms
|
21
|
+
|
22
|
+
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
|
23
|
+
|
24
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
|
25
|
+
|
26
|
+
If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
|
27
|
+
|
28
|
+
All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
|
29
|
+
|
30
|
+
You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
|
31
|
+
|
32
|
+
Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
|
33
|
+
|
34
|
+
This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
|
35
|
+
|
36
|
+
Covenants of Licensor
|
37
|
+
In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
|
38
|
+
|
39
|
+
To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
|
40
|
+
|
41
|
+
To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
|
42
|
+
|
43
|
+
To specify a Change Date.
|
44
|
+
|
45
|
+
Not to modify this License in any other way.
|
46
|
+
|
47
|
+
Notice
|
48
|
+
The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
|
49
|
+
|
50
|
+
For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
|
51
|
+
|
52
|
+
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
|
data/README.md
CHANGED
@@ -48,11 +48,8 @@ curl \
|
|
48
48
|
"http://yourincredibleheadlesscommercesolution.biz/api/carts.json"
|
49
49
|
```
|
50
50
|
|
51
|
-
|
51
|
+
License
|
52
|
+
--------------------------------------------------------------------------------
|
53
|
+
Workarea Commerce Platform is released under the [Business Software License](https://github.com/workarea-commerce/workarea/blob/master/LICENSE)
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
For licensing, contact [sales@workarea.com][].
|
56
|
-
|
57
|
-
[Workarea API]: https://homebase.weblinc.com/plugins/workarea-api-admin
|
58
|
-
[sales@workarea.com]: mailto:sales@workarea.com
|
55
|
+
[Workarea API]: https://github.com/workarea-commerce/workarea-api
|
@@ -1,38 +1,50 @@
|
|
1
1
|
module Workarea
|
2
2
|
module Api
|
3
3
|
module Storefront
|
4
|
-
class AnalyticsController <
|
5
|
-
include ActionController::Head
|
6
|
-
include ActionController::Instrumentation
|
7
|
-
|
4
|
+
class AnalyticsController < Api::Storefront::ApplicationController
|
8
5
|
def category_view
|
9
6
|
Metrics::CategoryByDay.inc(key: { category_id: params[:category_id] }, views: 1)
|
7
|
+
|
8
|
+
if current_metrics_id.present?
|
9
|
+
Metrics::User.save_affinity(
|
10
|
+
id: current_metrics_id,
|
11
|
+
action: 'viewed',
|
12
|
+
category_ids: params[:category_id]
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
10
16
|
head :ok
|
11
17
|
end
|
12
18
|
|
13
19
|
def product_view
|
14
20
|
Metrics::ProductByDay.inc(key: { product_id: params[:product_id] }, views: 1)
|
21
|
+
|
22
|
+
if current_metrics_id.present?
|
23
|
+
Metrics::User.save_affinity(
|
24
|
+
id: current_metrics_id,
|
25
|
+
action: 'viewed',
|
26
|
+
product_ids: params[:product_id]
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
15
30
|
head :ok
|
16
31
|
end
|
17
32
|
|
18
33
|
def search
|
19
|
-
|
20
|
-
head :ok
|
21
|
-
end
|
34
|
+
query_string = QueryString.new(params[:q])
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
36
|
+
if query_string.present? && !query_string.short?
|
37
|
+
Metrics::SearchByDay.save_search(params[:q], params[:total_results])
|
38
|
+
|
39
|
+
if current_metrics_id.present?
|
40
|
+
Metrics::User.save_affinity(
|
41
|
+
id: current_metrics_id,
|
42
|
+
action: 'viewed',
|
43
|
+
search_ids: query_string.id
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
30
47
|
|
31
|
-
def filters
|
32
|
-
warn <<~eos
|
33
|
-
DEPRECATION WARNING: Filter analytics tracking is deprecated and will be removed \
|
34
|
-
in Workarea 3.5.
|
35
|
-
eos
|
36
48
|
head :ok
|
37
49
|
end
|
38
50
|
end
|
@@ -2,15 +2,15 @@ module Workarea
|
|
2
2
|
module Api
|
3
3
|
module Storefront
|
4
4
|
class ApplicationController < Workarea::ApplicationController
|
5
|
-
include
|
5
|
+
include HttpCaching
|
6
6
|
include Api::Storefront::Authentication
|
7
|
-
include Api::Storefront::UserActivity
|
8
7
|
|
9
8
|
respond_to :json
|
10
9
|
|
11
10
|
before_action :set_json_format
|
12
11
|
before_action :skip_session
|
13
12
|
before_action { params.permit! }
|
13
|
+
around_action :apply_segments
|
14
14
|
after_action :disable_cors_protection
|
15
15
|
|
16
16
|
rescue_from Mongoid::Errors::DocumentNotFound, with: :handle_not_found
|
@@ -28,6 +28,19 @@ module Workarea
|
|
28
28
|
request.session_options[:skip] = true
|
29
29
|
end
|
30
30
|
|
31
|
+
def assert_current_metrics_id
|
32
|
+
if current_metrics_id.blank?
|
33
|
+
render(
|
34
|
+
json: {
|
35
|
+
problem: t('workarea.api.storefront.recent_views.missing_id')
|
36
|
+
},
|
37
|
+
status: :unprocessable_entity
|
38
|
+
)
|
39
|
+
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
31
44
|
private
|
32
45
|
|
33
46
|
def set_json_format
|
@@ -10,19 +10,16 @@ module Workarea
|
|
10
10
|
helper_method :current_user
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
user = authenticate_with_http_token do |token, options|
|
17
|
-
User::AuthenticationToken.authenticate(token, options).try(:user)
|
18
|
-
end
|
13
|
+
def self.find_user(token, options)
|
14
|
+
User::AuthenticationToken.authenticate(token, options).try(:user)
|
15
|
+
end
|
19
16
|
|
20
|
-
|
17
|
+
def current_user
|
18
|
+
current_visit.current_user || raise(InvalidError)
|
21
19
|
end
|
22
20
|
|
23
21
|
def authentication?
|
24
|
-
|
25
|
-
request.authorization.to_s[regex].present?
|
22
|
+
current_visit.logged_in?
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
@@ -5,7 +5,7 @@ module Workarea
|
|
5
5
|
before_action :cache_page
|
6
6
|
|
7
7
|
def index
|
8
|
-
models = Catalog::Category.
|
8
|
+
models = Catalog::Category.page(params[:page]).select(&:active?)
|
9
9
|
@categories = Workarea::Storefront::CategoryViewModel.wrap(
|
10
10
|
models,
|
11
11
|
view_model_options
|
@@ -14,6 +14,8 @@ module Workarea
|
|
14
14
|
|
15
15
|
def show
|
16
16
|
model = Catalog::Category.find_by(slug: params[:id])
|
17
|
+
raise InvalidDisplay unless model.active?
|
18
|
+
|
17
19
|
@category = Workarea::Storefront::CategoryViewModel.wrap(
|
18
20
|
model,
|
19
21
|
view_model_options
|
@@ -10,7 +10,9 @@ module Workarea
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def show
|
13
|
-
model = Navigation::Menu.
|
13
|
+
model = Navigation::Menu.find(params[:id])
|
14
|
+
raise InvalidDisplay unless model.active?
|
15
|
+
|
14
16
|
@menu = Workarea::Storefront::MenuViewModel.wrap(model, params)
|
15
17
|
end
|
16
18
|
end
|
@@ -5,7 +5,9 @@ module Workarea
|
|
5
5
|
before_action :cache_page
|
6
6
|
|
7
7
|
def show
|
8
|
-
model = Content::Page.
|
8
|
+
model = Content::Page.find_by(slug: params[:id])
|
9
|
+
raise InvalidDisplay unless model.active?
|
10
|
+
|
9
11
|
@page = Workarea::Storefront::PageViewModel.new(model, view_model_options)
|
10
12
|
end
|
11
13
|
end
|
@@ -5,7 +5,9 @@ module Workarea
|
|
5
5
|
before_action :cache_page
|
6
6
|
|
7
7
|
def show
|
8
|
-
model = Workarea::Catalog::Product.
|
8
|
+
model = Workarea::Catalog::Product.find_by(slug: params[:id])
|
9
|
+
raise InvalidDisplay unless model.active?
|
10
|
+
|
9
11
|
@product = Workarea::Storefront::ProductViewModel.wrap(
|
10
12
|
model,
|
11
13
|
view_model_options
|
@@ -2,39 +2,26 @@ module Workarea
|
|
2
2
|
module Api
|
3
3
|
module Storefront
|
4
4
|
class RecentViewsController < Api::Storefront::ApplicationController
|
5
|
-
before_action :
|
5
|
+
before_action :assert_current_metrics_id
|
6
6
|
|
7
7
|
def show
|
8
|
-
|
9
|
-
|
10
|
-
last_modified: user_activity.updated_at,
|
11
|
-
public: true
|
8
|
+
@recent_views = Workarea::Storefront::UserActivityViewModel.new(
|
9
|
+
current_metrics
|
12
10
|
)
|
13
|
-
@recent_views = Workarea::Storefront::UserActivityViewModel.new(
|
14
|
-
user_activity
|
15
|
-
)
|
16
|
-
end
|
17
11
|
end
|
18
12
|
|
19
13
|
def update
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
params[:product_id]
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
if params[:category_id].present?
|
28
|
-
Recommendation::UserActivity.save_category(
|
29
|
-
current_user_activity_id,
|
30
|
-
params[:category_id]
|
31
|
-
)
|
32
|
-
end
|
14
|
+
product_ids = Array.wrap(params[:product_id])
|
15
|
+
category_ids = Array.wrap(params[:category_id])
|
16
|
+
search_ids = Array.wrap(params[:search])
|
33
17
|
|
34
|
-
if
|
35
|
-
|
36
|
-
|
37
|
-
|
18
|
+
if current_metrics_id.present?
|
19
|
+
Metrics::User.save_affinity(
|
20
|
+
id: current_metrics_id,
|
21
|
+
action: 'viewed',
|
22
|
+
product_ids: product_ids,
|
23
|
+
category_ids: category_ids,
|
24
|
+
search_ids: search_ids
|
38
25
|
)
|
39
26
|
end
|
40
27
|
|
@@ -2,17 +2,11 @@ module Workarea
|
|
2
2
|
module Api
|
3
3
|
module Storefront
|
4
4
|
class RecommendationsController < Api::Storefront::ApplicationController
|
5
|
-
before_action :
|
5
|
+
before_action :assert_current_metrics_id
|
6
6
|
|
7
7
|
def show
|
8
|
-
fresh_when(
|
9
|
-
etag: user_activity,
|
10
|
-
last_modified: user_activity.updated_at,
|
11
|
-
public: true
|
12
|
-
)
|
13
|
-
|
14
8
|
@recommendations = Workarea::Storefront::PersonalizedRecommendationsViewModel.new(
|
15
|
-
|
9
|
+
current_metrics,
|
16
10
|
view_model_options
|
17
11
|
)
|
18
12
|
end
|
@@ -4,18 +4,6 @@ module Workarea
|
|
4
4
|
class SearchesController < Api::Storefront::ApplicationController
|
5
5
|
before_action :cache_page
|
6
6
|
|
7
|
-
def index
|
8
|
-
search_query = QueryString.new(params[:q]).sanitized
|
9
|
-
|
10
|
-
render(nothing: true) && (return) if search_query.blank?
|
11
|
-
autocomplete_params = params.permit(:q)
|
12
|
-
search = Search::SearchSuggestions.new(autocomplete_params)
|
13
|
-
|
14
|
-
@results = search.results.map do |result|
|
15
|
-
SearchSuggestionViewModel.new(result).to_h
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
7
|
def show
|
20
8
|
response = Search::StorefrontSearch.new(params.to_unsafe_h).response
|
21
9
|
@search = Workarea::Storefront::SearchViewModel.new(
|
@@ -14,7 +14,7 @@ json.cache! @category.cache_key, expires_in: 1.hour do
|
|
14
14
|
json.partial! 'workarea/api/storefront/taxons/taxon', taxon: taxon
|
15
15
|
end
|
16
16
|
|
17
|
-
json.content_blocks @category.content.blocks do |block|
|
17
|
+
json.content_blocks @category.content.blocks.select(&:active?) do |block|
|
18
18
|
json.partial! 'workarea/api/storefront/content_blocks/block', block: block
|
19
19
|
end
|
20
20
|
|
@@ -5,7 +5,7 @@ json.cache! menu.cache_key, expires_in: 1.hour do
|
|
5
5
|
json.url menu_path(menu)
|
6
6
|
json.taxon_url menu.taxon.url.presence || storefront_api_url_for(menu.taxon)
|
7
7
|
|
8
|
-
json.content_blocks menu.content.blocks do |block|
|
8
|
+
json.content_blocks menu.content.blocks.select(&:active?) do |block|
|
9
9
|
json.partial! 'workarea/api/storefront/content_blocks/block', block: block
|
10
10
|
end
|
11
11
|
end
|
@@ -10,7 +10,7 @@ json.cache! @page.cache_key, expires_in: 1.hour do
|
|
10
10
|
json.partial! 'workarea/api/storefront/taxons/taxon', taxon: taxon
|
11
11
|
end
|
12
12
|
|
13
|
-
json.content_blocks @page.content.blocks do |block|
|
13
|
+
json.content_blocks @page.content.blocks.select(&:active?) do |block|
|
14
14
|
json.partial! 'workarea/api/storefront/content_blocks/block', block: block
|
15
15
|
end
|
16
16
|
end
|
@@ -4,7 +4,7 @@ json.redirect @search.redirect
|
|
4
4
|
json.sorts @search.sorts
|
5
5
|
json.sort @search.sort
|
6
6
|
|
7
|
-
json.content_blocks @search.content.blocks do |block|
|
7
|
+
json.content_blocks @search.content.blocks.select(&:active?) do |block|
|
8
8
|
json.partial! 'workarea/api/storefront/content_blocks/block', block: block
|
9
9
|
end
|
10
10
|
|
@@ -6,7 +6,7 @@ json.cache! @content.cache_key, expires_in: 1.hour do
|
|
6
6
|
json.browser_title @content.browser_title
|
7
7
|
json.meta_description @content.meta_description
|
8
8
|
|
9
|
-
json.content_blocks @content.content.blocks do |block|
|
9
|
+
json.content_blocks @content.content.blocks.select(&:active?) do |block|
|
10
10
|
json.partial! 'workarea/api/storefront/content_blocks/block', block: block
|
11
11
|
end
|
12
12
|
end
|
@@ -1,2 +1,21 @@
|
|
1
1
|
Workarea.config.api_product_image_jobs_blacklist ||= %i[convert encode rotate optim avatar thumb]
|
2
2
|
Workarea.config.authentication_token_expiration ||= 1.week
|
3
|
+
|
4
|
+
# Ok, this one's a doozy.
|
5
|
+
#
|
6
|
+
# To deliver segmentation in the storefront API, we need a way to change a
|
7
|
+
# {Visit}'s definition of things like sessions, cookies, auth, etc.
|
8
|
+
#
|
9
|
+
# Since segments are determined first (before any other middleware), we need a
|
10
|
+
# way to know whether this is an API request to for logic in {Visit}.
|
11
|
+
#
|
12
|
+
# Since this is before any other middleware (including Rails' routing), we don't
|
13
|
+
# have a way to check the controller class or anything else application-related
|
14
|
+
# for whether it's an API request or an ordinary request.
|
15
|
+
#
|
16
|
+
# The best thing I could come up with is this regex. This lambda provides a hook
|
17
|
+
# for builds in case it doesn't work. They can provide their own logic here.
|
18
|
+
#
|
19
|
+
Workarea.config.is_api_visit = lambda do |request|
|
20
|
+
request.original_url =~ /:\/\/api\.|\/api\/./
|
21
|
+
end
|