fintoc 1.9.0 → 1.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da4a9b4fedf94553216b95ab3f9b82836530bec85cedf2975a5796eb06b509aa
4
- data.tar.gz: 990ac87930fab9e5bfaaa832e9eb5e45eb2f0380f612017f005e86dbc443ec84
3
+ metadata.gz: 60e9c0d402a45ce1462059bf4cb5b5f206e7b5a1c79ff2bd61834299af6fce01
4
+ data.tar.gz: 89a7c33461389bb3a5190e63d99df22d5afe1c7091fb1cc50595426ff6e84311
5
5
  SHA512:
6
- metadata.gz: ffdc7c130de48280a1c39da9edeed0eec1d4eac65b2a52855a663a8b7fcd9e967835ca0f75f415fb66795911d154ed5b0682be0caba9555b4120ba4424a0849a
7
- data.tar.gz: 38c4644259c6fd97d3877e465f10ac47d95c813962dd287acbe1eaf192cbed1d7e64c5461c05a67ea6a1fa1f00c058ef97acde4f19ae6ab300e23a515742d59d
6
+ metadata.gz: 28388ad1d43d031493f881874ed5f0a6370c4113500c3e0a8a15ea4bab031c330ab7ed54340aab2ec1852274a1c4615021f8a994a1d61756c89cbd8f6887d918
7
+ data.tar.gz: 2d6f01f3d34afc8a68ed2a212734b1f48f5c61381714179c5b6333790abfa4f589486a04206bc56e476b65fdb28014129de60ca727b75be26cda522f07569004
@@ -24,6 +24,15 @@ de cambios específicos también es bienvenido.
24
24
  - [x] Tests unitarios para x
25
25
  - [x] Tests de integración entre x e y
26
26
 
27
+ ## Release notes
28
+
29
+ <!--
30
+ Si este PR debe publicar una versión, agrega el label release:patch, release:minor
31
+ o release:major y escribe aquí, en inglés, lo que verán los usuarios del SDK.
32
+ Si queda vacío, se usan las notas autogeneradas de GitHub.
33
+ Los PRs sin label no publican.
34
+ -->
35
+
27
36
  ## Safety Checks
28
37
 
