app_manager 2.7.2 → 2.8.0
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.
- checksums.yaml +4 -4
- data/.cursor/rules/commit-and-pr.mdc +33 -0
- data/.github/copilot-instructions.md +25 -0
- data/CHANGELOG.md +97 -0
- data/CLAUDE.md +10 -0
- data/Gemfile.lock +68 -64
- data/README.md +37 -0
- data/app/controllers/app_manager/charges_controller.rb +8 -10
- data/docs/commit-and-pr-standards.md +121 -0
- data/lib/app_manager/config.rb +3 -0
- data/lib/app_manager/graphql_helper.rb +22 -18
- data/lib/app_manager/model.rb +7 -8
- data/lib/app_manager/shopify_api.rb +161 -0
- data/lib/app_manager/version.rb +1 -1
- data/lib/app_manager.rb +2 -0
- data/lib/generators/app_manager/install/templates/app_manager.rb.tt +1 -0
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1af077367723608dd6c4b9b917be9ce48dee6b5ccb01a468eef385a60c5375a
|
|
4
|
+
data.tar.gz: db446ea77cfbf40ec9e9891786e2a48446d6b74c33ee930c38822f99006d09b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a1d26b06d1f4d78b142d0943b04dcecd6347df4f6b43e650d8e712750b6de441fae90f2796792892a17c413da9ebd477757becff30413e8359fc33083031d2c
|
|
7
|
+
data.tar.gz: fbe2e3536bd1730d9fb0a7eb87fd85fd774c63f5d8e5cda505699b262ef653493b672122ddf8d17377b709368ce401af85009a7ab62b239dac02db3c30f64c17
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Commit and PR message standards for merges tracked in Atlas
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
When you write a commit message, a PR title or a PR description in this repo,
|
|
7
|
+
follow these rules. Full version: `docs/commit-and-pr-standards.md`.
|
|
8
|
+
|
|
9
|
+
## PR title (with squash-merge it becomes the commit on main)
|
|
10
|
+
- Format: `<JIRA-KEY>: <what changed, in plain words>`, imperative mood, under ~72 characters.
|
|
11
|
+
- Say what changed for the user or the system, not which branch it came from.
|
|
12
|
+
- Never use a branch name (`staging-v2`, `develop`, `testing to main`), `WIP`, `fix`, `update` or `changes`.
|
|
13
|
+
- Release / promotion PRs (develop → main, staging → master, staging-v2 → master-v2):
|
|
14
|
+
`Release: <the two or three main things it carries>`
|
|
15
|
+
|
|
16
|
+
## PR description: always end it with this block
|
|
17
|
+
```
|
|
18
|
+
Change type: New Feature | Improvement | Bug Fix | Refactor | Security | Maintenance
|
|
19
|
+
Feature scope: Major | Minor
|
|
20
|
+
Short description: <one sentence a product manager would understand>
|
|
21
|
+
Notes: <optional>
|
|
22
|
+
```
|
|
23
|
+
- New Feature: new user-facing functionality. Improvement: an existing feature made better.
|
|
24
|
+
Bug Fix: a fix for a defect shipped earlier. Refactor: no behaviour change.
|
|
25
|
+
Security: security-motivated. Maintenance: dependencies, infra, CI, version bumps.
|
|
26
|
+
- Major = significant surface-area change (new tab, endpoint, migration, broad behaviour change).
|
|
27
|
+
Minor = small and contained. When in doubt, Minor.
|
|
28
|
+
- Several changes in one PR: repeat the block per change, each starting with `Task: <name>`.
|
|
29
|
+
|
|
30
|
+
## Also
|
|
31
|
+
- Never leave a PR template unfilled: fill it in, or delete it.
|
|
32
|
+
- Commit messages: one line saying what changed (`Handle error on charges`, not `fix`).
|
|
33
|
+
- Put the Jira key in the branch name or the commit.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## Commit and PR messages
|
|
2
|
+
|
|
3
|
+
When you write a commit message, a PR title or a PR description in this repository,
|
|
4
|
+
follow these rules. The full version is in `docs/commit-and-pr-standards.md`.
|
|
5
|
+
|
|
6
|
+
**PR title** (with squash-merge it becomes the commit on main):
|
|
7
|
+
`<JIRA-KEY>: <what changed, in plain words>`. Use the imperative mood and keep it under
|
|
8
|
+
~72 characters. Never use a branch name (`staging-v2`, `develop`, `testing to main`),
|
|
9
|
+
`WIP`, `fix` or `update`. For release PRs (develop → main, staging-v2 → master-v2), use
|
|
10
|
+
`Release: <the two or three main things it carries>`.
|
|
11
|
+
|
|
12
|
+
**End every PR description with this block:**
|
|
13
|
+
```
|
|
14
|
+
Change type: New Feature | Improvement | Bug Fix | Refactor | Security | Maintenance
|
|
15
|
+
Feature scope: Major | Minor
|
|
16
|
+
Short description: <one sentence a product manager would understand>
|
|
17
|
+
Notes: <optional>
|
|
18
|
+
```
|
|
19
|
+
- Major = significant surface-area change. Minor = small and contained. When in doubt, Minor.
|
|
20
|
+
- If the PR contains several changes, repeat the block for each, starting it with `Task: <name>`.
|
|
21
|
+
|
|
22
|
+
**Also:**
|
|
23
|
+
- Never leave a PR template unfilled.
|
|
24
|
+
- Commit messages are one line saying what changed.
|
|
25
|
+
- Put the Jira key in the branch name or the commit.
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `app_manager` gem are documented here, newest first.
|
|
4
|
+
Versions before 2.3.5 are not listed. 2.6.x was never released.
|
|
5
|
+
|
|
6
|
+
## 2.8.0 - 2026-11-18
|
|
7
|
+
|
|
8
|
+
Support for Shopify's expiring offline access tokens (required for public apps
|
|
9
|
+
from 1 January 2027). Backward compatible: an app that changes nothing keeps the
|
|
10
|
+
previous behaviour.
|
|
11
|
+
|
|
12
|
+
- Billing calls now get their token from an app-supplied resolver instead of
|
|
13
|
+
reading the token column directly, so a merchant no longer gets a dead token
|
|
14
|
+
(HTTP 401) when upgrading a plan.
|
|
15
|
+
- New `config.shopify_token_resolver`: any object, class or class name responding
|
|
16
|
+
to `token(shop_domain)` and `refresh(shop_domain)`. Unset, the default
|
|
17
|
+
`AppManager::ColumnTokenResolver` reads the token exactly as before.
|
|
18
|
+
- New `AppManager::ModelTokenResolver` for shop models with a
|
|
19
|
+
`fresh_shopify_token` instance method. After a rejection it calls the method
|
|
20
|
+
again (with `force: true` if it accepts that keyword). Falls back to
|
|
21
|
+
`shop.shopify_token` when the method is missing, blank or raises.
|
|
22
|
+
- The token is read through the model's accessor, not the raw attribute, so an
|
|
23
|
+
encrypted `shopify_token` column comes back decrypted.
|
|
24
|
+
- Every gem call to Shopify (create, confirm, cancel and query charges) goes
|
|
25
|
+
through `AppManager::ShopifyApi`. A 401, or a 403 saying `Non-expiring access
|
|
26
|
+
tokens are no longer accepted`, triggers exactly one retry, and only with a
|
|
27
|
+
token different from the rejected one. A 403 for a missing scope is not a
|
|
28
|
+
rejection.
|
|
29
|
+
- `GraphqlHelper.new` no longer needs the token (a second argument is still
|
|
30
|
+
accepted as a fallback). The missing-token log no longer includes the token.
|
|
31
|
+
|
|
32
|
+
## 2.7.2 - 2026-11-03
|
|
33
|
+
|
|
34
|
+
- Security: `/api/app-manager` routes now require authentication: the App
|
|
35
|
+
Manager `token` header, or a verified Shopify session token for the routes the
|
|
36
|
+
billing page calls. New `shopify_api_secret` config.
|
|
37
|
+
- Security: a merchant can no longer get a paid plan without paying; the charge
|
|
38
|
+
callback only changes the plan for an `active` Shopify charge.
|
|
39
|
+
|
|
40
|
+
## 2.7.1 - 2026-07-24
|
|
41
|
+
|
|
42
|
+
- A free custom plan is marked as used when a shop changes to it.
|
|
43
|
+
|
|
44
|
+
## 2.7.0 - 2026-07-23
|
|
45
|
+
|
|
46
|
+
- The discount applied to a charge (value, type, duration, source) is stored on
|
|
47
|
+
the charge. Custom plans can be used once.
|
|
48
|
+
|
|
49
|
+
## 2.5.0 - 2026-05-29
|
|
50
|
+
|
|
51
|
+
- New plan fields (trial days text, most popular badge) and an FAQs table. Run
|
|
52
|
+
`rails g app_manager:install` and migrate. New `most_popular_plan_ids` config.
|
|
53
|
+
|
|
54
|
+
## 2.4.11 - 2026-05-14
|
|
55
|
+
|
|
56
|
+
- Safer install generator: migrations are skipped when already applied.
|
|
57
|
+
|
|
58
|
+
## 2.4.10 - 2026-05-13
|
|
59
|
+
|
|
60
|
+
- Added a `details` column to plans.
|
|
61
|
+
|
|
62
|
+
## 2.4.9 - 2026-05-08
|
|
63
|
+
|
|
64
|
+
- The highlights and note columns are only used when they exist, for backward
|
|
65
|
+
compatibility.
|
|
66
|
+
|
|
67
|
+
## 2.4.8 - 2026-05-08
|
|
68
|
+
|
|
69
|
+
- Added `note` and `highlights` columns to plans.
|
|
70
|
+
|
|
71
|
+
## 2.4.7 - 2026-05-01
|
|
72
|
+
|
|
73
|
+
- Fixed the SDK version parameter sent to App Manager.
|
|
74
|
+
|
|
75
|
+
## 2.4.6 - 2026-05-01
|
|
76
|
+
|
|
77
|
+
- The SDK version is sent to App Manager.
|
|
78
|
+
|
|
79
|
+
## 2.4.5 - 2026-03-19
|
|
80
|
+
|
|
81
|
+
- Security: `shopify_token` is excluded from the users response.
|
|
82
|
+
|
|
83
|
+
## 2.4.4 - 2026-03-18
|
|
84
|
+
|
|
85
|
+
- Security: fixed remote code execution and SQL injection vulnerabilities.
|
|
86
|
+
|
|
87
|
+
## 2.4.0 - 2.4.3 - 2026-02-26 to 2026-03-02
|
|
88
|
+
|
|
89
|
+
- Fail-safe: incremental plan updates.
|
|
90
|
+
|
|
91
|
+
## 2.3.7 - 2026-02-18
|
|
92
|
+
|
|
93
|
+
- Rails 7 `allow_other_host` support for redirects.
|
|
94
|
+
|
|
95
|
+
## 2.3.6 - 2025-10-28
|
|
96
|
+
|
|
97
|
+
- Support for the development-store partner field.
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
## Commit and PR messages
|
|
2
|
+
|
|
3
|
+
When you write a commit message, a PR title or a PR description, follow the rules in
|
|
4
|
+
@docs/commit-and-pr-standards.md.
|
|
5
|
+
|
|
6
|
+
Short version:
|
|
7
|
+
- PR title: `<JIRA-KEY>: <what changed>`. Never a branch name, `WIP` or `fix`.
|
|
8
|
+
- Release PRs: `Release: <the main things it carries>`.
|
|
9
|
+
- End every PR description with `Change type:`, `Feature scope:` and `Short description:` lines.
|
|
10
|
+
- Never leave a PR template unfilled.
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
app_manager (2.
|
|
4
|
+
app_manager (2.8.0)
|
|
5
5
|
activerecord-import (~> 1.4)
|
|
6
6
|
httparty
|
|
7
7
|
kaminari (>= 0.16.3)
|
|
@@ -12,29 +12,29 @@ GEM
|
|
|
12
12
|
specs:
|
|
13
13
|
action_text-trix (2.1.19)
|
|
14
14
|
railties
|
|
15
|
-
actioncable (8.1.
|
|
16
|
-
actionpack (= 8.1.
|
|
17
|
-
activesupport (= 8.1.
|
|
15
|
+
actioncable (8.1.4.1)
|
|
16
|
+
actionpack (= 8.1.4.1)
|
|
17
|
+
activesupport (= 8.1.4.1)
|
|
18
18
|
nio4r (~> 2.0)
|
|
19
19
|
websocket-driver (>= 0.6.1)
|
|
20
20
|
zeitwerk (~> 2.6)
|
|
21
|
-
actionmailbox (8.1.
|
|
22
|
-
actionpack (= 8.1.
|
|
23
|
-
activejob (= 8.1.
|
|
24
|
-
activerecord (= 8.1.
|
|
25
|
-
activestorage (= 8.1.
|
|
26
|
-
activesupport (= 8.1.
|
|
21
|
+
actionmailbox (8.1.4.1)
|
|
22
|
+
actionpack (= 8.1.4.1)
|
|
23
|
+
activejob (= 8.1.4.1)
|
|
24
|
+
activerecord (= 8.1.4.1)
|
|
25
|
+
activestorage (= 8.1.4.1)
|
|
26
|
+
activesupport (= 8.1.4.1)
|
|
27
27
|
mail (>= 2.8.0)
|
|
28
|
-
actionmailer (8.1.
|
|
29
|
-
actionpack (= 8.1.
|
|
30
|
-
actionview (= 8.1.
|
|
31
|
-
activejob (= 8.1.
|
|
32
|
-
activesupport (= 8.1.
|
|
28
|
+
actionmailer (8.1.4.1)
|
|
29
|
+
actionpack (= 8.1.4.1)
|
|
30
|
+
actionview (= 8.1.4.1)
|
|
31
|
+
activejob (= 8.1.4.1)
|
|
32
|
+
activesupport (= 8.1.4.1)
|
|
33
33
|
mail (>= 2.8.0)
|
|
34
34
|
rails-dom-testing (~> 2.2)
|
|
35
|
-
actionpack (8.1.
|
|
36
|
-
actionview (= 8.1.
|
|
37
|
-
activesupport (= 8.1.
|
|
35
|
+
actionpack (8.1.4.1)
|
|
36
|
+
actionview (= 8.1.4.1)
|
|
37
|
+
activesupport (= 8.1.4.1)
|
|
38
38
|
nokogiri (>= 1.8.5)
|
|
39
39
|
rack (>= 2.2.4)
|
|
40
40
|
rack-session (>= 1.0.1)
|
|
@@ -42,38 +42,38 @@ GEM
|
|
|
42
42
|
rails-dom-testing (~> 2.2)
|
|
43
43
|
rails-html-sanitizer (~> 1.6)
|
|
44
44
|
useragent (~> 0.16)
|
|
45
|
-
actiontext (8.1.
|
|
45
|
+
actiontext (8.1.4.1)
|
|
46
46
|
action_text-trix (~> 2.1.15)
|
|
47
|
-
actionpack (= 8.1.
|
|
48
|
-
activerecord (= 8.1.
|
|
49
|
-
activestorage (= 8.1.
|
|
50
|
-
activesupport (= 8.1.
|
|
47
|
+
actionpack (= 8.1.4.1)
|
|
48
|
+
activerecord (= 8.1.4.1)
|
|
49
|
+
activestorage (= 8.1.4.1)
|
|
50
|
+
activesupport (= 8.1.4.1)
|
|
51
51
|
globalid (>= 0.6.0)
|
|
52
52
|
nokogiri (>= 1.8.5)
|
|
53
|
-
actionview (8.1.
|
|
54
|
-
activesupport (= 8.1.
|
|
53
|
+
actionview (8.1.4.1)
|
|
54
|
+
activesupport (= 8.1.4.1)
|
|
55
55
|
builder (~> 3.1)
|
|
56
56
|
erubi (~> 1.11)
|
|
57
57
|
rails-dom-testing (~> 2.2)
|
|
58
|
-
rails-html-sanitizer (~> 1.6)
|
|
59
|
-
activejob (8.1.
|
|
60
|
-
activesupport (= 8.1.
|
|
58
|
+
rails-html-sanitizer (~> 1.6, >= 1.7.2)
|
|
59
|
+
activejob (8.1.4.1)
|
|
60
|
+
activesupport (= 8.1.4.1)
|
|
61
61
|
globalid (>= 0.3.6)
|
|
62
|
-
activemodel (8.1.
|
|
63
|
-
activesupport (= 8.1.
|
|
64
|
-
activerecord (8.1.
|
|
65
|
-
activemodel (= 8.1.
|
|
66
|
-
activesupport (= 8.1.
|
|
62
|
+
activemodel (8.1.4.1)
|
|
63
|
+
activesupport (= 8.1.4.1)
|
|
64
|
+
activerecord (8.1.4.1)
|
|
65
|
+
activemodel (= 8.1.4.1)
|
|
66
|
+
activesupport (= 8.1.4.1)
|
|
67
67
|
timeout (>= 0.4.0)
|
|
68
68
|
activerecord-import (1.8.1)
|
|
69
69
|
activerecord (>= 4.2)
|
|
70
|
-
activestorage (8.1.
|
|
71
|
-
actionpack (= 8.1.
|
|
72
|
-
activejob (= 8.1.
|
|
73
|
-
activerecord (= 8.1.
|
|
74
|
-
activesupport (= 8.1.
|
|
70
|
+
activestorage (8.1.4.1)
|
|
71
|
+
actionpack (= 8.1.4.1)
|
|
72
|
+
activejob (= 8.1.4.1)
|
|
73
|
+
activerecord (= 8.1.4.1)
|
|
74
|
+
activesupport (= 8.1.4.1)
|
|
75
75
|
marcel (~> 1.0)
|
|
76
|
-
activesupport (8.1.
|
|
76
|
+
activesupport (8.1.4.1)
|
|
77
77
|
base64
|
|
78
78
|
bigdecimal
|
|
79
79
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
@@ -86,7 +86,7 @@ GEM
|
|
|
86
86
|
securerandom (>= 0.3)
|
|
87
87
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
88
88
|
uri (>= 0.13.1)
|
|
89
|
-
addressable (2.
|
|
89
|
+
addressable (2.9.2)
|
|
90
90
|
public_suffix (>= 2.0.2, < 8.0)
|
|
91
91
|
base64 (0.3.0)
|
|
92
92
|
bigdecimal (4.0.1)
|
|
@@ -97,7 +97,7 @@ GEM
|
|
|
97
97
|
crack (1.0.1)
|
|
98
98
|
bigdecimal
|
|
99
99
|
rexml
|
|
100
|
-
crass (1.0.
|
|
100
|
+
crass (1.0.8)
|
|
101
101
|
csv (3.3.5)
|
|
102
102
|
date (3.5.1)
|
|
103
103
|
diff-lcs (1.6.2)
|
|
@@ -120,7 +120,7 @@ GEM
|
|
|
120
120
|
prism (>= 1.3.0)
|
|
121
121
|
rdoc (>= 4.0.0)
|
|
122
122
|
reline (>= 0.4.2)
|
|
123
|
-
json (2.21.
|
|
123
|
+
json (2.21.2)
|
|
124
124
|
kaminari (1.2.2)
|
|
125
125
|
activesupport (>= 4.1.0)
|
|
126
126
|
kaminari-actionview (= 1.2.2)
|
|
@@ -134,9 +134,9 @@ GEM
|
|
|
134
134
|
kaminari-core (= 1.2.2)
|
|
135
135
|
kaminari-core (1.2.2)
|
|
136
136
|
logger (1.7.0)
|
|
137
|
-
loofah (2.25.
|
|
137
|
+
loofah (2.25.3)
|
|
138
138
|
crass (~> 1.0.2)
|
|
139
|
-
nokogiri (>= 1.
|
|
139
|
+
nokogiri (>= 1.19.5)
|
|
140
140
|
mail (2.9.1)
|
|
141
141
|
logger
|
|
142
142
|
mini_mime (>= 0.1.1)
|
|
@@ -146,6 +146,7 @@ GEM
|
|
|
146
146
|
marcel (1.2.1)
|
|
147
147
|
method_source (1.1.0)
|
|
148
148
|
mini_mime (1.1.5)
|
|
149
|
+
mini_portile2 (2.8.9)
|
|
149
150
|
minitest (6.0.6)
|
|
150
151
|
drb (~> 2.0)
|
|
151
152
|
prism (~> 1.5)
|
|
@@ -161,7 +162,10 @@ GEM
|
|
|
161
162
|
net-smtp (0.5.2)
|
|
162
163
|
net-protocol
|
|
163
164
|
nio4r (2.7.5)
|
|
164
|
-
nokogiri (1.19.
|
|
165
|
+
nokogiri (1.19.7)
|
|
166
|
+
mini_portile2 (~> 2.8.2)
|
|
167
|
+
racc (~> 1.4)
|
|
168
|
+
nokogiri (1.19.7-x86_64-linux-gnu)
|
|
165
169
|
racc (~> 1.4)
|
|
166
170
|
pp (0.6.4)
|
|
167
171
|
prettyprint
|
|
@@ -173,7 +177,7 @@ GEM
|
|
|
173
177
|
reline (>= 0.6.0)
|
|
174
178
|
public_suffix (7.0.2)
|
|
175
179
|
racc (1.8.1)
|
|
176
|
-
rack (3.2.
|
|
180
|
+
rack (3.2.8)
|
|
177
181
|
rack-session (2.1.2)
|
|
178
182
|
base64 (>= 0.1.0)
|
|
179
183
|
rack (>= 3.0.0)
|
|
@@ -181,30 +185,30 @@ GEM
|
|
|
181
185
|
rack (>= 1.3)
|
|
182
186
|
rackup (2.3.1)
|
|
183
187
|
rack (>= 3)
|
|
184
|
-
rails (8.1.
|
|
185
|
-
actioncable (= 8.1.
|
|
186
|
-
actionmailbox (= 8.1.
|
|
187
|
-
actionmailer (= 8.1.
|
|
188
|
-
actionpack (= 8.1.
|
|
189
|
-
actiontext (= 8.1.
|
|
190
|
-
actionview (= 8.1.
|
|
191
|
-
activejob (= 8.1.
|
|
192
|
-
activemodel (= 8.1.
|
|
193
|
-
activerecord (= 8.1.
|
|
194
|
-
activestorage (= 8.1.
|
|
195
|
-
activesupport (= 8.1.
|
|
188
|
+
rails (8.1.4.1)
|
|
189
|
+
actioncable (= 8.1.4.1)
|
|
190
|
+
actionmailbox (= 8.1.4.1)
|
|
191
|
+
actionmailer (= 8.1.4.1)
|
|
192
|
+
actionpack (= 8.1.4.1)
|
|
193
|
+
actiontext (= 8.1.4.1)
|
|
194
|
+
actionview (= 8.1.4.1)
|
|
195
|
+
activejob (= 8.1.4.1)
|
|
196
|
+
activemodel (= 8.1.4.1)
|
|
197
|
+
activerecord (= 8.1.4.1)
|
|
198
|
+
activestorage (= 8.1.4.1)
|
|
199
|
+
activesupport (= 8.1.4.1)
|
|
196
200
|
bundler (>= 1.15.0)
|
|
197
|
-
railties (= 8.1.
|
|
201
|
+
railties (= 8.1.4.1)
|
|
198
202
|
rails-dom-testing (2.3.0)
|
|
199
203
|
activesupport (>= 5.0.0)
|
|
200
204
|
minitest
|
|
201
205
|
nokogiri (>= 1.6)
|
|
202
|
-
rails-html-sanitizer (1.7.
|
|
203
|
-
loofah (~> 2.25, >= 2.25.
|
|
206
|
+
rails-html-sanitizer (1.7.2)
|
|
207
|
+
loofah (~> 2.25, >= 2.25.3)
|
|
204
208
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
205
|
-
railties (8.1.
|
|
206
|
-
actionpack (= 8.1.
|
|
207
|
-
activesupport (= 8.1.
|
|
209
|
+
railties (8.1.4.1)
|
|
210
|
+
actionpack (= 8.1.4.1)
|
|
211
|
+
activesupport (= 8.1.4.1)
|
|
208
212
|
irb (~> 1.13)
|
|
209
213
|
rackup (>= 1.0.0)
|
|
210
214
|
rake (>= 12.2)
|
data/README.md
CHANGED
|
@@ -263,6 +263,43 @@ rails db:migrate
|
|
|
263
263
|
```
|
|
264
264
|
|
|
265
265
|
|
|
266
|
+
### Shopify expiring offline access tokens
|
|
267
|
+
|
|
268
|
+
Shopify requires public apps to use **expiring offline access tokens** from
|
|
269
|
+
1 January 2027. They live 60 minutes, so a token read straight from the database
|
|
270
|
+
can already be dead. The gem no longer needs to read it: it asks your app for a
|
|
271
|
+
token and, if Shopify rejects it, asks again for a replacement.
|
|
272
|
+
|
|
273
|
+
**Apps still on non-expiring tokens need do nothing** - unset, the gem reads the
|
|
274
|
+
`field_names['shopify_token']` attribute through the shop model, as before.
|
|
275
|
+
|
|
276
|
+
**Shop model with `fresh_shopify_token`.** If your shop model has an instance
|
|
277
|
+
method `fresh_shopify_token` that returns a live token (renewing it if needed):
|
|
278
|
+
|
|
279
|
+
```ruby
|
|
280
|
+
AppManager.configure do |config|
|
|
281
|
+
config.shopify_token_resolver = AppManager::ModelTokenResolver
|
|
282
|
+
end
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
The gem calls `shop.fresh_shopify_token`. After Shopify rejects a token it calls it
|
|
286
|
+
again (with `force: true` if the method accepts a `force:` keyword) and replays the
|
|
287
|
+
request once, only if the result differs from the rejected token. If the model has no
|
|
288
|
+
such method, `shop.shopify_token` is read (through the model's accessor, so an encrypted column comes back decrypted), so the setting is safe before you migrate.
|
|
289
|
+
|
|
290
|
+
**Anything else.** Provide any object, class or class name responding to:
|
|
291
|
+
|
|
292
|
+
```ruby
|
|
293
|
+
class MyTokenResolver
|
|
294
|
+
def token(shop_domain); end # a token valid right now, or nil
|
|
295
|
+
def refresh(shop_domain); end # a replacement after a rejection, or nil
|
|
296
|
+
end
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
A 401, or a 403 saying `Non-expiring access tokens are no longer accepted`, counts as
|
|
300
|
+
a rejection. A 403 for a missing scope does not. Both methods run in web requests and
|
|
301
|
+
background jobs, so they must be safe to call concurrently for one shop.
|
|
302
|
+
|
|
266
303
|
<a name="step5"></a>
|
|
267
304
|
### Extras
|
|
268
305
|
|
|
@@ -23,7 +23,7 @@ module AppManager
|
|
|
23
23
|
active_charge_data = plan_obj.get_charge(params[:shop])
|
|
24
24
|
begin
|
|
25
25
|
if active_charge_data && active_charge_data.any? && !active_charge_data['active_charge'].nil? && !active_charge_data['active_charge']['charge_id'].nil?
|
|
26
|
-
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain
|
|
26
|
+
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain)
|
|
27
27
|
rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(active_charge_data['active_charge']['charge_id'], @shop)
|
|
28
28
|
if !rec_cancel_data["errors"].present? && (rec_cancel_data["data"].present? && rec_cancel_data["data"]["appSubscriptionCancel"].present? && !rec_cancel_data["data"]["appSubscriptionCancel"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
|
|
29
29
|
# cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
|
|
@@ -74,7 +74,7 @@ module AppManager
|
|
|
74
74
|
request_data.merge!('old_plan' => params['old_plan']) if params['old_plan'].present?
|
|
75
75
|
|
|
76
76
|
return_url = "#{app_url}#{plan_callback_path}?#{Rack::Utils.build_query(request_data)}"
|
|
77
|
-
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain
|
|
77
|
+
gq_obj = AppManager::GraphqlHelper.new(@shop.shopify_domain)
|
|
78
78
|
discount_local_storage = params[:discount_code].present? && !params[:discount_code].nil? ? params[:discount_code] : nil
|
|
79
79
|
data = gq_obj.recurring_charge_api_call(plan_data, return_url, @shop,discount_local_storage)
|
|
80
80
|
# Stash the discount snapshot so the callback can persist it on the charge row.
|
|
@@ -106,7 +106,6 @@ module AppManager
|
|
|
106
106
|
def callback
|
|
107
107
|
if params[:charge_id].present? && params[:shop].present? && params[:plan].present?
|
|
108
108
|
@shop = shop_data
|
|
109
|
-
shopify_token = @field_names['shopify_token']
|
|
110
109
|
shopify_domain = @field_names['name']
|
|
111
110
|
grandfathered_field = @field_names['grandfathered']
|
|
112
111
|
discounted_plans = []
|
|
@@ -114,12 +113,12 @@ module AppManager
|
|
|
114
113
|
old_plan_id = @shop[@plan_field]
|
|
115
114
|
old_plan_data = nil
|
|
116
115
|
raise Error, "Invalid charge" unless params[:charge_id].to_s.match?(/\A\d+\z/)
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
charges = AppManager::ShopifyApi.rest(@shop[shopify_domain], :get, "recurring_application_charges/#{params[:charge_id]}.json")
|
|
117
|
+
charges_body = (JSON.parse(charges.body.to_s) rescue nil)
|
|
119
118
|
|
|
120
|
-
if
|
|
119
|
+
if charges_body && charges_body.is_a?(Hash) && charges_body.has_key?('recurring_application_charge')
|
|
121
120
|
|
|
122
|
-
charge =
|
|
121
|
+
charge = charges_body['recurring_application_charge']
|
|
123
122
|
return redirect_to_app if charge['status'].to_s.downcase != 'active'
|
|
124
123
|
|
|
125
124
|
# Read the plan from Shopify's stored return_url: the query string can be edited.
|
|
@@ -209,7 +208,7 @@ module AppManager
|
|
|
209
208
|
redirect_to "#{app_url}?host=#{embed_host}&shop=#{params[:shop]}", :allow_other_host => true, :status => 301 and return
|
|
210
209
|
end
|
|
211
210
|
else
|
|
212
|
-
raise Error, "Invalid shopify charge #{charges.
|
|
211
|
+
raise Error, "Invalid shopify charge #{charges.code} #{charges.body.to_s[0, 500]}"
|
|
213
212
|
end
|
|
214
213
|
else
|
|
215
214
|
raise ModelNotFound, "Shop not found"
|
|
@@ -231,9 +230,8 @@ module AppManager
|
|
|
231
230
|
def cancel_charge
|
|
232
231
|
if params[:charge_id].present? && params[:shop].present?
|
|
233
232
|
@shop = shop_data
|
|
234
|
-
shopify_token = @field_names['shopify_token']
|
|
235
233
|
begin
|
|
236
|
-
gq_obj = AppManager::GraphqlHelper.new(@shop[@shopify_domain]
|
|
234
|
+
gq_obj = AppManager::GraphqlHelper.new(@shop[@shopify_domain])
|
|
237
235
|
rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(params[:charge_id], @shop)
|
|
238
236
|
rescue Exception => e
|
|
239
237
|
Rollbar.error("APP MANAGER Cancel Plan Failed #{e.inspect}-#{e.backtrace}")
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Commit and PR message standards
|
|
2
|
+
|
|
3
|
+
These rules apply to every repository whose merges to production are tracked in
|
|
4
|
+
Atlas. They are written for the AI tools that write most of our commit and PR
|
|
5
|
+
messages (Cursor, Claude Code, Copilot) and for the people reviewing them.
|
|
6
|
+
|
|
7
|
+
**Let your AI tool write the commit message and the PR title and description.** It
|
|
8
|
+
has the diff in front of it and, with this file in the repo, it knows the format.
|
|
9
|
+
Review what it writes rather than typing it by hand.
|
|
10
|
+
|
|
11
|
+
## Why it matters
|
|
12
|
+
|
|
13
|
+
Every merge into production becomes a deployment record in Atlas. The PR title and
|
|
14
|
+
description are all that record has to go on. They feed:
|
|
15
|
+
|
|
16
|
+
- the classifier behind our KPIs (what kind of change it was, and whether it
|
|
17
|
+
shipped an AI feature),
|
|
18
|
+
- the changelog and the daily deployment digest in `#production-deployments`,
|
|
19
|
+
- the Data AI Agent, when someone asks what shipped.
|
|
20
|
+
|
|
21
|
+
A merge described as `WIP` or `staging-v2` shows up as nothing in all of them.
|
|
22
|
+
A better model cannot fix an empty input.
|
|
23
|
+
|
|
24
|
+
## 1. The PR title is the one that counts
|
|
25
|
+
|
|
26
|
+
Most repos squash-merge, so **the PR title becomes the commit on `main`**. The
|
|
27
|
+
individual commit messages disappear, so put your care into the PR title and
|
|
28
|
+
description.
|
|
29
|
+
|
|
30
|
+
**Format:** `<JIRA-KEY>: <what changed, in plain words>`
|
|
31
|
+
|
|
32
|
+
- Say what changed **for the user or the system**, not which branch it came from.
|
|
33
|
+
- Use the imperative mood and keep it under about 72 characters.
|
|
34
|
+
- Put the Jira key first when there is one.
|
|
35
|
+
- Never use a branch name (`staging-v2`, `develop`, `testing to main`), `WIP`, `fix`,
|
|
36
|
+
`update` or `changes` as a title.
|
|
37
|
+
|
|
38
|
+
**Release / promotion PRs** (`develop` → `main`, `staging` → `master`,
|
|
39
|
+
`staging-v2` → `master-v2`):
|
|
40
|
+
`Release: <the two or three main things it carries>`
|
|
41
|
+
|
|
42
|
+
| Seen in production | How it should read |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `WIP` | `PRODOPS-612: Add per-option inventory limits` |
|
|
45
|
+
| `staging-v2` | `Release: billing link fix, upgrade button visibility (OP-3612)` |
|
|
46
|
+
| `testing to main` | `Release: shared options UI, sales-channel filter` |
|
|
47
|
+
| `Pull last app_kit version` | `Bump app_kit to 4.2.0 (brings the new billing banner)` |
|
|
48
|
+
|
|
49
|
+
## 2. End the PR description with this block
|
|
50
|
+
|
|
51
|
+
Atlas reads this block directly, so a merge described this way is classified
|
|
52
|
+
correctly without an AI having to guess.
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
Change type: New Feature
|
|
56
|
+
Feature scope: Minor
|
|
57
|
+
Short description: Merchants can cap how many of each option value can be sold.
|
|
58
|
+
Notes: Behind the inventory_limits flag until the 1 Oct rollout.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Change type**, exactly one of:
|
|
62
|
+
|
|
63
|
+
| Type | Use it for |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `New Feature` | User-facing functionality that didn't exist before: new screens, flows, capabilities. |
|
|
66
|
+
| `Improvement` | Making something that already exists better: performance, UX polish, copy, more options. |
|
|
67
|
+
| `Bug Fix` | A targeted fix for a defect shipped in an earlier release. |
|
|
68
|
+
| `Refactor` | Restructuring code with **no change in behaviour**. |
|
|
69
|
+
| `Security` | Anything motivated by security: patched vulnerability, auth check, rotated secret. |
|
|
70
|
+
| `Maintenance` | Dependency bumps, infra, CI/build changes, version bumps. |
|
|
71
|
+
|
|
72
|
+
**Feature scope:** `Major` or `Minor`.
|
|
73
|
+
- **Major** means a significant surface-area change: a new tab, a new API endpoint, a
|
|
74
|
+
migration, a behaviour change users will notice across many flows.
|
|
75
|
+
- **Minor** means a small, contained change: one bug fix, a copy tweak, one new option.
|
|
76
|
+
|
|
77
|
+
When in doubt, choose **Minor**.
|
|
78
|
+
|
|
79
|
+
**Short description:** one sentence a product manager would understand.
|
|
80
|
+
**Notes:** optional.
|
|
81
|
+
|
|
82
|
+
**Several changes in one PR?** Repeat the block once per change, starting each
|
|
83
|
+
block with a `Task:` line:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
Task: Inventory limits
|
|
87
|
+
Change type: New Feature
|
|
88
|
+
Feature scope: Major
|
|
89
|
+
Short description: Merchants can cap how many of each option value can be sold.
|
|
90
|
+
|
|
91
|
+
Task: Checkout crash
|
|
92
|
+
Change type: Bug Fix
|
|
93
|
+
Feature scope: Minor
|
|
94
|
+
Short description: Fixed a crash when an option set had no values.
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 3. Never merge a template unfilled
|
|
98
|
+
|
|
99
|
+
A PR template left with its headings, HTML comments, empty checkboxes and
|
|
100
|
+
`[Short description here]` placeholders looks like a long description to a machine
|
|
101
|
+
and says nothing to a person. Either fill it in or delete it.
|
|
102
|
+
|
|
103
|
+
## 4. Commits
|
|
104
|
+
|
|
105
|
+
With squash-merge, commit messages matter less, but they are still what a release
|
|
106
|
+
falls back on when nothing else describes it. So:
|
|
107
|
+
|
|
108
|
+
- Write one line that says what changed: `Handle error on charges`, not `fix`.
|
|
109
|
+
- Put the Jira key in the branch name or the commit (`OP-3612-upgrade-button`).
|
|
110
|
+
- Don't push work straight to `staging` / `develop` without a PR. A release built
|
|
111
|
+
from direct pushes leaves only commit messages to describe it.
|
|
112
|
+
|
|
113
|
+
## Where these rules are wired in
|
|
114
|
+
|
|
115
|
+
This repository contains the same rules for each AI tool:
|
|
116
|
+
|
|
117
|
+
- **Claude Code** reads `CLAUDE.md`, which imports this file.
|
|
118
|
+
- **Cursor** reads `.cursor/rules/commit-and-pr.mdc` (always applied).
|
|
119
|
+
- **Copilot** reads `.github/copilot-instructions.md`.
|
|
120
|
+
|
|
121
|
+
If you change the rules, change them here and keep the other three files in step.
|
data/lib/app_manager/config.rb
CHANGED
|
@@ -17,6 +17,9 @@ module AppManager
|
|
|
17
17
|
attr_accessor :shopify_app_slug
|
|
18
18
|
attr_accessor :most_popular_plan_ids
|
|
19
19
|
attr_accessor :plan_page_route
|
|
20
|
+
# Object/class/class-name responding to #token(shop_domain) and #refresh(shop_domain),
|
|
21
|
+
# e.g. AppManager::ModelTokenResolver. nil keeps the old behaviour: read the token column.
|
|
22
|
+
attr_accessor :shopify_token_resolver
|
|
20
23
|
|
|
21
24
|
def initialize
|
|
22
25
|
@refresh_by_request_params = true
|
|
@@ -5,7 +5,9 @@ module AppManager
|
|
|
5
5
|
# charge callback can persist it (value/type/duration/source) on the charge row.
|
|
6
6
|
attr_reader :discount_snapshot
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
# shopify_token is only a fallback for when the resolver has none; billing
|
|
9
|
+
# calls get their token from AppManager::ShopifyApi (the app's resolver).
|
|
10
|
+
def initialize(shopify_domain, shopify_token = nil)
|
|
9
11
|
@api_key = AppManager.configuration.shopify_api_key || nil
|
|
10
12
|
@api_version = AppManager.configuration.shopify_api_version || nil
|
|
11
13
|
@shopify_domain = shopify_domain
|
|
@@ -17,27 +19,29 @@ module AppManager
|
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def api_call(query,is_json=false)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
if !@api_key.nil? && !@api_version.nil? && !@shopify_domain.nil?
|
|
23
|
+
url = URI("https://#{@shopify_domain}/admin/api/#{@api_version}/graphql.json")
|
|
24
|
+
content_type = is_json.present? ? 'application/json' : 'application/graphql'
|
|
25
|
+
begin
|
|
26
|
+
response = AppManager::ShopifyApi.with_token(@shopify_domain, @shopify_token) do |token|
|
|
27
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
28
|
+
http.use_ssl = true
|
|
29
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
30
|
+
request = Net::HTTP::Post.new(url)
|
|
31
|
+
request["X-Shopify-Access-Token"] = token
|
|
32
|
+
request.body = query
|
|
33
|
+
request["Accept"] = 'application/json'
|
|
34
|
+
request["Content-Type"] = content_type
|
|
35
|
+
http.request(request)
|
|
36
|
+
end
|
|
37
|
+
rescue AppManager::MissingTokenError
|
|
38
|
+
Rollbar.error("=== no Shopify access token available for shopify_domain=#{@shopify_domain} ===")
|
|
39
|
+
return []
|
|
35
40
|
end
|
|
36
|
-
response = http.request(request)
|
|
37
41
|
response = ActiveSupport::JSON.decode(response.read_body) rescue nil
|
|
38
42
|
return response
|
|
39
43
|
else
|
|
40
|
-
Rollbar.error("=== params missing from any of these api_key=#{@api_key}, api_version=#{@api_version}, shopify_domain=#{@shopify_domain}
|
|
44
|
+
Rollbar.error("=== params missing from any of these api_key=#{@api_key}, api_version=#{@api_version}, shopify_domain=#{@shopify_domain} ===")
|
|
41
45
|
return []
|
|
42
46
|
end
|
|
43
47
|
end
|
data/lib/app_manager/model.rb
CHANGED
|
@@ -158,7 +158,7 @@ module AppManager
|
|
|
158
158
|
@field_names = AppManager.configuration.field_names
|
|
159
159
|
shopify_active_charge_id = self.active_shopify_charge_id
|
|
160
160
|
if shopify_active_charge_id.present?
|
|
161
|
-
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain
|
|
161
|
+
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain)
|
|
162
162
|
rec_cancel_data = gq_obj.recurring_charge_cancel_api_call(shopify_active_charge_id, self)
|
|
163
163
|
if !rec_cancel_data["errors"].present? && (rec_cancel_data["data"].present? && rec_cancel_data["data"]["appSubscriptionCancel"].present? && !rec_cancel_data["data"]["appSubscriptionCancel"]["userErrors"].any? && (rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["status"] == 'CANCELLED'))
|
|
164
164
|
cancelled_charge_id = rec_cancel_data["data"]["appSubscriptionCancel"]["appSubscription"]["id"].split('/')[-1]
|
|
@@ -177,7 +177,7 @@ module AppManager
|
|
|
177
177
|
|
|
178
178
|
def get_current_shopify_charge
|
|
179
179
|
begin
|
|
180
|
-
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain
|
|
180
|
+
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain)
|
|
181
181
|
data = gq_obj.recurring_charge_current_api_call(self)
|
|
182
182
|
if !data["errors"].present? && (data["data"].present? && data["data"]["currentAppInstallation"].present? && data["data"]["currentAppInstallation"]["activeSubscriptions"].present?)
|
|
183
183
|
return data["data"]["currentAppInstallation"]["activeSubscriptions"].first
|
|
@@ -274,7 +274,6 @@ module AppManager
|
|
|
274
274
|
# begin
|
|
275
275
|
@shop = shop
|
|
276
276
|
@field_names = AppManager.configuration.field_names
|
|
277
|
-
shopify_token = @field_names['shopify_token']
|
|
278
277
|
shopify_domain = @field_names['name']
|
|
279
278
|
grandfathered_field = @field_names['grandfathered']
|
|
280
279
|
shop_domain = @shop[AppManager.configuration.shopify_domain_field]
|
|
@@ -282,9 +281,9 @@ module AppManager
|
|
|
282
281
|
if charge_obj.present? && !charge_obj.nil?
|
|
283
282
|
shopify_charge_obj = charge_obj
|
|
284
283
|
else
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
shopify_charge_obj =
|
|
284
|
+
charges = AppManager::ShopifyApi.rest(shop_domain, :get, "recurring_application_charges/#{current_charge_id}.json")
|
|
285
|
+
charges_body = (JSON.parse(charges.body.to_s) rescue nil)
|
|
286
|
+
shopify_charge_obj = charges_body.is_a?(Hash) && charges_body.has_key?('recurring_application_charge') ? charges_body['recurring_application_charge'] : {}
|
|
288
287
|
end
|
|
289
288
|
|
|
290
289
|
if shopify_charge_obj.present?
|
|
@@ -339,7 +338,7 @@ module AppManager
|
|
|
339
338
|
def active_shopfiy_charge_full
|
|
340
339
|
active_charge_id = self.active_shopify_charge_id
|
|
341
340
|
if active_charge_id.present?
|
|
342
|
-
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain
|
|
341
|
+
gq_obj = AppManager::GraphqlHelper.new(self.shopify_domain)
|
|
343
342
|
rac_data = gq_obj.current_rc_charge_gql(active_charge_id)
|
|
344
343
|
return rac_data
|
|
345
344
|
else
|
|
@@ -348,7 +347,7 @@ module AppManager
|
|
|
348
347
|
end
|
|
349
348
|
|
|
350
349
|
def usage_charge_call(amount, description = '', shopify_charge_id = nil)
|
|
351
|
-
gq_obj = AppManager::GraphqlHelper.new(shopify_domain
|
|
350
|
+
gq_obj = AppManager::GraphqlHelper.new(shopify_domain)
|
|
352
351
|
|
|
353
352
|
# Validate amount is present and is a valid number
|
|
354
353
|
return 'Amount must be present and a positive float' if amount.blank? || !amount.is_a?(Numeric) || amount.to_f <= 0
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'uri'
|
|
3
|
+
|
|
4
|
+
module AppManager
|
|
5
|
+
# Raised when no Shopify access token is available for a shop at all.
|
|
6
|
+
class MissingTokenError < Error; end
|
|
7
|
+
|
|
8
|
+
# Default resolver: reads the token column of the configured shop table, which
|
|
9
|
+
# is what the gem has always done. Right for non-expiring offline tokens. It
|
|
10
|
+
# cannot mint a new token, so an app on expiring tokens must configure another.
|
|
11
|
+
class ColumnTokenResolver
|
|
12
|
+
def token(shop_domain)
|
|
13
|
+
value = read_token(find_shop(shop_domain))
|
|
14
|
+
value.to_s.empty? ? nil : value.to_s
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def refresh(_shop_domain)
|
|
18
|
+
nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# Read through the model's own accessor (like fresh_shopify_token), so an
|
|
24
|
+
# app that encrypts the column, or wraps it in a custom getter, gets the
|
|
25
|
+
# decrypted value. Only a model without the accessor is read by attribute.
|
|
26
|
+
def read_token(shop)
|
|
27
|
+
return nil if shop.nil?
|
|
28
|
+
|
|
29
|
+
field = AppManager.configuration.field_names['shopify_token'].to_s
|
|
30
|
+
shop.respond_to?(field) ? shop.public_send(field) : shop[field]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def find_shop(shop_domain)
|
|
34
|
+
config = AppManager.configuration
|
|
35
|
+
table = config.shopify_table_name
|
|
36
|
+
return nil unless ActiveRecord::Base.connection.tables.include?(table)
|
|
37
|
+
|
|
38
|
+
table.classify.constantize.find_by(config.shopify_domain_field => shop_domain)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# For apps whose shop model owns the token and renews it in an instance
|
|
43
|
+
# method, `fresh_shopify_token` (e.g. Shop#fresh_shopify_token). Set
|
|
44
|
+
# config.shopify_token_resolver = AppManager::ModelTokenResolver
|
|
45
|
+
#
|
|
46
|
+
# token -> shop.fresh_shopify_token
|
|
47
|
+
# refresh -> the same call after Shopify rejected the token. If the method
|
|
48
|
+
# accepts a `force:` keyword it is passed as true, so the app can
|
|
49
|
+
# renew regardless of its own expiry bookkeeping; the shop is also
|
|
50
|
+
# reloaded first. The gem replays only if the result differs from
|
|
51
|
+
# the rejected token.
|
|
52
|
+
#
|
|
53
|
+
# Falls back to the token column when the model does not define the method or
|
|
54
|
+
# cannot be found, so the config can be set before the model is migrated.
|
|
55
|
+
class ModelTokenResolver < ColumnTokenResolver
|
|
56
|
+
METHOD = :fresh_shopify_token
|
|
57
|
+
|
|
58
|
+
def token(shop_domain)
|
|
59
|
+
shop = find_shop(shop_domain)
|
|
60
|
+
return super unless shop.respond_to?(METHOD)
|
|
61
|
+
|
|
62
|
+
present(shop.public_send(METHOD)) || super
|
|
63
|
+
rescue StandardError => e
|
|
64
|
+
warn_failure('token', shop_domain, e)
|
|
65
|
+
super
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def refresh(shop_domain)
|
|
69
|
+
shop = find_shop(shop_domain)
|
|
70
|
+
return nil unless shop.respond_to?(METHOD)
|
|
71
|
+
|
|
72
|
+
present(call_forced(shop))
|
|
73
|
+
rescue StandardError => e
|
|
74
|
+
warn_failure('refresh', shop_domain, e)
|
|
75
|
+
nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def call_forced(shop)
|
|
81
|
+
accepts_force = shop.method(METHOD).parameters.any? { |type, name| name == :force && %i[key keyreq].include?(type) }
|
|
82
|
+
accepts_force ? shop.public_send(METHOD, force: true) : shop.public_send(METHOD)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def present(value)
|
|
86
|
+
value.to_s.empty? ? nil : value.to_s
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def warn_failure(what, shop_domain, error)
|
|
90
|
+
Rails.logger.warn("App Manager: #{METHOD} #{what} failed for #{shop_domain}: #{error.message}")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# The single path for every gem call to a shop's Admin API. It asks the app's
|
|
95
|
+
# resolver for a token and replays once with a replacement if Shopify rejects
|
|
96
|
+
# it. With the default resolver there is no replacement, so nothing changes.
|
|
97
|
+
#
|
|
98
|
+
# A resolver is any object responding to:
|
|
99
|
+
# token(shop_domain) -> a token valid right now, or nil
|
|
100
|
+
# refresh(shop_domain) -> a replacement after Shopify rejected token(), or nil
|
|
101
|
+
class ShopifyApi
|
|
102
|
+
NON_EXPIRING_REJECTED = 'Non-expiring access tokens are no longer accepted'.freeze
|
|
103
|
+
|
|
104
|
+
def self.resolver
|
|
105
|
+
configured = AppManager.configuration.shopify_token_resolver
|
|
106
|
+
configured = configured.constantize if configured.is_a?(String)
|
|
107
|
+
configured = configured.new if configured.is_a?(Class)
|
|
108
|
+
resolver = configured || ColumnTokenResolver.new
|
|
109
|
+
unless resolver.respond_to?(:token) && resolver.respond_to?(:refresh)
|
|
110
|
+
raise ArgumentError, 'AppManager shopify_token_resolver must respond to #token(shop_domain) and #refresh(shop_domain)'
|
|
111
|
+
end
|
|
112
|
+
resolver
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Sends a request to /admin/api/{version}/{path}. Returns a Net::HTTPResponse.
|
|
116
|
+
def self.rest(shop_domain, method, path, body: nil, headers: {})
|
|
117
|
+
url = URI("https://#{shop_domain}/admin/api/#{AppManager.configuration.shopify_api_version}/#{path.to_s.sub(%r{\A/}, '')}")
|
|
118
|
+
with_token(shop_domain) { |token| request(url, method, token, body, headers) }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Yields a token, expecting a response back. Replays exactly once, and only
|
|
122
|
+
# with a token that differs from the rejected one: if a fresh token is
|
|
123
|
+
# rejected too, the token is not what is wrong.
|
|
124
|
+
def self.with_token(shop_domain, fallback_token = nil)
|
|
125
|
+
resolver = self.resolver
|
|
126
|
+
token = resolver.token(shop_domain)
|
|
127
|
+
token = fallback_token if token.to_s.empty?
|
|
128
|
+
raise MissingTokenError, "No Shopify access token available for #{shop_domain}" if token.to_s.empty?
|
|
129
|
+
|
|
130
|
+
response = yield(token)
|
|
131
|
+
return response unless token_rejected?(response)
|
|
132
|
+
|
|
133
|
+
replacement = resolver.refresh(shop_domain)
|
|
134
|
+
return response if replacement.to_s.empty? || replacement == token
|
|
135
|
+
|
|
136
|
+
yield(replacement)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# A 403 is only a rejection when Shopify says the token type is the problem:
|
|
140
|
+
# a missing scope is also a 403 and a new token would not fix it.
|
|
141
|
+
def self.token_rejected?(response)
|
|
142
|
+
status = response.respond_to?(:code) ? response.code.to_i : 0
|
|
143
|
+
return true if status == 401
|
|
144
|
+
|
|
145
|
+
status == 403 && response.body.to_s.include?(NON_EXPIRING_REJECTED)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def self.request(url, method, token, body, headers)
|
|
149
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
150
|
+
http.use_ssl = true
|
|
151
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
152
|
+
req = Net::HTTP.const_get(method.to_s.capitalize).new(url)
|
|
153
|
+
req['X-Shopify-Access-Token'] = token
|
|
154
|
+
req['Accept'] = 'application/json'
|
|
155
|
+
headers.each { |key, value| req[key] = value }
|
|
156
|
+
req.body = body if body
|
|
157
|
+
http.request(req)
|
|
158
|
+
end
|
|
159
|
+
private_class_method :request
|
|
160
|
+
end
|
|
161
|
+
end
|
data/lib/app_manager/version.rb
CHANGED
data/lib/app_manager.rb
CHANGED
|
@@ -8,6 +8,8 @@ require "app_manager/engine"
|
|
|
8
8
|
require "app_manager/client"
|
|
9
9
|
require "app_manager/actions"
|
|
10
10
|
require "app_manager/api_cache_handler"
|
|
11
|
+
require "app_manager/exceptions"
|
|
12
|
+
require "app_manager/shopify_api"
|
|
11
13
|
require "app_manager/graphql_helper"
|
|
12
14
|
require "app_manager/response_cache"
|
|
13
15
|
require "app_manager/config"
|
|
@@ -22,6 +22,7 @@ AppManager.configure do |config|
|
|
|
22
22
|
'partner_development' => 'partner_development',
|
|
23
23
|
'total_trial_days' => '' #optional, put a trial days field from your shops table otherwise leave it blank
|
|
24
24
|
}
|
|
25
|
+
# config.shopify_token_resolver = AppManager::ModelTokenResolver # Optional, for Shopify expiring offline tokens: uses Shop#fresh_shopify_token (see README). Unset reads the shopify_token column
|
|
25
26
|
config.plan_features = [
|
|
26
27
|
{
|
|
27
28
|
"uuid" => "b48a3a6c-c1fb-11ec-9d64-0242ac120002",
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: app_manager
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rahul Tiwari @ Hulkapps
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -72,9 +72,13 @@ executables: []
|
|
|
72
72
|
extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
|
74
74
|
files:
|
|
75
|
+
- ".cursor/rules/commit-and-pr.mdc"
|
|
76
|
+
- ".github/copilot-instructions.md"
|
|
75
77
|
- ".github/workflows/ruby.yml"
|
|
76
78
|
- ".gitignore"
|
|
77
79
|
- ".rubocop.yml"
|
|
80
|
+
- CHANGELOG.md
|
|
81
|
+
- CLAUDE.md
|
|
78
82
|
- CODE_OF_CONDUCT.md
|
|
79
83
|
- Gemfile
|
|
80
84
|
- Gemfile.lock
|
|
@@ -104,6 +108,7 @@ files:
|
|
|
104
108
|
- bin/console
|
|
105
109
|
- bin/setup
|
|
106
110
|
- config/routes.rb
|
|
111
|
+
- docs/commit-and-pr-standards.md
|
|
107
112
|
- lib/app_manager.rb
|
|
108
113
|
- lib/app_manager/actions.rb
|
|
109
114
|
- lib/app_manager/api_cache_handler.rb
|
|
@@ -123,6 +128,7 @@ files:
|
|
|
123
128
|
- lib/app_manager/response_cache.rb
|
|
124
129
|
- lib/app_manager/session_token.rb
|
|
125
130
|
- lib/app_manager/set_local_storage.rb
|
|
131
|
+
- lib/app_manager/shopify_api.rb
|
|
126
132
|
- lib/app_manager/tasks/sync/local_app_manager.rake
|
|
127
133
|
- lib/app_manager/version.rb
|
|
128
134
|
- lib/generators/app_manager/install/install_generator.rb
|