kiosk-core 0.5.20

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e13d8c20ff22d54f80b08ce121162c575f73cf7159f2a623c9a52dc8afda820a
4
+ data.tar.gz: 4cd1571a390aad1e782ce844b2d35d7d4bfe2697466ad14b0e1ef3c49cf3cfc7
5
+ SHA512:
6
+ metadata.gz: 75e6135c30f091b70d05104c8179bcf275b4ec99a8e0e771981c7ab90ae3c6c2de8f180efc9d3d37ba0f16116e302843a6d1a945356cc163f337caabbbfd17b2
7
+ data.tar.gz: d9e5bbd82971df57550ace1912ef0d499b0066f7a7d325ea6c5e334063c37e132a4731602d5f7096bc101aa164b690acf7558dd83d85816710212f1314aed08f
data/CHANGELOG.md ADDED
@@ -0,0 +1,136 @@
1
+ # Changelog
2
+
3
+ All notable changes follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/).
4
+
5
+ How to write an entry, and what a release section means: `CHANGELOG-RULE.md` at
6
+ the root of this repository —
7
+ <https://github.com/kiosk-hq/kiosk/blob/main/CHANGELOG-RULE.md>. In short: under
8
+ 200 characters, one or two sentences, the essence rather than the content; write it
9
+ under `## [Unreleased]`; a cut renames that heading to
10
+ `## [MAJOR.MINOR.PATCH] — <date>` and opens a fresh empty one above it; nothing
11
+ already written is edited.
12
+
13
+ ## [Unreleased]
14
+
15
+ ## [0.5.20] — 2026-10-20
16
+
17
+ - 2026-10-20: Version 0.5.20, the tree cut that matches skill 0.5.20.
18
+
19
+ ## [0.5.19] — 2026-10-20
20
+
21
+ - 2026-10-20: `MIN_CLIENT` is the oldest skill cut the release works with: the same MAJOR.MINOR as `API_VERSION`, no newer.
22
+
23
+ ## [0.5.18] — 2026-10-18
24
+
25
+ - 2026-10-18: Version 0.5.18, the tree cut that matches skill 0.5.18.
26
+
27
+ ## [0.5.17] — 2026-10-18
28
+
29
+ - 2026-10-18: `refund` takes `key:`, which names the refund among the refunds of its charge; kiosk-pay-stripe keys the Stripe request by the charge and that key.
30
+ - 2026-10-18: `PaymentFailed` takes no `reason:`; the engine reads only its message and `retryable?`.
31
+ - 2026-10-18: `AgentIdentityProviders::Base` declares only `verify`; the engine never called `issue` or `agent_payment_key` on a configured `c.agent_idp`.
32
+
33
+ ## [0.5.16] — 2026-10-18
34
+
35
+ - 2026-10-18: `Kiosk::UuidCheck::JSON_SCHEMA_PATTERN` is removed.
36
+ - 2026-10-18: `Kiosk::Identity#agent?`, `#human?` and `#service?` are removed; read `actor`.
37
+ - 2026-10-18: `Kiosk::PaymentProviders::Base#refund(psp_reference:, amount_cents:)` is part of the port; the base raises `NotImplementedError`.
38
+ ## [0.5.15] — 2026-10-18
39
+
40
+ - 2026-10-18: Version 0.5.15, the tree cut that matches skill 0.5.15.
41
+
42
+ ## [0.5.14] — 2026-10-18
43
+
44
+ - 2026-10-18: Version 0.5.14, the tree cut that matches skill 0.5.14.
45
+
46
+ - 2026-10-18: `PaymentProviders::Base#resume` runs the capture again for a repeated chain. An adapter keys its capture by the cart mandate id, so a repeat cannot charge twice.
47
+
48
+ - 2026-10-17: `schema` and `guc_namespace` move to kiosk-server and `user_id_column` to kiosk-user-idp-devise, the gems that read them; `Kiosk.configure` sets them as before.
49
+
50
+ - 2026-10-17: `Configuration#guc` and `UserIdentityProviders::Base#user_active?` are removed; nothing called them.
51
+
52
+ ## [0.5.13] — 2026-10-11
53
+
54
+ - 2026-10-11: Version 0.5.13, the tree cut that matches skill 0.5.13; this gem's surface is unchanged.
55
+
56
+ ## [0.5.12] — 2026-10-08
57
+
58
+ - 2026-10-08: Version 0.5.12, the tree cut that matches skill 0.5.12; this gem's surface is unchanged.
59
+
60
+ ## [0.5.11] — 2026-10-08
61
+
62
+ - 2026-10-08: Version 0.5.11, the tree cut that matches skill 0.5.11; this gem's surface is unchanged.
63
+
64
+ ## [0.5.10] — 2026-10-08
65
+
66
+ - 2026-10-08: Version 0.5.10, the tree cut that matches skill 0.5.10; this gem's surface is unchanged.
67
+
68
+ ## [0.5.9] — 2026-10-08
69
+
70
+ - 2026-10-08: Version 0.5.9, the tree cut that matches skill 0.5.9; this gem's surface is unchanged.
71
+
72
+ ## [0.5.8] — 2026-10-07
73
+
74
+ - 2026-10-07: Version 0.5.8, the tree cut that matches skill 0.5.8; this gem's surface is unchanged.
75
+
76
+ ## [0.5.7] — 2026-10-07
77
+
78
+ - 2026-10-07: Version 0.5.7, the tree cut that matches skill 0.5.7; this gem's surface is unchanged.
79
+
80
+ ## [0.5.6] — 2026-10-07
81
+
82
+ - 2026-10-07: Version 0.5.6, the tree cut that matches skill 0.5.6; this gem's surface is unchanged.
83
+
84
+ ## [0.5.5] — 2026-10-07
85
+
86
+ - 2026-10-07: Version 0.5.5, the tree cut that matches skill 0.5.5; this gem's surface is unchanged.
87
+
88
+ ## [0.5.4] — 2026-10-07
89
+
90
+ - 2026-10-07: **`Kiosk::Protocol::API_VERSION` and `MIN_CLIENT` are `0.5.4`**, matching skill 0.5.4; a 0.5.3 assistant is told it is behind.
91
+
92
+ - 2026-10-07: **`KycProviders::Base` is the KYC provider port and `kyc_provider` its setting**, so kiosk-server opens verifications through any `kiosk-kyc-*` adapter (T-220).
93
+
94
+ - 2026-10-07: **`PaymentProviders::Base` declares `setup_url(user_id:, return_url:)`**, so an adapter written against the port serves `payment_setup` (T-219).
95
+
96
+ ## [0.5.3] — 2026-10-06
97
+
98
+ - 2026-10-06: **`Kiosk::Protocol::API_VERSION` and `MIN_CLIENT` are `0.5.3`**, matching skill 0.5.3; a 0.5.2 assistant is told it is behind.
99
+
100
+ ## [0.5.2] — 2026-10-06
101
+
102
+ - 2026-10-06: **`Kiosk::Protocol::API_VERSION` is `0.5.2`**: before 1.0 `Kiosk-API-Version` carries the full version every gem and the skill share.
103
+
104
+ - 2026-10-06: **`Kiosk::Protocol::MIN_CLIENT` is `0.5.2`**, so `Kiosk-Min-Client` and `kiosk.min_client` tell a 0.5.0 or 0.5.1 assistant it is behind a 0.5.2 origin.
105
+
106
+ - 2026-10-05: `c.additional_origins` lists further origins one deployment serves; `Kiosk.current_issuer` answers the origin of the request being served (ADR-0040).
107
+
108
+ ## [0.5.0] — 2026-09-26
109
+
110
+ - 2026-09-25: **README: «What is Kiosk» names the protocol, not a Postgres-backed app** (K-1810). The database belongs to this implementation, never to the wire.
111
+
112
+ ### Changed
113
+
114
+ - `UuidCheck`'s JSON Schema pattern IS enforced: the engine validates every verb's arguments against its `input_schema`. The doc said it validated nothing.
115
+ - The three adapter-base docs and the gemspec stop forecasting adapter gems that do not exist, and name what does.
116
+ - `Kiosk.configuration` serialises its FIRST read: racing first-touchers share one `Configuration` instead of each building their own. Later reads stay lock-free.
117
+ - README and `Identity` doc: the accessors are `Kiosk.configuration.user_id_type` / `.roles` — `Kiosk.user_id_type` and `Kiosk.roles` do not exist.
118
+ - `Kiosk::Protocol` gains `HEADER_TIMEZONE` (`Kiosk-Timezone`), the request header a caller declares its own clock in.
119
+ - README: every `gem` line in the install section now carries `github: "kiosk-hq/kiosk"`, so a copied line resolves before publication; the banner above them states what the block does rather than asking the reader to add it.
120
+ - `Kiosk::AgentIdentityProviders::Base` doc now states plainly that the
121
+ bundled `DefaultAgentIdp` ships as the default (zero config) and that
122
+ fronting an external agent-identity issuer is a PLANNED seam — no external
123
+ `kiosk-agent-idp-*` adapter ships yet (was overclaiming shipped adapters).
124
+ - `Kiosk::Configuration` gains `schema` (default "kiosk") and `app_role`
125
+ (default "app_role") — moved from kiosk-rls; they are deployment
126
+ vocabulary shared by kiosk-server, not RLS-specific.
127
+
128
+ ### Added
129
+
130
+ - `Kiosk::UuidCheck` — canonical-uuid shape guard for identifiers that arrive on the wire, with `PATTERN` (the runtime predicate) and `JSON_SCHEMA_PATTERN` (the same shape for a verb descriptor's `input_schema`) beside each other so the declared contract and the enforced one cannot drift. An origin that lets a malformed id reach a Postgres `uuid` cast answers either a 500 leaking SQL internals or a wrong ownership refusal; both are the origin's bug reported as something else.
131
+ - Initial skeleton.
132
+ - Value types: `Kiosk::Identity`, `Kiosk::Mandate::IntentMandate` / `CartMandate` / `PaymentMandate`.
133
+ - Abstract base classes: `AgentIdentityProviders::Base`, `UserIdentityProviders::Base`, `PaymentProviders::Base`.
134
+ - GUC namespace constants (`Kiosk::GUC`) with the four well-known names (`current_user_id`, `current_role`, `current_actor`, `current_agent_id`) and a composer (`Kiosk::GUC.for`).
135
+ - Configuration object (`Kiosk::Configuration`) and `Kiosk.configure { |c| ... }` block.
136
+ - Protocol-version surface (`Kiosk::Protocol`): `API_VERSION`, `MIN_CLIENT`, response-header names, default mount path.
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # kiosk-core
2
+
3
+ Core abstractions for the [Kiosk](https://kiosk.tech) framework.
4
+
5
+ ## What is Kiosk
6
+
7
+ Kiosk is the standards-based open protocol that lets your customers' AI assistants discover, transact with, and pay your service. Its Ruby reference implementation is a Rails engine: REST endpoint, multi-assistant identity per user, app-layer-authorized data plane with opt-in Postgres RLS defense-in-depth, AP2 mandate trail. Alpha. Apache-2.0.
8
+
9
+ ## What is kiosk-core
10
+
11
+ The foundation. Defines:
12
+
13
+ - **Value types** — `Kiosk::Identity`, `Kiosk::Mandate` (intent / cart / payment)
14
+ - **Abstract base classes** that adapter gems extend:
15
+ - `Kiosk::AgentIdentityProviders::Base`
16
+ - `Kiosk::UserIdentityProviders::Base`
17
+ - `Kiosk::PaymentProviders::Base`
18
+ - `Kiosk::KycProviders::Base`
19
+
20
+ An agent-IdP adapter's `agent_id` **must be a UUID string**: `Identity`
21
+ checks only that it is present, but every `agent_id` column in the canonical
22
+ Postgres schema and the `kiosk.current_agent_id()` helper are typed `uuid`,
23
+ and there is no `user_id_type`-style knob for it. Map a foreign issuer's
24
+ agent identifier onto a local uuid inside the adapter. `user_id`
25
+ carries no such constraint — it follows `c.user_id_type` (`Kiosk.configuration.user_id_type`).
26
+ - **Postgres GUC namespace constants** — `Kiosk::GUC`
27
+ - **Canonical-uuid shape guard** — `Kiosk::UuidCheck` (`valid?`)
28
+ - **Protocol-version surface** — `Kiosk::Protocol` (API version, min client, response header names, default mount path)
29
+ - **Configuration** — `Kiosk.configure { |c| ... }`
30
+
31
+ No Rails dependency. Loadable in any Ruby app. Heavier `kiosk-server`, `kiosk-rls`, and adapter gems build on top of this.
32
+
33
+ ## Install
34
+
35
+ > **Not on RubyGems yet** — so every `gem` line below carries `github: "kiosk-hq/kiosk"`, which is what makes it copy-pasteable today. Publication status and the canonical install are stated once, in the monorepo README's [Install](https://github.com/kiosk-hq/kiosk#install) section.
36
+
37
+ ```ruby
38
+ gem "kiosk-core", github: "kiosk-hq/kiosk"
39
+ ```
40
+
41
+ For the data plane (core + server), install the meta-gem — add RLS, payment, and IdP adapters per stack:
42
+
43
+ ```ruby
44
+ gem "kiosk-all", github: "kiosk-hq/kiosk"
45
+ ```
46
+
47
+ ## Status
48
+
49
+ Pre-v1.0 alpha. Wire-protocol semver stability begins at v1.0; pre-v1.0 minor bumps may break compatibility (CHANGELOG.md tracks).
50
+
51
+ ## License
52
+
53
+ Apache-2.0 — see `LICENSE.txt`.
54
+
55
+ ## Links
56
+
57
+ - [kiosk.tech](https://kiosk.tech) — landing + docs
58
+ - [Specification](https://kiosk.tech/specification.html) — the normative spec
59
+ - [Issue tracker](https://github.com/kiosk-hq/kiosk/issues)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ module AgentIdentityProviders
5
+ # Base for an agent-IdP adapter fronting an external agent-identity issuer
6
+ # (`c.agent_idp`). The engine calls only `verify`: it mints tokens and reads
7
+ # mandate-signing keys through its bundled DefaultAgentIdp. The `agent_id` it
8
+ # returns must be a uuid: every schema column and `kiosk.current_agent_id()`
9
+ # are typed `uuid`, so map foreign ids.
10
+ class Base
11
+ # @return [Kiosk::Identity, nil] nil when the credential is absent or invalid (the caller answers 401)
12
+ def verify(_request)
13
+ raise NotImplementedError, "#{self.class}#verify must be implemented by the adapter"
14
+ end
15
+ end
16
+
17
+ class InvalidToken < StandardError; end
18
+ end
19
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+
5
+ module Kiosk
6
+ # Host-application settings, filled via `Kiosk.configure`. Defaults suit a greenfield
7
+ # Rails app on the bundled agent-IdP; the provider supplies its own user
8
+ # model and (optionally) a user-IdP adapter.
9
+ class Configuration
10
+ # Class name as a String, resolved at request time.
11
+ attr_accessor :user_model
12
+
13
+ # :uuid (default), :bigint, :integer or :text.
14
+ attr_accessor :user_id_type
15
+
16
+ # Nil in satellite mode: the provider's own frontend drives the wire endpoints.
17
+ attr_accessor :user_idp
18
+
19
+ # Nil uses kiosk-server's bundled DefaultAgentIdp; set only to front another agent-identity system.
20
+ attr_accessor :agent_idp
21
+
22
+ # A {Kiosk::PaymentProviders::Base}; nil means no payment.
23
+ attr_accessor :payment_provider
24
+
25
+ # A {Kiosk::KycProviders::Base}; nil makes `request_kyc` answer `module_not_served`.
26
+ attr_accessor :kyc_provider
27
+
28
+ # Runtime DB role named in kiosk-rls GRANTs and `SET LOCAL ROLE`; the DBA creates it.
29
+ attr_accessor :app_role
30
+
31
+ # E.g. `%i[customer master support]`. Never `:admin`.
32
+ attr_accessor :roles
33
+
34
+ # The default origin served: `iss` of tokens and mandates, required proof `aud`,
35
+ # discovery `issuer`. Readers ask `Kiosk.current_issuer`.
36
+ attr_accessor :issuer
37
+
38
+ # Further origins, each a separate operator on the wire. Exact origins only;
39
+ # an alias of the SAME business is better redirected
40
+ # to the issuer at the edge. (Rails' `config.hosts` governs which Host
41
+ # headers are accepted, not which origin the operator is.)
42
+ attr_accessor :additional_origins
43
+
44
+ def initialize
45
+ @user_id_type = :uuid
46
+ @app_role = 'app_role'
47
+ @roles = []
48
+ @additional_origins = []
49
+ end
50
+
51
+ def origins
52
+ [issuer, *additional_origins].compact.map { |o| self.class.normalize_origin(o) }.compact.uniq
53
+ end
54
+
55
+ # The Host only selects among declared origins; it never adds one.
56
+ def issuer_for(origin)
57
+ normalized = self.class.normalize_origin(origin)
58
+ origins.include?(normalized) ? normalized : issuer
59
+ end
60
+
61
+ # Lower-case scheme and host, default port dropped; nil unless an absolute http(s) URL.
62
+ def self.normalize_origin(value)
63
+ uri = URI.parse(value.to_s.strip)
64
+ return unless uri.is_a?(URI::HTTP) && uri.host
65
+
66
+ port = uri.port == uri.default_port ? '' : ":#{uri.port}"
67
+ "#{uri.scheme.downcase}://#{uri.host.downcase}#{port}"
68
+ rescue URI::InvalidURIError
69
+ nil
70
+ end
71
+ end
72
+ end
data/lib/kiosk/guc.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ # Postgres GUC names that carry identity from the request into the session.
5
+ module GUC
6
+ DEFAULT_NAMESPACE = 'app'
7
+
8
+ USER_ID = 'current_user_id'
9
+ ROLE = 'current_role'
10
+ ACTOR = 'current_actor'
11
+ AGENT_ID = 'current_agent_id'
12
+
13
+ def self.for(namespace, name)
14
+ "#{namespace}.#{name}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ # The principal making a request, as an IdP adapter's #verify returns it.
5
+ # `actor` is "agent", "human" or "service"; `agent_id` is present iff the
6
+ # actor is an agent and must be a uuid (the schema types it so, with no knob).
7
+ Identity = Data.define(:user_id, :role, :actor, :agent_id, :claims)
8
+
9
+ # Validates user_id, actor and agent_id on construction.
10
+ class Identity
11
+ VALID_ACTORS = %w[agent human service].freeze
12
+
13
+ def initialize(user_id:, role:, actor:, agent_id: nil, claims: {})
14
+ actor = actor.to_s
15
+ validate!(user_id, actor, agent_id)
16
+ role = role.to_s
17
+ super(user_id:, role: (role unless role.empty?), actor:, agent_id:, claims: claims || {})
18
+ end
19
+
20
+ private
21
+
22
+ def validate!(user_id, actor, agent_id)
23
+ raise ArgumentError, 'user_id required' if user_id.nil?
24
+
25
+ validate_actor!(actor)
26
+ validate_agent_id!(actor, agent_id)
27
+ end
28
+
29
+ def validate_actor!(actor)
30
+ return if VALID_ACTORS.include?(actor)
31
+
32
+ raise ArgumentError, "actor must be one of #{VALID_ACTORS.inspect}, got #{actor.inspect}"
33
+ end
34
+
35
+ def validate_agent_id!(actor, agent_id)
36
+ if actor == 'agent'
37
+ raise ArgumentError, "agent_id required when actor == 'agent'" if agent_id.to_s.empty?
38
+ elsif agent_id
39
+ raise ArgumentError, "agent_id must be nil when actor != 'agent' (got actor=#{actor.inspect})"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ module KycProviders
5
+ # The provider did not open a verification now; a later attempt may.
6
+ class Unavailable < StandardError
7
+ end
8
+
9
+ # Port for a KYC provider (`kiosk-kyc-*`); kiosk-server serves `request_kyc`
10
+ # whenever `Kiosk.configuration.kyc_provider` is set.
11
+ class Base
12
+ # The provider later POSTs `{request_id, nonce, kyc_jws}` to `callback_url`.
13
+ # @return [Hash] `request_id:`, `verification_url:`, `nonce:`
14
+ # @raise [Unavailable]
15
+ def open_verification(subject:, claims:, audience:, callback_url:)
16
+ raise NotImplementedError, "#{self.class}#open_verification must be implemented by the adapter"
17
+ end
18
+
19
+ # Provider-specific checks after the engine verified signature, iss, aud, sub, level and exp.
20
+ def accepts?(_payload) = true
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ # AP2 (Agent Payments Protocol) mandate value objects.
5
+ # Each is a JWS the assistant signs; its `iss` must equal the origin's issuer.
6
+ module Mandate
7
+ IntentMandate = Data.define(
8
+ :id, :user_id, :agent_id, :issuer, :scope, :cap_amount_cents, :currency,
9
+ :expires_at, :created_at, :raw_jws
10
+ )
11
+
12
+ CartMandate = Data.define(
13
+ :id, :intent_mandate_id, :user_id, :agent_id, :issuer, :line_items,
14
+ :total_amount_cents, :currency, :expires_at, :created_at, :raw_jws
15
+ )
16
+
17
+ PaymentMandate = Data.define(
18
+ :id, :cart_mandate_id, :user_id, :agent_id, :issuer, :payment_method,
19
+ :amount_cents, :currency, :expires_at, :created_at, :raw_jws
20
+ )
21
+ end
22
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ module PaymentProviders
5
+ # The principal has nothing to charge yet; their human must finish {Base#setup_url} first.
6
+ class SetupRequired < StandardError
7
+ end
8
+
9
+ # A charge failed at the processor. `retryable?` is true only when nothing
10
+ # was charged; false means the outcome is unknown, so reconcile, do not retry.
11
+ class PaymentFailed < StandardError
12
+ def initialize(message = 'payment failed', retryable: false)
13
+ super(message)
14
+ @retryable = retryable
15
+ end
16
+
17
+ def retryable? = @retryable
18
+ end
19
+
20
+ # Port for a payment processor adapter (`kiosk-pay-*`). An adapter that also
21
+ # defines `setup_return_user_id(params)` gets the `payment_setup` event topic.
22
+ class Base
23
+ # Asked before the mandate trail is persisted.
24
+ def setup_required?(user_id:) # rubocop:disable Lint/UnusedMethodArgument
25
+ false
26
+ end
27
+
28
+ # The page the human opens to make payment possible; the PSP returns the browser to `return_url`.
29
+ def setup_url(user_id:, return_url:)
30
+ raise NotImplementedError, "#{self.class}#setup_url must be implemented by an adapter " \
31
+ 'whose setup_required? can answer true'
32
+ end
33
+
34
+ # @return [Hash] `psp_reference`, `settled_amount_cents`, `settled_at`
35
+ def capture(_cart_mandate, payment_method:)
36
+ raise NotImplementedError, "#{self.class}#capture must be implemented by the adapter"
37
+ end
38
+
39
+ # Returns `amount_cents` of the charge `psp_reference` to the card. `key`
40
+ # names this refund among the refunds of that charge: a repeat with the
41
+ # same key is the same refund, so a retry cannot refund twice.
42
+ # @return [Hash] `psp_reference` (of the refund), `refunded_psp_reference`, `refunded_amount_cents`, `refunded_at`
43
+ def refund(psp_reference:, amount_cents:, key:)
44
+ raise NotImplementedError, "#{self.class}#refund must be implemented by an adapter whose operator refunds"
45
+ end
46
+
47
+ # A repeat of a chain whose capture did not complete. The adapter keys its
48
+ # capture by the cart mandate id, so a second capture cannot charge twice.
49
+ def resume(cart_mandate, payment_method:) = capture(cart_mandate, payment_method:)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ # Wire-protocol version and header names.
5
+ module Protocol
6
+ # Before 1.0 every gem and every pinned skill cut carry this exact version (spec §14.1).
7
+ API_VERSION = '0.5.20'
8
+
9
+ # The oldest skill cut that works with this release: same MAJOR.MINOR as
10
+ # API_VERSION, no newer (spec §3.6). Advisory.
11
+ MIN_CLIENT = '0.5.20'
12
+
13
+ HEADER_SERVER_VERSION = 'Kiosk-Server-Version'
14
+ HEADER_API_VERSION = 'Kiosk-API-Version'
15
+ HEADER_MIN_CLIENT = 'Kiosk-Min-Client'
16
+
17
+ # Request header: the caller's IANA time zone, for reading a bare date argument.
18
+ HEADER_TIMEZONE = 'Kiosk-Timezone'
19
+
20
+ DEFAULT_MOUNT_PATH = '/kiosk'
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ module UserIdentityProviders
5
+ # Base for a user-IdP adapter (`kiosk-user-idp-*`): consumes whatever already
6
+ # authenticates the principal at the provider.
7
+ class Base
8
+ # @return [Kiosk::Identity, nil]
9
+ def verify(_request)
10
+ raise NotImplementedError, "#{self.class}#verify must be implemented by the adapter"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ # Shape check for wire-supplied uuids, so a malformed id is a typed 4xx rather
5
+ # than a 500 from Postgres or a false ownership refusal from Active Record's
6
+ # NULL cast. Format only: it says nothing about whether the row exists.
7
+ module UuidCheck
8
+ # Canonical 8-4-4-4-12 only, so a refusal can name exactly what to send.
9
+ PATTERN = /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
10
+
11
+ def self.valid?(value)
12
+ PATTERN.match?(value.to_s)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kiosk
4
+ VERSION = '0.5.20'
5
+ end
data/lib/kiosk.rb ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # kiosk-core — foundation for the Kiosk framework (https://kiosk.tech).
4
+
5
+ require 'kiosk/version'
6
+ require 'kiosk/protocol'
7
+ require 'kiosk/guc'
8
+ require 'kiosk/configuration'
9
+ require 'kiosk/identity'
10
+ require 'kiosk/mandate'
11
+ require 'kiosk/uuid_check'
12
+
13
+ require 'kiosk/agent_identity_providers/base'
14
+ require 'kiosk/user_identity_providers/base'
15
+ require 'kiosk/payment_providers/base'
16
+ require 'kiosk/kyc_providers/base'
17
+
18
+ module Kiosk
19
+ # Serialises the first build of {configuration}, so racing threads never
20
+ # each build one and lose settings written on a discarded copy.
21
+ CONFIGURATION_MUTEX = Mutex.new
22
+
23
+ def self.configure
24
+ yield(configuration)
25
+ end
26
+
27
+ def self.configuration
28
+ @configuration ||
29
+ CONFIGURATION_MUTEX.synchronize { @configuration ||= Configuration.new }
30
+ end
31
+
32
+ CURRENT_ISSUER_KEY = :kiosk_current_issuer
33
+
34
+ # The origin of the request being served, or the configured issuer outside one.
35
+ def self.current_issuer
36
+ Thread.current[CURRENT_ISSUER_KEY] || configuration.issuer
37
+ end
38
+
39
+ def self.with_issuer(issuer)
40
+ previous = Thread.current[CURRENT_ISSUER_KEY]
41
+ Thread.current[CURRENT_ISSUER_KEY] = issuer
42
+ yield
43
+ ensure
44
+ Thread.current[CURRENT_ISSUER_KEY] = previous
45
+ end
46
+
47
+ def self.reset!
48
+ CONFIGURATION_MUTEX.synchronize { @configuration = Configuration.new }
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kiosk-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.20
5
+ platform: ruby
6
+ authors:
7
+ - Phil Pirozhkov
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: |
13
+ kiosk-core is the foundation for the Kiosk framework. It defines the value
14
+ types (Identity, Mandate), the abstract base classes adapters extend
15
+ (AgentIdentityProviders, UserIdentityProviders, PaymentProviders,
16
+ KycProviders), the Postgres GUC namespace constants, the protocol-version
17
+ surface, the canonical-uuid shape guard (UuidCheck), and the Kiosk.configure
18
+ block.
19
+
20
+ No Rails dependency. Loadable in any Ruby app; the heavier kiosk-server
21
+ and kiosk-rls gems build on top of this.
22
+ email:
23
+ - hello@fili.pp.ru
24
+ executables: []
25
+ extensions: []
26
+ extra_rdoc_files: []
27
+ files:
28
+ - CHANGELOG.md
29
+ - LICENSE.txt
30
+ - README.md
31
+ - lib/kiosk.rb
32
+ - lib/kiosk/agent_identity_providers/base.rb
33
+ - lib/kiosk/configuration.rb
34
+ - lib/kiosk/guc.rb
35
+ - lib/kiosk/identity.rb
36
+ - lib/kiosk/kyc_providers/base.rb
37
+ - lib/kiosk/mandate.rb
38
+ - lib/kiosk/payment_providers/base.rb
39
+ - lib/kiosk/protocol.rb
40
+ - lib/kiosk/user_identity_providers/base.rb
41
+ - lib/kiosk/uuid_check.rb
42
+ - lib/kiosk/version.rb
43
+ homepage: https://kiosk.tech
44
+ licenses:
45
+ - Apache-2.0
46
+ metadata:
47
+ homepage_uri: https://kiosk.tech
48
+ source_code_uri: https://github.com/kiosk-hq/kiosk
49
+ changelog_uri: https://github.com/kiosk-hq/kiosk/blob/main/kiosk-core/CHANGELOG.md
50
+ bug_tracker_uri: https://github.com/kiosk-hq/kiosk/issues
51
+ rubygems_mfa_required: 'true'
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '4.0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 4.0.3
67
+ specification_version: 4
68
+ summary: Core abstractions for Kiosk — value types, abstract bases, GUC constants,
69
+ configuration
70
+ test_files: []