29
38
  - [ ] Versión y CHANGELOG actualizados (si corresponde)
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env bash
2
+ # Decide the bump and release notes for the release workflow.
3
+ # Writes `bump` (empty means skip the release) and `notes` to $GITHUB_OUTPUT.
4
+ #
5
+ # Required env: EVENT_NAME, GITHUB_OUTPUT
6
+ # workflow_dispatch: INPUT_BUMP, INPUT_NOTES
7
+ # push: SHA, PULLS_JSON (response of GET repos/{repo}/commits/{sha}/pulls)
8
+ set -euo pipefail
9
+
10
+ extract_release_notes() {
11
+ perl -0777 -ne '
12
+ s/\r//g;
13
+ s/<!--.*?-->//gs;
14
+ if (/^##[ \t]+Release notes[ \t]*$(.*?)(?=^##[ \t]|\z)/msi) {
15
+ my $notes = $1;
16
+ $notes =~ s/^\s+|\s+$//g;
17
+ print $notes;
18
+ }
19
+ '
20
+ }
21
+
22
+ trim() {
23
+ perl -0777 -pe 's/^\s+|\s+$//g'
24
+ }
25
+
26
+ write_output() {
27
+ local bump=$1 notes=$2 delimiter
28
+ delimiter="RELEASE_NOTES_$(openssl rand -hex 16)"
29
+ {
30
+ echo "bump=$bump"
31
+ echo "notes<<$delimiter"
32
+ printf '%s\n' "$notes"
33
+ echo "$delimiter"
34
+ } >> "$GITHUB_OUTPUT"
35
+ }
36
+
37
+ skip_release() {
38
+ echo "::notice::$1 Skipping release."
39
+ write_output "" ""
40
+ }
41
+
42
+ resolve_from_dispatch() {
43
+ write_output "$INPUT_BUMP" "$(printf '%s' "${INPUT_NOTES:-}" | trim)"
44
+ }
45
+
46
+ resolve_from_push() {
47
+ local pr number labels label_count bump
48
+ pr=$(jq -c --arg sha "$SHA" \
49
+ 'map(select(.merged_at != null and .merge_commit_sha == $sha)) | first // empty' \
50
+ <<< "$PULLS_JSON")
51
+ if [ -z "$pr" ]; then
52
+ skip_release "No merged PR found for $SHA."
53
+ return
54
+ fi
55
+
56
+ number=$(jq -r '.number' <<< "$pr")
57
+ labels=$(jq -r '[.labels[].name | select(startswith("release:"))] | join(" ")' <<< "$pr")
58
+ label_count=$(jq '[.labels[].name | select(startswith("release:"))] | length' <<< "$pr")
59
+
60
+ if [ "$label_count" -eq 0 ]; then
61
+ skip_release "PR #$number has no release:* label."
62
+ return
63
+ fi
64
+ if [ "$label_count" -gt 1 ]; then
65
+ echo "::error::PR #$number has more than one release:* label ($labels). Keep only one."
66
+ exit 1
67
+ fi
68
+
69
+ bump=${labels#release:}
70
+ case "$bump" in
71
+ patch|minor|major) ;;
72
+ *)
73
+ echo "::error::PR #$number has an unknown label $labels. Use release:patch, release:minor or release:major."
74
+ exit 1
75
+ ;;
76
+ esac
77
+
78
+ echo "Releasing PR #$number with bump $bump."
79
+ write_output "$bump" "$(jq -r '.body // ""' <<< "$pr" | extract_release_notes)"
80
+ }
81
+
82
+ case "$EVENT_NAME" in
83
+ workflow_dispatch) resolve_from_dispatch ;;
84
+ push) resolve_from_push ;;
85
+ *)
86
+ echo "::error::Unsupported event $EVENT_NAME."
87
+ exit 1
88
+ ;;
89
+ esac
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env bash
2
+ set -uo pipefail
3
+
4
+ SCRIPT="$(dirname "$0")/resolve-release.sh"
5
+ SHA=abc123
6
+ failures=0
7
+
8
+ pulls_json() {
9
+ local labels=$1 body=$2
10
+ jq -nc --arg sha "$SHA" --arg body "$body" --argjson labels "$labels" \
11
+ '[{number: 7, merged_at: "2026-01-01T00:00:00Z", merge_commit_sha: $sha,
12
+ body: $body, labels: ($labels | map({name: .}))}]'
13
+ }
14
+
15
+ read_output() {
16
+ local file=$1 name=$2
17
+ awk -v name="$name" '
18
+ index($0, name "=") == 1 { print substr($0, length(name) + 2); exit }
19
+ index($0, name "<<") == 1 { delimiter = substr($0, length(name) + 3); reading = 1; next }
20
+ reading && $0 == delimiter { exit }
21
+ reading { print }
22
+ ' "$file"
23
+ }
24
+
25
+ assert_release() {
26
+ local description=$1 expected_status=$2 expected_bump=$3 expected_notes=$4
27
+ shift 4
28
+ local output status
29
+ output=$(mktemp)
30
+ env GITHUB_OUTPUT="$output" "$@" bash "$SCRIPT" > /dev/null
31
+ status=$?
32
+
33
+ if [ "$status" -ne "$expected_status" ]; then
34
+ echo "FAIL: $description (exit $status, expected $expected_status)"
35
+ failures=$((failures + 1))
36
+ elif [ "$expected_status" -eq 0 ] &&
37
+ { [ "$(read_output "$output" bump)" != "$expected_bump" ] ||
38
+ [ "$(read_output "$output" notes)" != "$expected_notes" ]; }; then
39
+ echo "FAIL: $description"
40
+ echo " bump: '$(read_output "$output" bump)' expected '$expected_bump'"
41
+ echo " notes: '$(read_output "$output" notes)' expected '$expected_notes'"
42
+ failures=$((failures + 1))
43
+ else
44
+ echo "ok: $description"
45
+ fi
46
+ rm -f "$output"
47
+ }
48
+
49
+ assert_push() {
50
+ local description=$1 expected_status=$2 expected_bump=$3 expected_notes=$4 labels=$5 body=$6
51
+ assert_release "$description" "$expected_status" "$expected_bump" "$expected_notes" \
52
+ EVENT_NAME=push SHA="$SHA" PULLS_JSON="$(pulls_json "$labels" "$body")"
53
+ }
54
+
55
+ assert_push "notes section at the end, comments stripped" 0 minor $'- Added X.\n- Removed Y.' \
56
+ '["bug", "release:minor"]' \
57
+ $'## Contexto\nctx\n\n## Release notes\n\n<!-- instructions\nspanning lines -->\n\n- Added X.\n- Removed Y.\n'
58
+
59
+ assert_push "notes section followed by another section" 0 patch $'Fixed X.\n### Details\nmore' \
60
+ '["release:patch"]' \
61
+ $'## Release notes\r\n\r\nFixed X.\r\n### Details\r\nmore\r\n\r\n## Rollback\r\nsafe\r\n'
62
+
63
+ assert_push "notes section with only a comment" 0 major "" \
64
+ '["release:major"]' $'## Release notes\n<!-- empty -->\n## Rollback\nx'
65
+
66
+ assert_push "no notes section" 0 patch "" '["release:patch"]' $'## Contexto\nctx'
67
+
68
+ assert_push "PR without release label is skipped" 0 "" "" '["bug"]' $'## Release notes\nx'
69
+
70
+ assert_push "more than one release label fails" 1 "" "" '["release:patch", "release:minor"]' "x"
71
+
72
+ assert_push "unknown release label fails" 1 "" "" '["release:hotfix"]' "x"
73
+
74
+ assert_release "push without merged PR is skipped" 0 "" "" \
75
+ EVENT_NAME=push SHA="$SHA" PULLS_JSON='[{"number": 8, "merged_at": null, "merge_commit_sha": "abc123", "labels": [{"name": "release:patch"}], "body": ""}]'
76
+
77
+ assert_release "workflow_dispatch uses the inputs" 0 minor "notes here" \
78
+ EVENT_NAME=workflow_dispatch INPUT_BUMP=minor INPUT_NOTES=$' \n notes here\n'
79
+
80
+ assert_release "workflow_dispatch with empty notes" 0 patch "" \
81
+ EVENT_NAME=workflow_dispatch INPUT_BUMP=patch INPUT_NOTES=""
82
+
83
+ [ "$failures" -eq 0 ] || { echo "$failures failing case(s)"; exit 1; }
@@ -26,6 +26,17 @@ jobs:
26
26
  - name: Run RuboCop
27
27
  run: bundle exec rubocop
28
28
 
29
+ release-scripts:
30
+ runs-on: ubuntu-latest
31
+ name: Test release scripts
32
+
33
+ steps:
34
+ - name: Checkout code
35
+ uses: actions/checkout@v4
36
+
37
+ - name: Test resolve-release
38
+ run: .github/scripts/resolve-release.test.sh
39
+
29
40
  test:
30
41
  runs-on: ubuntu-latest
31
42
  strategy:
@@ -1,6 +1,8 @@
1
1
  name: release
2
2
 
3
3
  on:
4
+ push:
5
+ branches: [main]
4
6
  workflow_dispatch:
5
7
  inputs:
6
8
  bump:
@@ -14,15 +16,72 @@ on:
14
16
  type: string
15
17
  required: false
16
18
 
19
+ permissions: {}
20
+
17
21
  jobs:
22
+ resolve:
23
+ runs-on: blacksmith-2vcpu-ubuntu-2404
24
+ permissions:
25
+ contents: read
26
+ pull-requests: read
27
+ outputs:
28
+ bump: ${{ steps.resolve.outputs.bump }}
29
+ notes: ${{ steps.resolve.outputs.notes }}
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+ with:
33
+ persist-credentials: false
34
+
35
+ - name: Find merged PR
36
+ id: pulls
37
+ if: github.event_name == 'push'
38
+ env:
39
+ GH_TOKEN: ${{ github.token }}
40
+ run: |
41
+ for attempt in 1 2 3; do
42
+ pulls=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" --jq 'tojson')
43
+ if [ "$pulls" != "[]" ] || [ "$attempt" -eq 3 ]; then break; fi
44
+ sleep 10
45
+ done
46
+ echo "json=$pulls" >> "$GITHUB_OUTPUT"
47
+
48
+ - name: Resolve bump and release notes
49
+ id: resolve
50
+ env:
51
+ EVENT_NAME: ${{ github.event_name }}
52
+ SHA: ${{ github.sha }}
53
+ INPUT_BUMP: ${{ inputs.bump }}
54
+ INPUT_NOTES: ${{ inputs.release-notes }}
55
+ PULLS_JSON: ${{ steps.pulls.outputs.json }}
56
+ run: .github/scripts/resolve-release.sh
57
+
18
58
  release:
19
- if: github.ref == 'refs/heads/main'
20
- runs-on: ubuntu-latest
59
+ needs: resolve
60
+ if: github.ref == 'refs/heads/main' && needs.resolve.outputs.bump != ''
61
+ runs-on: blacksmith-2vcpu-ubuntu-2404
62
+ concurrency:
63
+ group: release
64
+ cancel-in-progress: false
21
65
  permissions:
22
66
  contents: write
23
67
  id-token: write
24
68
  steps:
25
69
  - uses: actions/checkout@v4
70
+ with:
71
+ ref: main
72
+
73
+ - name: Check main has no other changes after the merged PR
74
+ if: github.event_name == 'push'
75
+ env:
76
+ GH_TOKEN: ${{ github.token }}
77
+ run: |
78
+ head=$(git rev-parse HEAD)
79
+ later=$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$head" \
80
+ --jq '[.commits[] | select(.author.login != "fin-releases[bot]" or (.commit.message | startswith("release: ") | not)) | .sha[0:7]] | join(" ")')
81
+ if [ -n "$later" ]; then
82
+ echo "::error::main has commits merged after $GITHUB_SHA ($later). Aborting so they are not published with this PR's bump and notes. The next release will include this PR; use workflow_dispatch if it needs a bigger bump."
83
+ exit 1
84
+ fi
26
85
 
27
86
  - uses: ruby/setup-ruby@v1
28
87
  with:
@@ -37,17 +96,36 @@ jobs:
37
96
  - uses: fintoc-com/release-action/prepare@main
38
97
  id: prep
39
98
  with:
40
- bump: ${{ inputs.bump }}
99
+ bump: ${{ needs.resolve.outputs.bump }}
41
100
  version-format: ruby
42
101
  tag-prefix: v
102
+ push: 'true'
43
103
  app-id: ${{ vars.FIN_RELEASES_APP_ID }}
44
104
  app-private-key: ${{ secrets.FIN_RELEASES_PRIVATE_KEY }}
45
105
 
106
+ - name: Fall back to auto-generated release notes
107
+ id: notes
108
+ env:
109
+ GH_TOKEN: ${{ github.token }}
110
+ TAG: ${{ steps.prep.outputs.tag }}
111
+ NOTES: ${{ needs.resolve.outputs.notes }}
112
+ run: |
113
+ if [ -z "${NOTES//[[:space:]]/}" ]; then
114
+ NOTES=$(gh api -X POST "repos/$GITHUB_REPOSITORY/releases/generate-notes" \
115
+ -f tag_name="$TAG" -f target_commitish="$GITHUB_SHA" --jq '.body')
116
+ fi
117
+ delimiter="RELEASE_NOTES_$(openssl rand -hex 16)"
118
+ {
119
+ echo "body<<$delimiter"
120
+ printf '%s\n' "$NOTES"
121
+ echo "$delimiter"
122
+ } >> "$GITHUB_OUTPUT"
123
+
46
124
  - uses: rubygems/release-gem@v1
47
125
 
48
126
  - uses: fintoc-com/release-action/finalize@main
49
127
  with:
50
128
  tag: ${{ steps.prep.outputs.tag }}
51
- release-notes: ${{ inputs.release-notes }}
129
+ release-notes: ${{ steps.notes.outputs.body }}
52
130
  app-id: ${{ vars.FIN_RELEASES_APP_ID }}
53
131
  app-private-key: ${{ secrets.FIN_RELEASES_PRIVATE_KEY }}
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fintoc (1.9.0)
4
+ fintoc (1.10.0)
5
5
  http
6
6
  money-rails
7
7
  tabulate
data/README.md CHANGED
@@ -150,7 +150,7 @@ disputes = client.v1.disputes.list(status: 'needs_response')
150
150
  client.v1.disputes.create_document('dispute_id', file: 'path/to/evidence.pdf')
151
151
  client.v1.disputes.submit_for_review('dispute_id')
152
152
 
153
- # Referred organizations (live mode only). The request is signed with the JWS private key
153
+ # Referred organizations
154
154
  organization = client.v1.organizations.create(
155
155
  name: 'Empresa SpA',
156
156
  tax_id: '11.111.111-1',
@@ -158,6 +158,11 @@ organization = client.v1.organizations.create(
158
158
  products: { business_accounts: {} },
159
159
  external_reference: 'SOL-123'
160
160
  )
161
+ client.v1.organizations.update(
162
+ organization.id,
163
+ founder_email: 'new-founder@example.com',
164
+ previous_founder_email: 'founder@example.com'
165
+ )
161
166
  ```
162
167
 
163
168
  ### **API V2 Client**
@@ -51,7 +51,7 @@ module Fintoc
51
51
  content = JSON.parse(response.body, symbolize_names: true)
52
52
 
53
53
  if response.status.client_error? || response.status.server_error?
54
- raise_custom_error(content[:error])
54
+ raise_custom_error(content[:error], response.status.code)
55
55
  end
56
56
 
57
57
  @link_headers = response.headers.get('link')
@@ -147,8 +147,10 @@ module Fintoc
147
147
  value.respond_to?(:read) || (value.is_a?(String) && File.file?(value))
148
148
  end
149
149
 
150
- def raise_custom_error(error)
151
- raise error_class(error[:code]).new(error[:message], error[:doc_url])
150
+ def raise_custom_error(error, status)
151
+ raise error_class(error[:code]).new(
152
+ error[:message], error[:doc_url], status:, code: error[:code]
153
+ )
152
154
  end
153
155
 
154
156
  def error_class(snake_code)
data/lib/fintoc/errors.rb CHANGED
@@ -3,11 +3,19 @@ require 'fintoc/constants'
3
3
  module Fintoc
4
4
  module Errors
5
5
  class FintocError < StandardError
6
- def initialize(message, doc_url = Fintoc::Constants::GENERAL_DOC_URL)
6
+ # HTTP status of the API response (Integer), or nil when not raised from a response.
7
+ # API error code, such as 'invalid_institution_id' (String), or nil.
8
+ attr_reader :status, :code
9
+
10
+ def initialize(
11
+ message, doc_url = Fintoc::Constants::GENERAL_DOC_URL, status: nil, code: nil
12
+ )
7
13
  super(message)
8
14
 
9
15
  @message = message
10
16
  @doc_url = doc_url
17
+ @status = status
18
+ @code = code
11
19
  end
12
20
 
13
21
  def message
@@ -131,6 +139,7 @@ module Fintoc
131
139
  class InvalidUrlError < FintocError; end
132
140
  class OrganizationWithoutEntitiesError < FintocError; end
133
141
  class ResourceNotFoundError < FintocError; end
142
+ class FounderEmailMismatchError < FintocError; end
134
143
 
135
144
  # 405 Method Not Allowed Errors
136
145
  class OperationNotAllowedError < FintocError; end
@@ -156,6 +165,7 @@ module Fintoc
156
165
  class DisputeNotOpenForDocumentsError < FintocError; end
157
166
  class DuplicateRecipientError < FintocError; end
158
167
  class EntityHolderIdAlreadyExistsForOrganizationError < FintocError; end
168
+ class FounderAlreadyActivatedError < FintocError; end
159
169
  class InvalidEmptySubscriptionError < FintocError; end
160
170
  class InvoiceNotEditableError < FintocError; end
161
171
  class InvoiceNotFinalizableError < FintocError; end
@@ -169,6 +179,8 @@ module Fintoc
169
179
 
170
180
  # 422 Unprocessable Entity Errors
171
181
  class AccountBlockedForDirectDebitError < FintocError; end
182
+ class FounderEmailChangeLimitReachedError < FintocError; end
183
+ class InvalidHolderNameError < FintocError; end
172
184
  class InvalidOtpCodeError < FintocError; end
173
185
  class InvalidProductsError < FintocError; end
174
186
  class InvalidTaxIdError < FintocError; end
@@ -9,11 +9,18 @@ module Fintoc
9
9
  end
10
10
 
11
11
  def create(name:, tax_id:, founder_email:, products:, **params)
12
- data = @client.post(version: :v1, use_jws: true)
12
+ data = @client.post(version: :v1)
13
13
  .call('organizations', name:, tax_id:, founder_email:, products:, **params)
14
14
  build_organization(data)
15
15
  end
16
16
 
17
+ def update(organization_id, founder_email:, previous_founder_email:)
18
+ data = @client.patch(version: :v1)
19
+ .call("organizations/#{organization_id}", founder_email:,
20
+ previous_founder_email:)
21
+ build_organization(data)
22
+ end
23
+
17
24
  private
18
25
 
19
26
  def build_organization(data)
@@ -1,3 +1,3 @@
1
1
  module Fintoc
2
- VERSION = '1.9.0'
2
+ VERSION = '1.10.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fintoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Ca Sardin
@@ -59,6 +59,8 @@ extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
61
  - ".github/pull_request_template.md"
62
+ - ".github/scripts/resolve-release.sh"
63
+ - ".github/scripts/resolve-release.test.sh"
62
64
  - ".github/workflows/ci.yml"
63
65
  - ".github/workflows/release.yml"
64
66
  - ".gitignore"