gokashi commited on
Commit
6870e27
·
verified ·
1 Parent(s): 0d8754d

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. deps/deep_merge/.fetch +0 -0
  2. deps/deep_merge/.formatter.exs +9 -0
  3. deps/deep_merge/.hex +0 -0
  4. deps/deep_merge/CHANGELOG.md +16 -0
  5. deps/deep_merge/LICENSE.md +21 -0
  6. deps/deep_merge/README.md +123 -0
  7. deps/deep_merge/hex_metadata.config +14 -0
  8. deps/deep_merge/lib/deep_merge.ex +145 -0
  9. deps/deep_merge/lib/deep_merge/resolver.ex +122 -0
  10. deps/deep_merge/mix.exs +70 -0
  11. deps/eini/.hex +0 -0
  12. deps/eini/LICENSE +202 -0
  13. deps/eini/README.md +37 -0
  14. deps/eini/_build/default/plugins/hex_core/CHANGELOG.md +222 -0
  15. deps/eini/_build/default/plugins/hex_core/LICENSE +191 -0
  16. deps/eini/_build/default/plugins/hex_core/README.md +244 -0
  17. deps/eini/_build/default/plugins/hex_core/ebin/hex_api.beam +0 -0
  18. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_auth.beam +0 -0
  19. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_key.beam +0 -0
  20. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_oauth.beam +0 -0
  21. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_organization.beam +0 -0
  22. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_organization_member.beam +0 -0
  23. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_package.beam +0 -0
  24. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_package_owner.beam +0 -0
  25. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_release.beam +0 -0
  26. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_short_url.beam +0 -0
  27. deps/eini/_build/default/plugins/hex_core/ebin/hex_api_user.beam +0 -0
  28. deps/eini/_build/default/plugins/hex_core/ebin/hex_core.app +20 -0
  29. deps/eini/_build/default/plugins/hex_core/ebin/hex_core.beam +0 -0
  30. deps/eini/_build/default/plugins/hex_core/ebin/hex_erl_tar.beam +0 -0
  31. deps/eini/_build/default/plugins/hex_core/ebin/hex_filename.beam +0 -0
  32. deps/eini/_build/default/plugins/hex_core/ebin/hex_http.beam +0 -0
  33. deps/eini/_build/default/plugins/hex_core/ebin/hex_http_httpc.beam +0 -0
  34. deps/eini/_build/default/plugins/hex_core/ebin/hex_licenses.beam +0 -0
  35. deps/eini/_build/default/plugins/hex_core/ebin/hex_pb_names.beam +0 -0
  36. deps/eini/_build/default/plugins/hex_core/ebin/hex_pb_package.beam +0 -0
  37. deps/eini/_build/default/plugins/hex_core/ebin/hex_pb_signed.beam +0 -0
  38. deps/eini/_build/default/plugins/hex_core/ebin/hex_pb_versions.beam +0 -0
  39. deps/eini/_build/default/plugins/hex_core/ebin/hex_registry.beam +0 -0
  40. deps/eini/_build/default/plugins/hex_core/ebin/hex_repo.beam +0 -0
  41. deps/eini/_build/default/plugins/hex_core/ebin/hex_safe_binary_to_term.beam +0 -0
  42. deps/eini/_build/default/plugins/hex_core/ebin/hex_tarball.beam +0 -0
  43. deps/eini/_build/default/plugins/hex_core/ebin/safe_erl_term.beam +0 -0
  44. deps/eini/_build/default/plugins/hex_core/hex_metadata.config +27 -0
  45. deps/eini/_build/default/plugins/hex_core/rebar.config +67 -0
  46. deps/eini/_build/default/plugins/hex_core/rebar.config.script +9 -0
  47. deps/eini/_build/default/plugins/hex_core/rebar.lock +1 -0
  48. deps/eini/_build/default/plugins/hex_core/src/hex_api.erl +186 -0
  49. deps/eini/_build/default/plugins/hex_core/src/hex_api_oauth.erl +201 -0
  50. deps/eini/_build/default/plugins/hex_core/src/hex_api_package_owner.erl +109 -0
deps/deep_merge/.fetch ADDED
File without changes
deps/deep_merge/.formatter.exs ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ inputs: [
3
+ "lib/**/*.{ex,exs}",
4
+ "test/**/*.{ex,exs}",
5
+ "mix/**/*.{ex,exs}",
6
+ "./mix.exs",
7
+ ]
8
+ ]
9
+
deps/deep_merge/.hex ADDED
Binary file (274 Bytes). View file
 
deps/deep_merge/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## 1.0.0 (2019-03-26)
2
+
3
+ * Added the possibility to `@derive [DeepMerge.Resolver]` if you want your custom structs to also easily be deep_mergeable
4
+ * added type specs
5
+ * Changed elixir support to ~> 1.6
6
+
7
+ Considered feature complete (tm) - unless you come with great feature ideas of course ;)
8
+
9
+ ## 0.2.0 (2018-07-27)
10
+
11
+ * Remove compile warnings on elixir 1.7
12
+ * Remove 1.2 from the build matrix (was getting big, should still work)
13
+
14
+ ## 0.1.1 (2016-11-29)
15
+
16
+ * Remove warnings when run with elixir 1.4.0-rc.0
deps/deep_merge/LICENSE.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Tobias Pfeiffer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
deps/deep_merge/README.md ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # DeepMerge [![Hex Version](https://img.shields.io/hexpm/v/deep_merge.svg)](https://hex.pm/packages/deep_merge) [![docs](https://img.shields.io/badge/docs-hexpm-blue.svg)](https://hexdocs.pm/deep_merge/) [![Build Status](https://travis-ci.org/PragTob/deep_merge.svg?branch=master)](https://travis-ci.org/PragTob/deep_merge) [![Coverage Status](https://coveralls.io/repos/github/PragTob/deep_merge/badge.svg?branch=master)](https://coveralls.io/github/PragTob/deep_merge?branch=master) [![Inline docs](http://inch-ci.org/github/PragTob/deep_merge.svg?branch=master)](http://inch-ci.org/github/PragTob/deep_merge)
2
+
3
+ Provides functionality for "deep merging" maps and keyword lists in elixir, which is if during merging both values at the same key are maps/keyword lists merge them recursively. This is done via a protocol so can be extended for your own structs/data types if needbe.
4
+
5
+ ```
6
+ iex> DeepMerge.deep_merge(%{a: 1, b: [x: 10, y: 9]}, %{b: [y: 20, z: 30], c: 4})
7
+ %{a: 1, b: [x: 10, y: 20, z: 30], c: 4}
8
+ ```
9
+
10
+ This functionality can be useful for instance when merging a default configuration with a user supplied custom configuration:
11
+
12
+ ```elixir
13
+ DeepMerge.deep_merge(default_config, custom_config) # => merged configuration
14
+ ```
15
+
16
+ Further features include:
17
+
18
+ * It handles both maps and keyword lists
19
+ * It does not merge structs or maps with structs…
20
+ * …but you can implement the simple DeepMerge.Resolver protocol for types/structs of your choice to also make them deep mergable (there is also a default implementation)
21
+ * a deep_merge/3 variant that gets a function similar to Map.merge/3 to modify the merging behavior, for instance in case you don't want keyword lists to be merged or you want all lists to be appended
22
+
23
+ I wanted this to be a feature of Elixir itself, however the proposal [was rejected](https://github.com/elixir-lang/elixir/pull/5339) hence this library exists :)
24
+
25
+ ## Installation
26
+
27
+ Add `deep_merge` to your list of dependencies in `mix.exs`:
28
+
29
+ ```elixir
30
+ def deps do
31
+ [{:deep_merge, "~> 1.0"}]
32
+ end
33
+ ```
34
+
35
+ ## General Usage - deep_merge/2
36
+
37
+ Using this library is quite simple (and you might also want to look at the [hexdocs](https://hexdocs.pm/deep_merge/api-reference.html)) - just pass two structures to be deep merged into `DeepMerge.deep_merge/2`:
38
+
39
+ ```elixir
40
+ iex> DeepMerge.deep_merge(%{a: 1, b: %{x: 10, y: 9}}, %{b: %{y: 20, z: 30}, c: 4})
41
+ %{a: 1, b: %{x: 10, y: 20, z: 30}, c: 4}
42
+
43
+ iex> DeepMerge.deep_merge([a: 1, b: [x: 10, y: 9]], [b: [y: 20, z: 30], c: 4])
44
+ [a: 1, b: [x: 10, y: 20, z: 30], c: 4]
45
+ ```
46
+
47
+ It is worth noting that structs are not deeply merged - not with each other and not with normal maps. This is because structs, while internally a map, are more like their own data types and therefore should not be deeply merged... unless you implement the protocol provided by this library for them.
48
+
49
+ ## Customization via protocols
50
+
51
+ What is merged and how is defined by implementing the `DeepMerge.Resolver` protocol. This library implements it for `Map`, `List` and falls back to `Any` (where the right hand side value/override is taken).
52
+
53
+ If you want your own struct to be deeply merged you can simply `@derive` the protocole:
54
+
55
+ ```elixir
56
+ defmodule Derived do
57
+ @derive [DeepMerge.Resolver]
58
+ defstruct [:attrs]
59
+ end
60
+ ```
61
+
62
+
63
+ If you want to change the deep merge for a custom struct you can do so. An example implementation might look like this if you want to deeply merge your struct but only against non `nil` values (because all keys are always there) if you merge against the same struct (but still merge with maps):
64
+
65
+ ```elixir
66
+ defimpl DeepMerge.Resolver, for: MyStruct do
67
+ def resolve(original, override = %MyStruct{}, resolver) do
68
+ cleaned_override =
69
+ override
70
+ |> Map.from_struct()
71
+ |> Enum.reject(fn {_key, value} -> is_nil(value) end)
72
+ |> Map.new()
73
+
74
+ Map.merge(original, cleaned_override, resolver)
75
+ end
76
+
77
+ def resolve(original, override, resolver) when is_map(override) do
78
+ Map.merge(original, override, resolver)
79
+ end
80
+ end
81
+ ```
82
+
83
+ In this implementation, `MyStruct` structs are merged with other `MyStruct` structs, omitting nil values. The arguments passed to `resolve` are the original value (left hand side) and the override value (right hand side, which would normally replace the original). The third parameter is a `resolver` function which you can pass to `Map.merge/3`/`Keyword.merge/3` to continue the deep merge.
84
+
85
+ ## Customization via deep_merge/3
86
+
87
+ There is another deep merge variant that is a bit like `Map.merge/3` as it takes an additional function which you can use to alter the deep merge behavior:
88
+
89
+ ```elixir
90
+ iex> resolver = fn
91
+ ...> (_, original, override) when is_list(original) and is_list(override) ->
92
+ ...> override
93
+ ...> (_, _original, _override) ->
94
+ ...> DeepMerge.continue_deep_merge
95
+ ...> end
96
+ iex> DeepMerge.deep_merge(%{a: %{b: 1}, c: [d: 1]},
97
+ ...> %{a: %{z: 5}, c: [x: 0]}, resolver)
98
+ %{a: %{b: 1, z: 5}, c: [x: 0]}
99
+ ```
100
+
101
+ This function is called for a given merge conflict with the key where it occured and the two conflicting values. Whatever value is returned in this function is inserted at that point in the structure - unless `DeepMerge.continue_deep_merge` is returned in which case the deep merge continues as normal.
102
+
103
+ When would you want to use this versus a protocol? The best use case I can think of is when you want to alter behavior for which a protocol is already implemented or if you care about specific keys.
104
+
105
+ In the example above the behavior is changed so that keyword lists are not deep_merged (if they were the result would contain `c: [d: 1, x:0]`), but maps still are if that's what you are looking for.
106
+
107
+ ## Do I really need a library for this?
108
+
109
+ Well not necessarily, no. There are [very simple implementations for maps that use Map.merge/3](http://stackoverflow.com/a/38865647).
110
+
111
+ There are subtle things that can be missed there though (and I missed the first time around):
112
+
113
+ * the most simple implementation also merges structs which is not always what you want
114
+ * For keyword lists on the other hand you gotta be careful that you don't accidentally merge keyword lists with lists as that's [currently possible](https://github.com/elixir-lang/elixir/issues/5395)
115
+ * you might want to further adopt the implementation, in [benchee](https://github.com/bencheeorg/benchee) we have 2 custom implementations of the protocol due to our needs
116
+
117
+ This library takes care of those problems and will take care of further problems/edge cases should they appear so you can focus on your business logic.
118
+
119
+ At the same time it offers extension mechanisms through protocols and a function in `deep_merge/3`. So, it should be adjustable to your use case and if not please open an issue :)
120
+
121
+ ## Considered feature-complete
122
+
123
+ Unless you come with great feature ideas of course ;) So if you come here and there are no recent commits, don't worry - there are no known bugs or whatever. It's a small little library that does its job.
deps/deep_merge/hex_metadata.config ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {<<"app">>,<<"deep_merge">>}.
2
+ {<<"build_tools">>,[<<"mix">>]}.
3
+ {<<"description">>,
4
+ <<"Deep (recursive) merging for maps, keyword lists and whatever else\nyou may want via implementing a simple protocol.">>}.
5
+ {<<"elixir">>,<<"~> 1.6">>}.
6
+ {<<"files">>,
7
+ [<<"lib">>,<<"lib/deep_merge.ex">>,<<"lib/deep_merge">>,
8
+ <<"lib/deep_merge/resolver.ex">>,<<".formatter.exs">>,<<"mix.exs">>,
9
+ <<"README.md">>,<<"LICENSE.md">>,<<"CHANGELOG.md">>]}.
10
+ {<<"licenses">>,[<<"MIT">>]}.
11
+ {<<"links">>,[{<<"github">>,<<"https://github.com/PragTob/deep_merge">>}]}.
12
+ {<<"name">>,<<"deep_merge">>}.
13
+ {<<"requirements">>,[]}.
14
+ {<<"version">>,<<"1.0.0">>}.
deps/deep_merge/lib/deep_merge.ex ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defmodule DeepMerge do
2
+ @moduledoc """
3
+ Provides functionality for deeply/recursively merging structures (normally for
4
+ `Map` and `Keyword`).
5
+
6
+ If you want to change the deep merge behavior of a custom struct,
7
+ please have a look at the `DeepMerge.Resolver` protocol.
8
+ """
9
+
10
+ alias DeepMerge.Resolver
11
+ @continue_symbol :__deep_merge_continue
12
+
13
+ @doc """
14
+ Deeply merges two maps or keyword list `original` and `override`.
15
+
16
+ In more detail, if two conflicting values are maps or keyword lists themselves
17
+ then they will also be merged recursively. This is an extension in that sense
18
+ to what `Map.merge/2` and `Keyword.merge/2` do as it doesn't just override map
19
+ or keyword values but tries to merge them.
20
+
21
+ It does not merge structs or structs with maps. If you want your structs to be
22
+ merged then please have a look at the `DeepMerge.Resolver` protocol and
23
+ consider implementing/deriving it.
24
+
25
+ Also, while it says `Map` and `Keyword` here, it is really dependent on which
26
+ types implement the `DeepMerge.Resolver` protocol, which by default are `Map`
27
+ and `Keyword`.
28
+
29
+ ## Examples
30
+
31
+ iex> DeepMerge.deep_merge(%{a: 1, b: [x: 10, y: 9]}, %{b: [y: 20, z: 30], c: 4})
32
+ %{a: 1, b: [x: 10, y: 20, z: 30], c: 4}
33
+
34
+ iex> DeepMerge.deep_merge(%{a: 1, b: %{x: 10, y: 9}}, %{b: %{y: 20, z: 30}, c: 4})
35
+ %{a: 1, b: %{x: 10, y: 20, z: 30}, c: 4}
36
+
37
+ iex> DeepMerge.deep_merge(%{a: 1, b: %{x: 10, y: 9}}, %{b: %{y: 20, z: 30}, c: 4})
38
+ %{a: 1, b: %{x: 10, y: 20, z: 30}, c: 4}
39
+
40
+ iex> DeepMerge.deep_merge([a: 1, b: [x: 10, y: 9]], [b: [y: 20, z: 30], c: 4])
41
+ [a: 1, b: [x: 10, y: 20, z: 30], c: 4]
42
+
43
+ iex> DeepMerge.deep_merge(%{a: 1, b: 2}, %{b: 3, c: 4})
44
+ %{a: 1, b: 3, c: 4}
45
+
46
+ iex> DeepMerge.deep_merge(%{a: 1, b: %{x: 10, y: 9}}, %{b: 5, c: 4})
47
+ %{a: 1, b: 5, c: 4}
48
+
49
+ iex> DeepMerge.deep_merge([a: [b: [c: 1, d: 2], e: [24]]], [a: [b: [f: 3], e: [42, 100]]])
50
+ [a: [b: [c: 1, d: 2, f: 3], e: [42, 100]]]
51
+
52
+ iex> DeepMerge.deep_merge(%{a: 1, b: 5}, %{b: %{x: 10, y: 9}, c: 4})
53
+ %{a: 1, b: %{x: 10, y: 9}, c: 4}
54
+
55
+ iex> DeepMerge.deep_merge(%{a: [b: %{c: [d: "foo", e: 2]}]}, %{a: [b: %{c: [d: "bar"]}]})
56
+ %{a: [b: %{c: [e: 2, d: "bar"]}]}
57
+ """
58
+ @spec deep_merge(map() | keyword(), map | keyword()) :: map() | keyword()
59
+ def deep_merge(original, override)
60
+ when (is_map(original) or is_list(original)) and (is_map(override) or is_list(override)) do
61
+ standard_resolve(nil, original, override)
62
+ end
63
+
64
+ @doc """
65
+ A variant of `DeepMerge.deep_merge/2` that allows to modify the merge behavior
66
+ through the additional passed in function.
67
+
68
+ This is similar to the relationship between `Map.merge/2` and `Map.merge/3`
69
+ and the structure of the function is exactly the same, e.g. the passed in
70
+ arguments are `key`, `original` and `override`.
71
+
72
+ The function is called before a merge is performed. If it returns any value
73
+ that value is inserted at that point during the deep_merge. If the deep merge
74
+ should continue like normal you need to return the symbol returned by
75
+ `DeepMerge.continue_deep_merge/0`.
76
+
77
+ If the merge conflict occurs at the top level then `key` is `nil`.
78
+
79
+ The example shows how this can be used to modify `deep_merge` not to merge
80
+ keyword lists, in case you don't like that behavior.
81
+
82
+ ## Examples
83
+
84
+ iex> resolver = fn
85
+ ...> (_, original, override) when is_list(original) and is_list(override) ->
86
+ ...> override
87
+ ...> (_, _original, _override) ->
88
+ ...> DeepMerge.continue_deep_merge
89
+ ...> end
90
+ iex> DeepMerge.deep_merge(%{a: %{b: 1}, c: [d: 1]},
91
+ ...> %{a: %{z: 5}, c: [x: 0]}, resolver)
92
+ %{a: %{b: 1, z: 5}, c: [x: 0]}
93
+ """
94
+ @spec deep_merge(map() | keyword(), map() | keyword(), (any(), any() -> any())) ::
95
+ map() | keyword()
96
+ def deep_merge(original, override, resolve_function)
97
+ when (is_map(original) or is_list(original)) and (is_map(override) or is_list(override)) do
98
+ resolver = build_resolver(resolve_function)
99
+ resolver.(nil, original, override)
100
+ end
101
+
102
+ @doc """
103
+ The symbol to return in the function in `deep_merge/3` when deep merging
104
+ should continue as normal.
105
+
106
+ ## Examples
107
+
108
+ iex> DeepMerge.continue_deep_merge
109
+ :__deep_merge_continue
110
+ """
111
+ @spec continue_deep_merge() :: :__deep_merge_continue
112
+ def continue_deep_merge, do: @continue_symbol
113
+
114
+ @spec build_resolver((any(), any() -> any())) :: (any(), any(), any() -> any())
115
+ defp build_resolver(resolve_function) do
116
+ my_resolver = fn key, base, override, fun ->
117
+ resolved_value = resolve_function.(key, base, override)
118
+
119
+ case resolved_value do
120
+ @continue_symbol ->
121
+ continue_deep_merge(base, override, fun)
122
+
123
+ _anything ->
124
+ resolved_value
125
+ end
126
+ end
127
+
128
+ rebuild_resolver(my_resolver)
129
+ end
130
+
131
+ defp rebuild_resolver(resolve_function) do
132
+ fn key, base, override ->
133
+ resolve_function.(key, base, override, resolve_function)
134
+ end
135
+ end
136
+
137
+ defp continue_deep_merge(base, override, fun) do
138
+ resolver = rebuild_resolver(fun)
139
+ Resolver.resolve(base, override, resolver)
140
+ end
141
+
142
+ defp standard_resolve(_key, original, override) do
143
+ Resolver.resolve(original, override, &standard_resolve/3)
144
+ end
145
+ end
deps/deep_merge/lib/deep_merge/resolver.ex ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defprotocol DeepMerge.Resolver do
2
+ @moduledoc """
3
+ Protocol defining how conflicts during deep_merge should be resolved.
4
+
5
+ As part of the DeepMerge library this protocol is already implemented for
6
+ `Map` and `List` as well as a fallback to `Any` (which just always takes the
7
+ override).
8
+
9
+ If you want your custom structs to also be deeply mergable and not just
10
+ override one another (default behaviour) you can derive the protocol:
11
+
12
+ defmodule Derived do
13
+ @derive [DeepMerge.Resolver]
14
+ defstruct [:attrs]
15
+ end
16
+
17
+ It will then automatically be deeply merged with structs of its own kind, not
18
+ with other structs or maps though.
19
+ """
20
+ @fallback_to_any true
21
+
22
+ @doc """
23
+ Defines what happens when a merge conflict occurs on this struct during a
24
+ deep_merge.
25
+
26
+ Can be implemented for additional data types to implement custom deep merging
27
+ behavior.
28
+
29
+ The passed in values are:
30
+ * `original` - the value in the original data structure, usually left side
31
+ argument
32
+ * `override` - the value with which `original` would be overridden in a
33
+ normal `Map.merge/2`
34
+ * `resolver` - the function used by DeepMerge to resolve merge conflicts,
35
+ i.e. what you can pass to `Map.merge/3` and `Keyword.merge/3` to continue
36
+ deeply merging.
37
+
38
+ An example implementation might look like this if you want to deeply merge
39
+ your struct but only against non `nil` values (because all keys are always there)
40
+ if you merge against the same struct (but still merge with maps):
41
+
42
+ defimpl DeepMerge.Resolver, for: MyStruct do
43
+ def resolve(original, override = %MyStruct{}, resolver) do
44
+ cleaned_override =
45
+ override
46
+ |> Map.from_struct()
47
+ |> Enum.reject(fn {_key, value} -> is_nil(value) end)
48
+ |> Map.new()
49
+
50
+ Map.merge(original, cleaned_override, resolver)
51
+ end
52
+
53
+ def resolve(original, override, resolver) when is_map(override) do
54
+ Map.merge(original, override, resolver)
55
+ end
56
+ end
57
+ """
58
+ def resolve(original, override, resolver)
59
+ end
60
+
61
+ defimpl DeepMerge.Resolver, for: Map do
62
+ @doc """
63
+ Resolve the merge between two maps by continuing to deeply merge them.
64
+
65
+ Don't merge structs or if its any other type take the override value.
66
+ """
67
+ def resolve(_original, override = %{__struct__: _}, _fun) do
68
+ override
69
+ end
70
+
71
+ def resolve(original, override, resolver) when is_map(override) do
72
+ Map.merge(original, override, resolver)
73
+ end
74
+
75
+ def resolve(_original, override, _fun), do: override
76
+ end
77
+
78
+ defimpl DeepMerge.Resolver, for: List do
79
+ @doc """
80
+ Deeply merge keyword lists but avoid overriding a keywords with an empty list.
81
+ """
82
+ def resolve(original = [{_k, _v} | _], override = [{_, _} | _], resolver) do
83
+ Keyword.merge(original, override, resolver)
84
+ end
85
+
86
+ def resolve(original = [{_k, _v} | _tail], _override = [], _fun) do
87
+ original
88
+ end
89
+
90
+ def resolve(_original, override, _fun), do: override
91
+ end
92
+
93
+ defimpl DeepMerge.Resolver, for: Any do
94
+ @doc """
95
+ Fall back to always taking the override.
96
+
97
+ Also the implementation for `@derive [DeppMerge.Resolver]` where structs of the same type that
98
+ implement the protocol are deeply merged.
99
+ """
100
+ def resolve(original = %{__struct__: struct}, override = %{__struct__: struct}, resolver) do
101
+ implementors = get_implementors(DeepMerge.Resolver.__protocol__(:impls))
102
+
103
+ if Enum.member?(implementors, struct) do
104
+ Map.merge(original, override, resolver)
105
+ else
106
+ override
107
+ end
108
+ end
109
+
110
+ def resolve(_original, override, _fun), do: override
111
+
112
+ defp get_implementors({:consolidated, implementors}), do: implementors
113
+
114
+ defp get_implementors(:not_consolidated) do
115
+ IO.warn(
116
+ "Protocols not consolidated and trying to merge two structs of the same type. Not supported!"
117
+ )
118
+
119
+ # let the code work with override semantics without being intrusive
120
+ []
121
+ end
122
+ end
deps/deep_merge/mix.exs ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defmodule DeepMerge.Mixfile do
2
+ use Mix.Project
3
+
4
+ @version "1.0.0"
5
+
6
+ def project do
7
+ [
8
+ app: :deep_merge,
9
+ version: @version,
10
+ elixir: "~> 1.6",
11
+ build_embedded: Mix.env() == :prod,
12
+ start_permanent: Mix.env() == :prod,
13
+ elixirc_paths: elixirc_paths(Mix.env()),
14
+ deps: deps(),
15
+ docs: [source_ref: @version],
16
+ test_coverage: [tool: ExCoveralls],
17
+ preferred_cli_env: [
18
+ coveralls: :test,
19
+ "coveralls.detail": :test,
20
+ "coveralls.post": :test,
21
+ "coveralls.html": :test,
22
+ "coveralls.travis": :test
23
+ ],
24
+ package: package(),
25
+ name: "deep_merge",
26
+ source_url: "https://github.com/PragTob/deep_merge",
27
+ dialyzer: [
28
+ flags: [:unmatched_returns, :error_handling, :race_conditions, :underspecs],
29
+ ignore_warnings: ".dialyzer_ignore.exs",
30
+ list_unused_filters: true
31
+ ],
32
+ description: """
33
+ Deep (recursive) merging for maps, keyword lists and whatever else
34
+ you may want via implementing a simple protocol.
35
+ """
36
+ ]
37
+ end
38
+
39
+ # Specifies which paths to compile per environment.
40
+ defp elixirc_paths(:test), do: ["lib", "test/support"]
41
+ defp elixirc_paths(_), do: ["lib"]
42
+
43
+ # Configuration for the OTP application
44
+ #
45
+ # Type "mix help compile.app" for more information
46
+ def application do
47
+ []
48
+ end
49
+
50
+ defp deps do
51
+ [
52
+ {:credo, "~> 1.0", only: :dev},
53
+ {:ex_doc, "~> 0.11", only: :dev},
54
+ {:earmark, "~> 1.2", only: :dev},
55
+ {:excoveralls, "~> 0.7", only: :test},
56
+ {:inch_ex, "~> 0.5", only: :docs},
57
+ {:dialyxir, "~> 1.0.0-rc.4", only: [:dev], runtime: false}
58
+ ]
59
+ end
60
+
61
+ defp package do
62
+ [
63
+ maintainers: ["Tobias Pfeiffer"],
64
+ licenses: ["MIT"],
65
+ links: %{
66
+ "github" => "https://github.com/PragTob/deep_merge"
67
+ }
68
+ ]
69
+ end
70
+ end
deps/eini/.hex ADDED
Binary file (268 Bytes). View file
 
deps/eini/LICENSE 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.
deps/eini/README.md ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ eini-beam - An Erlang INI parser
2
+ ================================
3
+ This is just an INI parser. That's it. No state, no gen_servers, no ets tables,
4
+ just a parser that returns a map and does not convert strings into atoms.
5
+
6
+ You're probably looking for the original: https://github.com/erlcloud/eini
7
+
8
+ Example
9
+ -------
10
+
11
+ Input file:
12
+ ```
13
+ [title1]
14
+ key = value
15
+ key2 = value2
16
+ [title2]
17
+ key = value
18
+ ```
19
+
20
+ Result form:
21
+ ```
22
+ #{ <<"title1">> => #{ <<"key">> => <<"value">>,
23
+ <<"key2">> => <<"value2">> },
24
+ <<"title2">> => #{ <<"key">> => <<"value">> }
25
+ }
26
+ ```
27
+
28
+ History
29
+ -------
30
+ This is a fork to decruft the parser of things it doesn't need (supervision,
31
+ ETS, gen_server) and make it use maps and not convert to atoms. We renamed
32
+ the repo in 2021 so we could publish it to hex.
33
+
34
+ Copyright
35
+ ---------
36
+ Copyright 2011 by Accense Technology, Inc.
37
+ Copyright 2018 by Mark R. Allen
deps/eini/_build/default/plugins/hex_core/CHANGELOG.md ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CHANGELOG
2
+
3
+ ## v0.12.2 (2026-02-27)
4
+
5
+ * Exclude `src/safe_erl_term.erl` from package.
6
+
7
+ ## v0.12.1 (2026-02-27)
8
+
9
+ * Fix unsafe deserialization of Erlang terms in API responses (CVE-2026-21619).
10
+
11
+ ## v0.12.0 (2025-10-26)
12
+
13
+ * Add short URL API `hex_api_short_url:create/2`.
14
+ * Add OAuth API:
15
+ * `hex_api_oauth:device_authorization/3,4`
16
+ * `hex_api_oauth:poll_device_token/3`
17
+ * `hex_api_oauth:refresh_token/3`
18
+ * `hex_api_oauth:revoke_token/3`
19
+ * `hex_api_oauth:client_credentials_token/4,5`
20
+ * Support 2FA authentication, any API request can now return `{error, otp_required | invalid_totp}`
21
+ if 2FA is required. The config option `api_otp` can be used to provide the TOTP code.
22
+ * Differentiate between registry verification errors. `{error, unverified}` has been replaced with
23
+ `{error, bad_repo_name | bad_signature}`.
24
+ * Support nested maps in `extra` package metadata field.
25
+
26
+ ## v0.11.0 (2024-12-03)
27
+
28
+ * Use secure SSL defaults for OTP 25+.
29
+ * Start inets and ssl applications.
30
+
31
+ ## v0.10.3 (2024-06-28)
32
+
33
+ * Fix `hex_api_release:retirement_params/0` type spec.
34
+
35
+ ## v0.10.2 (2024-06-12)
36
+
37
+ * Fix `hex_tarball:create_docs/1` type spec.
38
+
39
+ ## v0.10.1 (2024-06-11)
40
+
41
+ * Drop support for OTP 20.
42
+ * Update `hex_licenses` module to reflect most recent list available from SPDX.
43
+
44
+ ## v0.10.0 (2023-05-09)
45
+
46
+ * Drop support for old OTP and Rebar versions. `hex_core` now requires OTP20+ and Rebar 3.15.1+.
47
+
48
+ * Add `hex_repo:get_docs/3` and `hex_repo:get_public_key/1`.
49
+
50
+ ## v0.9.0 (2022-11-03)
51
+
52
+ * Change `hex_registry` functions to match protobuf fields
53
+
54
+ Before:
55
+
56
+ > hex_registry:unpack_names(Payload, <<"test">>, TestPublicKey)
57
+ {ok,[#{name => <<"package1">>, ...},
58
+ #{name => <<"package2">>, ...}]}
59
+
60
+ After:
61
+
62
+ > hex_registry:unpack_names(Payload, <<"test">>, TestPublicKey)
63
+ {ok,#{packages => [#{name => <<"package1">>, ...},
64
+ #{name => <<"package2">>, ...}],
65
+ repository: <<"test">>}}
66
+
67
+ * Change `hex_repo` functions to match protobuf fields
68
+
69
+ Before:
70
+
71
+ > hex_repo:get_names(Config),
72
+ {ok,{200, ...,
73
+ [#{name => <<"pacakge2">>, ...},
74
+ #{name => <<"pacakge2">>, ...},
75
+ ...]}}
76
+
77
+ After:
78
+
79
+ > hex_repo:get_names(Config),
80
+ {ok,{200, ...,
81
+ #{packages => [#{name => <<"pacakge2">>, ...},
82
+ #{name => <<"pacakge2">>, ...},
83
+ ...],
84
+ repository => <<"test">>}}}
85
+
86
+ ## v0.8.4 (2021-12-20)
87
+
88
+ * Add `@doc` to `hex_licenses`
89
+
90
+ ## v0.8.3 (2021-12-14)
91
+
92
+ * Don't warn on non-https URLs
93
+ * Add `hex_licenses` module
94
+
95
+ ## v0.8.2 (2021-05-28)
96
+
97
+ * Warn on unsafe httpc default SSL settings
98
+
99
+ ## v0.8.1 (2021-05-20)
100
+
101
+ * Update gpb to 4.17.6 to avoid dialyzer warnings
102
+
103
+ ## v0.8.0 (2021-05-02)
104
+
105
+ * Deprecate registry encode/decode API in favour of new high-level build/unpack API
106
+ * Add `updated_at` to repository names resource
107
+
108
+ ## v0.7.1 (2020-10-12)
109
+
110
+ * Fix dialyzer warnings on OTP 23
111
+
112
+ ## v0.7.0 (2020-10-20)
113
+
114
+ * Fix compatibility with OTP 24
115
+ * Change `hex_tarball:create/2` error value from `{error, too_big}` to `{tarball, {too_big_compressed | too_big_uncompressed, Size}}`.
116
+
117
+ ## v0.6.10 (2020-08-25)
118
+
119
+ * Add configuration for max tarball size
120
+ * Do not create extraneous "memory" directory when unpacking
121
+
122
+ ## v0.6.9 (2020-05-24)
123
+
124
+ * Add `hex_api_release:publish/3`
125
+
126
+ ## v0.6.8 (2020-02-04)
127
+
128
+ * Fix tarball file extraction through symlinks
129
+
130
+ ## v0.6.7 (2020-02-03)
131
+
132
+ * Fix compatibility with OTP 18 and 17
133
+
134
+ ## v0.6.6 (2020-02-03)
135
+
136
+ * Do not crash on empty tarballs
137
+ * Fix directory traversal vulnerability for symlinks in tarballs
138
+
139
+ ## v0.6.5 (2020-01-14)
140
+
141
+ * Transition away from `http_uri` when using newer OTP releases
142
+ * Ensure `Role` is given as an atom in `hex_api_organization_member:add/3`
143
+ * Add `http_headers` to the `hex_core:config()` type
144
+ * Add default `http_headers` to `hex_core:default_config/0`
145
+ * Fix `hex_registry:decode_and_verify_signed/2` spec
146
+ * Fix `hex_tarball:files/0` type
147
+
148
+ ## v0.6.4 (2019-12-27)
149
+
150
+ * Fix setting level and transfer options in organization api
151
+
152
+ ## v0.6.3 (2019-12-16)
153
+
154
+ * Add organization API
155
+ * Add level and transfer params to add owner API
156
+ * Add `hex_tarball:unpack_docs/2`
157
+ * Add `hex_api_auth:test_key/3`
158
+
159
+ ## v0.6.2 (2019-11-11)
160
+
161
+ * Gracefully handle HTTP errors
162
+
163
+ ## v0.6.1 (2019-07-30)
164
+
165
+ * Fix bug when publishing with configuration that does not have `repo_organization` key set
166
+
167
+ ## v0.6.0 (2019-07-27)
168
+
169
+ * **Backwards-incompatible**: Change successful return value of `hex_tarball:create/2` from
170
+ `{ok, {Tarball, Checksum}}` to `{ok, Map}`. Currently, `Map` has `tarball`, `inner_tarball`,
171
+ and `outer_tarball` keys
172
+ * Rename existing tarball checksum to inner checksum and deprecate it
173
+ * Add tarball outer checksum
174
+ * Do not allow comments in `safe_erl_term`
175
+ * Forward compatible tarball contents by not failing on unknown files
176
+
177
+ ## v0.5.1 (2019-07-30)
178
+
179
+ * Fix bug when publishing with configuration that does not have `repo_organization` key set
180
+
181
+ ## v0.5.0 (2019-02-26)
182
+
183
+ * Fetch package data from proper repository organization and don't verify origin if configured
184
+ * **Backwards-incompatible**: Make `hex_api` module private
185
+ * **Backwards-incompatible**: `organization` config key has been replaced with `api_organization`
186
+ and `api_repository` keys
187
+ * Add `repo_organization` config key
188
+ * `vendor.sh`: Add missing `hex_pb_*.erl` files
189
+ * `vendor.sh`: Fix replacing `hex_core`
190
+
191
+ ## v0.4.0 (2018-12-30)
192
+
193
+ * Revert switch from proto2 to proto3
194
+ * Verify authenticity of signed payload
195
+ * Add `repo_verify_origin` config option
196
+
197
+ ## v0.3.0 (2018-12-14)
198
+
199
+ * Switch from proto2 to proto3
200
+ * Fix `hex_http:body` type
201
+ * Fix `hex_http:request` spec
202
+
203
+ ## v0.2.1 (2018-12-13)
204
+
205
+ * Always return the whole response tuple from requests
206
+ * Guess rebar3 as build tool over rebar
207
+ * Return compressed tarball from hex_tarball:create_docs/1
208
+ * Add package identity to registry records
209
+
210
+ ## v0.2.0 (2018-09-01)
211
+
212
+ * Accept `{filename(), filename()}` in files list for tarballs
213
+ * Support httpc profile through adapter configs
214
+ * Update generated protobuf files with OTP 21 compatibility
215
+
216
+ ## v0.1.1 (2018-08-11)
217
+
218
+ * Use `hex_core` project name in user agent string
219
+
220
+ ## v0.1.0 (2018-08-08)
221
+
222
+ * First release
deps/eini/_build/default/plugins/hex_core/LICENSE ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2018, Six Colors AB
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
191
+
deps/eini/_build/default/plugins/hex_core/README.md ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # hex_core
2
+
3
+ [![Build Status](https://github.com/hexpm/hex_core/actions/workflows/main.yml/badge.svg)](https://github.com/hexpm/hex_core/actions/workflows/main.yml)
4
+
5
+ Reference implementation of Hex specifications: <https://github.com/hexpm/specifications>.
6
+
7
+ ## Usage
8
+
9
+ Let's use default config for now. See "Configuration" section below for customization.
10
+
11
+ ```erlang
12
+ Config = hex_core:default_config().
13
+ ```
14
+
15
+ **WARNING** The built-in httpc-based HTTP client adapter has insecure default settings
16
+ and thus it is not recommended for usage, in particular for API write operations.
17
+ Use HTTP clients with secure defaults like [hackney](https://hex.pm/packages/hackney) and [Mint](https://hex.pm/packages/mint).
18
+ See "Configuration" and "Wrapper Module" sections for more information on customising your usage of `hex_core`.
19
+
20
+ ### Repository
21
+
22
+ Get all package names:
23
+
24
+ ```erlang
25
+ > hex_repo:get_names(Config).
26
+ {ok,{200, ...,
27
+ #{packages => [
28
+ #{name => <<"package1">>},
29
+ #{name => <<"package2">>},
30
+ ...]}}}
31
+ ```
32
+
33
+ Get all package versions from repository:
34
+
35
+ ```erlang
36
+ > hex_repo:get_versions(Config).
37
+ {ok,{200, ...,
38
+ #{packages => [[
39
+ #{name => <<"package1">>, retired => [], versions => [<<"1.0.0">>]},
40
+ #{name => <<"package2">>, retired => [], versions => [<<"0.5.0">>]},
41
+ ...]}}}
42
+ ```
43
+
44
+ Get package releases from repository:
45
+
46
+ ```erlang
47
+ > hex_repo:get_package(Config, <<"package1">>).
48
+ {ok,{200, ...,
49
+ #{releases => [
50
+ #{checksum => ..., version => <<"0.5.0">>, dependencies => []}],
51
+ #{checksum => ..., version => <<"1.0.0">>, dependencies => []}],
52
+ ...]}}}
53
+ ```
54
+
55
+ ### API
56
+
57
+ For a full list of all parameters and returned objects for the API, check out the API docs: <https://github.com/hexpm/specifications/blob/master/http_api.md>.
58
+
59
+ Get package from HTTP API:
60
+
61
+ ```erlang
62
+ > hex_api_package:get(Config, <<"package1">>).
63
+ {ok, {200, ...,
64
+ #{
65
+ <<"name">> => <<"package1">>,
66
+ <<"meta">> => #{
67
+ <<"description">> => ...,
68
+ <<"licenses">> => ...,
69
+ <<"links">> => ...,
70
+ <<"maintainers">> => ...,
71
+ },
72
+ ...,
73
+ <<"releases">> => [
74
+ #{<<"url">> => ..., <<"version">> => <<"0.5.0">>}],
75
+ #{<<"url">> => ..., <<"version">> => <<"1.0.0">>}],
76
+ ...
77
+ ]
78
+ }}}
79
+ ```
80
+
81
+ Get package tarball:
82
+
83
+ ```erlang
84
+ {ok, {200, _, Tarball}} = hex_repo:get_tarball(Config, <<"package1">>, <<"1.0.0">>).
85
+ ```
86
+
87
+ Publish package tarball:
88
+
89
+ ```erlang
90
+ {ok, {200, _Headers, _Body} = hex_api_package:publish(Config, Tarball).
91
+ ```
92
+
93
+ ### Two-Factor Authentication
94
+
95
+ When using OAuth tokens, two-factor authentication may be required. If required, the server will return `{error, otp_required}` and you should retry the request with the TOTP code via the `api_otp` configuration option. If the TOTP code is incorrect, the server will return `{error, invalid_totp}` and you should retry with the correct TOTP code.
96
+
97
+ ```erlang
98
+ %% First attempt without OTP
99
+ case hex_api_release:publish(Config, Tarball) of
100
+ {error, otp_required} ->
101
+ %% Retry with TOTP code
102
+ ConfigWithOTP = Config#{api_otp := <<"123456">>},
103
+ hex_api_release:publish(ConfigWithOTP, Tarball);
104
+ {error, invalid_totp} ->
105
+ %% Retry with correct TOTP code
106
+ ConfigWithOTP = Config#{api_otp := <<"123456">>},
107
+ hex_api_release:publish(ConfigWithOTP, Tarball);
108
+ Result ->
109
+ Result
110
+ end.
111
+ ```
112
+
113
+ API keys don't require TOTP validation.
114
+
115
+ ### Package tarballs
116
+
117
+ Unpack package tarball:
118
+
119
+ ```erlang
120
+ {ok, #{outer_checksum := Checksum, contents := Contents, metadata := Metadata}} = hex_tarball:unpack(Tarball, memory).
121
+ ```
122
+
123
+ Remember to verify the outer tarball checksum against the registry checksum
124
+ returned from `hex_repo:get_package(Config, Package)`.
125
+
126
+ Create package tarball:
127
+
128
+ ```erlang
129
+ {ok, #{tarball := Tarball,
130
+ inner_checksum := InnerChecksum,
131
+ outer_checksum := OuterChecksum}} = hex_tarball:create(Metadata, Contents).
132
+ ```
133
+
134
+ ## Configuration
135
+
136
+ The default configuration, provided by `hex_core:default_config/0`, uses built-in httpc-based adapter and Hex.pm APIs:
137
+ <https://hex.pm/api> and <https://repo.hex.pm>.
138
+
139
+ HTTP client configuration can be overridden as follows:
140
+
141
+ ```erlang
142
+ Config = maps:merge(hex_core:default_config(), #{
143
+ http_adapter => {my_hackney_adapter, my_hackney_adapter_config},
144
+ http_user_agent_fragment => <<"(my_app/0.1.0) (hackney/1.12.1) ">>
145
+ }),
146
+ hex_repo:get_names(Config).
147
+
148
+ %% my_hackney_adapter.erl
149
+ -module(my_hackney_adapter).
150
+ -behaviour(hex_http).
151
+ -exports([request/5]).
152
+
153
+ request(Method, URI, ReqHeaders, Body, AdapterConfig) ->
154
+ %% ...
155
+ ```
156
+
157
+ See the [`hex_core` module](src/hex_core.erl) for more information about the configuration.
158
+
159
+ ## Wrapper Module
160
+
161
+ It's recommended to write a wrapper module because a lot of decisions are left to the user, e.g.:
162
+ where to get configuration from, how to handle caching, failures etc.
163
+
164
+ For a sample, see: [`examples/myapp_hex.erl`](examples/myapp_hex.erl). Here's an excerpt:
165
+
166
+ ```erlang
167
+ -module(myapp_hex).
168
+ -export([
169
+ get_api_package/1,
170
+ get_repo_tarball/2,
171
+ get_repo_versions/0
172
+ ]).
173
+
174
+ %%====================================================================
175
+ %% API functions
176
+ %%====================================================================
177
+
178
+ get_api_package(Name) ->
179
+ case hex_api_package:get(config(), Name) of
180
+ {ok, {200, _Headers, Payload}} ->
181
+ {ok, Payload};
182
+
183
+ Other ->
184
+ Other
185
+ end.
186
+
187
+ get_repo_versions() ->
188
+ case hex_repo:get_versions(config()) of
189
+ {ok, {200, _Headers, Payload}} ->
190
+ {ok, maps:get(packages, Payload)};
191
+
192
+ Other ->
193
+ Other
194
+ end.
195
+
196
+ %%====================================================================
197
+ %% Internal functions
198
+ %%====================================================================
199
+
200
+ config() ->
201
+ Config1 = hex_core:default_config(),
202
+ Config2 = put_http_config(Config1),
203
+ Config3 = maybe_put_api_key(Config2),
204
+ Config3.
205
+
206
+ put_http_config(Config) ->
207
+ maps:put(http_user_agent_fragment, <<"(myapp/1.0.0) (httpc)">>, Config).
208
+
209
+ maybe_put_api_key(Config) ->
210
+ case os:getenv("HEX_API_KEY") of
211
+ false -> Config;
212
+ Key -> maps:put(api_key, Key, Config)
213
+ end.
214
+ ```
215
+
216
+ ## Installation
217
+
218
+ ### Rebar3
219
+
220
+ Add to `rebar.config`:
221
+
222
+ ```erlang
223
+ {deps, [
224
+ {hex_core, "0.12.2"}
225
+ ]}
226
+ ```
227
+
228
+ ### Mix
229
+
230
+ Add to `mix.exs`:
231
+
232
+ ```elixir
233
+ defp deps do
234
+ [
235
+ {:hex_core, "~> 0.12.2"}
236
+ ]
237
+ end
238
+ ```
239
+
240
+ ## Development
241
+
242
+ * Run `rebar3 as dev compile` to re-generate protobuf files
243
+ * Run `rebar3 as test proper` for property-based tests
244
+ * Run `rebar3 ex_doc` to generate documentation
deps/eini/_build/default/plugins/hex_core/ebin/hex_api.beam ADDED
Binary file (8.11 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_auth.beam ADDED
Binary file (1.97 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_key.beam ADDED
Binary file (3.17 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_oauth.beam ADDED
Binary file (4.26 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_organization.beam ADDED
Binary file (2.42 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_organization_member.beam ADDED
Binary file (3.3 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_package.beam ADDED
Binary file (2.6 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_package_owner.beam ADDED
Binary file (3.17 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_release.beam ADDED
Binary file (5.65 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_short_url.beam ADDED
Binary file (1.92 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_api_user.beam ADDED
Binary file (2.78 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_core.app ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {application,hex_core,
2
+ [{description,"Reference implementation of Hex specifications"},
3
+ {vsn,"0.12.2"},
4
+ {registered,[]},
5
+ {applications,[kernel,stdlib,inets,ssl]},
6
+ {licenses,["Apache-2.0"]},
7
+ {include_paths,["CHANGELOG.md"]},
8
+ {exclude_paths,["src/safe_erl_term.erl"]},
9
+ {links,[{"GitHub","https://github.com/hexpm/hex_core"},
10
+ {"Hex specifications",
11
+ "https://github.com/hexpm/specifications"}]},
12
+ {doc,"doc"},
13
+ {modules,[hex_api,hex_api_auth,hex_api_key,hex_api_oauth,
14
+ hex_api_organization,hex_api_organization_member,
15
+ hex_api_package,hex_api_package_owner,hex_api_release,
16
+ hex_api_short_url,hex_api_user,hex_core,hex_erl_tar,
17
+ hex_filename,hex_http,hex_http_httpc,hex_licenses,
18
+ hex_pb_names,hex_pb_package,hex_pb_signed,
19
+ hex_pb_versions,hex_registry,hex_repo,
20
+ hex_safe_binary_to_term,hex_tarball,safe_erl_term]}]}.
deps/eini/_build/default/plugins/hex_core/ebin/hex_core.beam ADDED
Binary file (4.22 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_erl_tar.beam ADDED
Binary file (94.9 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_filename.beam ADDED
Binary file (2.55 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_http.beam ADDED
Binary file (4.32 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_http_httpc.beam ADDED
Binary file (5.01 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_licenses.beam ADDED
Binary file (37.7 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_pb_names.beam ADDED
Binary file (46.8 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_pb_package.beam ADDED
Binary file (74.1 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_pb_signed.beam ADDED
Binary file (26.4 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_pb_versions.beam ADDED
Binary file (43.2 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_registry.beam ADDED
Binary file (14.4 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_repo.beam ADDED
Binary file (8.14 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_safe_binary_to_term.beam ADDED
Binary file (4.14 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/hex_tarball.beam ADDED
Binary file (28.6 kB). View file
 
deps/eini/_build/default/plugins/hex_core/ebin/safe_erl_term.beam ADDED
Binary file (35.9 kB). View file
 
deps/eini/_build/default/plugins/hex_core/hex_metadata.config ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {<<"app">>,<<"hex_core">>}.
2
+ {<<"build_tools">>,[<<"rebar3">>]}.
3
+ {<<"description">>,<<"Reference implementation of Hex specifications">>}.
4
+ {<<"files">>,
5
+ [<<"CHANGELOG.md">>,<<"LICENSE">>,<<"README.md">>,<<"rebar.config">>,
6
+ <<"rebar.config.script">>,<<"rebar.lock">>,<<"src">>,<<"src/hex_api.erl">>,
7
+ <<"src/hex_api_auth.erl">>,<<"src/hex_api_key.erl">>,
8
+ <<"src/hex_api_oauth.erl">>,<<"src/hex_api_organization.erl">>,
9
+ <<"src/hex_api_organization_member.erl">>,<<"src/hex_api_package.erl">>,
10
+ <<"src/hex_api_package_owner.erl">>,<<"src/hex_api_release.erl">>,
11
+ <<"src/hex_api_short_url.erl">>,<<"src/hex_api_user.erl">>,
12
+ <<"src/hex_core.app.src">>,<<"src/hex_core.erl">>,<<"src/hex_core.hrl">>,
13
+ <<"src/hex_erl_tar.erl">>,<<"src/hex_erl_tar.hrl">>,
14
+ <<"src/hex_filename.erl">>,<<"src/hex_http.erl">>,
15
+ <<"src/hex_http_httpc.erl">>,<<"src/hex_licenses.erl">>,
16
+ <<"src/hex_pb_names.erl">>,<<"src/hex_pb_package.erl">>,
17
+ <<"src/hex_pb_signed.erl">>,<<"src/hex_pb_versions.erl">>,
18
+ <<"src/hex_registry.erl">>,<<"src/hex_repo.erl">>,
19
+ <<"src/hex_safe_binary_to_term.erl">>,<<"src/hex_tarball.erl">>,
20
+ <<"src/safe_erl_term.xrl">>]}.
21
+ {<<"licenses">>,[<<"Apache-2.0">>]}.
22
+ {<<"links">>,
23
+ [{<<"GitHub">>,<<"https://github.com/hexpm/hex_core">>},
24
+ {<<"Hex specifications">>,<<"https://github.com/hexpm/specifications">>}]}.
25
+ {<<"name">>,<<"hex_core">>}.
26
+ {<<"requirements">>,[]}.
27
+ {<<"version">>,<<"0.12.2">>}.
deps/eini/_build/default/plugins/hex_core/rebar.config ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {erl_opts, [
2
+ debug_info
3
+ ]}.
4
+
5
+ {project_plugins, [rebar3_hex, rebar3_ex_doc, erlfmt]}.
6
+
7
+ {gpb_opts, [
8
+ {i, "proto"},
9
+ {o_erl, "src"},
10
+ {o_hrl, "src"},
11
+ {verify, always},
12
+ {strings_as_binaries, true},
13
+ {maps, true},
14
+ {maps_unset_optional, omitted},
15
+ {report_warnings, true},
16
+ {target_erlang_version, 17}
17
+ ]}.
18
+
19
+ {ex_doc, [
20
+ {source_url, <<"https://github.com/hexpm/hex_core">>},
21
+ {extras, [<<"README.md">>, <<"CHANGELOG.md">>]},
22
+ {main, <<"readme">>}
23
+ ]}.
24
+
25
+ {hex, [{doc, #{provider => ex_doc}}]}.
26
+
27
+ {erlfmt, [
28
+ write,
29
+ {files, ["{src,test,examples}/*.{hrl,erl,app.src}", "rebar.config"]},
30
+ {exclude_files, ["src/hex_pb_*.erl", "src/hex_erl_tar.{hrl,erl}"]}
31
+ ]}.
32
+
33
+ {profiles, [
34
+ {dev, [
35
+ {deps, [
36
+ {gpb, "4.21.1"}
37
+ ]},
38
+ {plugins, [
39
+ {rebar3_gpb_plugin, "2.23.1"}
40
+ ]},
41
+ {overrides, [
42
+ {del, rebar3_gpb_plugin, [
43
+ {deps, [gpb]}
44
+ ]}
45
+ ]},
46
+ {provider_hooks, [
47
+ {pre, [
48
+ {compile, {protobuf, compile}},
49
+ {clean, {protobuf, clean}}
50
+ ]}
51
+ ]}
52
+ ]},
53
+ {test, [
54
+ {erl_opts, [nowarn_export_all]},
55
+ {ct_opts, [
56
+ {create_priv_dir, auto_per_tc},
57
+ {config, "test/ct.config"}
58
+ ]},
59
+ {plugins, [
60
+ rebar3_proper
61
+ ]},
62
+ {deps, [
63
+ {proper, "1.3.0"}
64
+ ]},
65
+ {extra_src_dirs, ["test/support"]}
66
+ ]}
67
+ ]}.
deps/eini/_build/default/plugins/hex_core/rebar.config.script ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ case os:getenv("TARGET_ERLANG_VERSION") of
2
+ false -> CONFIG;
3
+ [] -> CONFIG;
4
+ TargetErlangVersionString ->
5
+ GpbOpts = proplists:get_value(gpb_opts, CONFIG),
6
+ TargetErlangVersion = {target_erlang_version, list_to_integer(TargetErlangVersionString)},
7
+ NewGpbOpts = lists:keystore(target_erlang_version, 1, GpbOpts, TargetErlangVersion),
8
+ lists:keystore(gpb_opts, 1, CONFIG, {gpb_opts, NewGpbOpts})
9
+ end.
deps/eini/_build/default/plugins/hex_core/rebar.lock ADDED
@@ -0,0 +1 @@
 
 
1
+ [].
deps/eini/_build/default/plugins/hex_core/src/hex_api.erl ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %% @doc
2
+ %% Hex HTTP API
3
+ -module(hex_api).
4
+
5
+ -export([
6
+ delete/2,
7
+ get/2,
8
+ post/3,
9
+ put/3,
10
+ encode_query_string/1,
11
+ build_repository_path/2,
12
+ build_organization_path/2,
13
+ join_path_segments/1
14
+ ]).
15
+ -define(ERL_CONTENT_TYPE, <<"application/vnd.hex+erlang">>).
16
+
17
+ -export_type([response/0]).
18
+
19
+ -type response() :: {ok, {hex_http:status(), hex_http:headers(), body() | nil}} | {error, term()}.
20
+ -type body() :: [body()] | #{binary() => body() | binary()}.
21
+
22
+ %% @private
23
+ get(Config, Path) ->
24
+ request(Config, get, Path, undefined).
25
+
26
+ %% @private
27
+ post(Config, Path, Body) ->
28
+ request(Config, post, Path, encode_body(Body)).
29
+
30
+ %% @private
31
+ put(Config, Path, Body) ->
32
+ request(Config, put, Path, encode_body(Body)).
33
+
34
+ %% @private
35
+ delete(Config, Path) ->
36
+ request(Config, delete, Path, undefined).
37
+
38
+ %% @private
39
+ encode_query_string(List) ->
40
+ Pairs = lists:map(fun({K, V}) -> {to_list(K), to_list(V)} end, List),
41
+ list_to_binary(compose_query(Pairs)).
42
+
43
+ %% OTP 21+
44
+ %% @private
45
+ -ifdef(OTP_RELEASE).
46
+ compose_query(Pairs) ->
47
+ uri_string:compose_query(Pairs).
48
+ -else.
49
+ compose_query(Pairs) ->
50
+ String = join("&", lists:map(fun({K, V}) -> K ++ "=" ++ V end, Pairs)),
51
+ http_uri:encode(String).
52
+ -endif.
53
+
54
+ %% @private
55
+ build_repository_path(#{api_repository := Repo}, Path) when is_binary(Repo) ->
56
+ ["repos", Repo | Path];
57
+ build_repository_path(#{api_repository := undefined}, Path) ->
58
+ Path.
59
+
60
+ %% @private
61
+ build_organization_path(#{api_organization := Org}, Path) when is_binary(Org) ->
62
+ ["orgs", Org | Path];
63
+ build_organization_path(#{api_organization := undefined}, Path) ->
64
+ Path.
65
+
66
+ %% @private
67
+ join_path_segments(Segments) ->
68
+ iolist_to_binary(recompose(Segments)).
69
+
70
+ %% OTP 21+
71
+ %% @private
72
+ -ifdef(OTP_RELEASE).
73
+ recompose(Segments) ->
74
+ Concatenated = join(<<"/">>, Segments),
75
+ %% uri_string:recompose/1 accepts path segments as a list,
76
+ %% both strings and binaries
77
+ uri_string:recompose(#{path => Concatenated}).
78
+ -else.
79
+ recompose(Segments) ->
80
+ join(<<"/">>, lists:map(fun encode_segment/1, Segments)).
81
+
82
+ %% @private
83
+ encode_segment(Binary) when is_binary(Binary) ->
84
+ encode_segment(binary_to_list(Binary));
85
+ encode_segment(String) when is_list(String) ->
86
+ http_uri:encode(String).
87
+ -endif.
88
+
89
+ %%====================================================================
90
+ %% Internal functions
91
+ %%====================================================================
92
+
93
+ request(Config, Method, PathSegments, Body) when is_list(PathSegments) ->
94
+ Path = join_path_segments(PathSegments),
95
+ request(Config, Method, Path, Body);
96
+ request(Config, Method, Path, Body) when is_binary(Path) and is_map(Config) ->
97
+ DefaultHeaders = make_headers(Config),
98
+ ReqHeaders = maps:merge(maps:get(http_headers, Config, #{}), DefaultHeaders),
99
+ ReqHeaders2 = put_new(<<"accept">>, ?ERL_CONTENT_TYPE, ReqHeaders),
100
+
101
+ case hex_http:request(Config, Method, build_url(Path, Config), ReqHeaders2, Body) of
102
+ {ok, {Status, RespHeaders, RespBody}} ->
103
+ ContentType = maps:get(<<"content-type">>, RespHeaders, <<"">>),
104
+ Response =
105
+ case binary:match(ContentType, ?ERL_CONTENT_TYPE) of
106
+ {_, _} ->
107
+ case hex_safe_binary_to_term:safe_binary_to_term(RespBody) of
108
+ {ok, Term} ->
109
+ {ok, {Status, RespHeaders, Term}};
110
+ {error, Reason} ->
111
+ {error, Reason}
112
+ end;
113
+ nomatch ->
114
+ {ok, {Status, RespHeaders, nil}}
115
+ end,
116
+ detect_otp_error(Response);
117
+ Other ->
118
+ Other
119
+ end.
120
+
121
+ %% TODO: not needed after exdoc is fixed
122
+ %% @private
123
+ build_url(Path, #{api_url := URI}) ->
124
+ <<URI/binary, "/", Path/binary>>.
125
+
126
+ %% TODO: not needed after exdoc is fixed
127
+ %% @private
128
+ encode_body({_ContentType, _Body} = Body) ->
129
+ Body;
130
+ encode_body(Body) ->
131
+ {binary_to_list(?ERL_CONTENT_TYPE), term_to_binary(Body)}.
132
+
133
+ %% TODO: not needed after exdoc is fixed
134
+ %% @private
135
+ %% TODO: copy-pasted from hex_repo
136
+ make_headers(Config) ->
137
+ maps:fold(fun set_header/3, #{}, Config).
138
+
139
+ %% TODO: not needed after exdoc is fixed
140
+ %% @private
141
+ set_header(api_key, Token, Headers) when is_binary(Token) ->
142
+ maps:put(<<"authorization">>, Token, Headers);
143
+ set_header(api_otp, OTP, Headers) when is_binary(OTP) ->
144
+ maps:put(<<"x-hex-otp">>, OTP, Headers);
145
+ set_header(_, _, Headers) ->
146
+ Headers.
147
+
148
+ %% TODO: not needed after exdoc is fixed
149
+ %% @private
150
+ put_new(Key, Value, Map) ->
151
+ case maps:find(Key, Map) of
152
+ {ok, _} -> Map;
153
+ error -> maps:put(Key, Value, Map)
154
+ end.
155
+
156
+ %% TODO: not needed after exdoc is fixed
157
+ %% @private
158
+ %% https://github.com/erlang/otp/blob/OTP-20.3/lib/stdlib/src/lists.erl#L1449:L1453
159
+ join(_Sep, []) -> [];
160
+ join(Sep, [H | T]) -> [H | join_prepend(Sep, T)].
161
+
162
+ %% TODO: not needed after exdoc is fixed
163
+ %% @private
164
+ join_prepend(_Sep, []) -> [];
165
+ join_prepend(Sep, [H | T]) -> [Sep, H | join_prepend(Sep, T)].
166
+
167
+ %% TODO: not needed after exdoc is fixed
168
+ %% @private
169
+ to_list(A) when is_atom(A) -> atom_to_list(A);
170
+ to_list(B) when is_binary(B) -> unicode:characters_to_list(B);
171
+ to_list(I) when is_integer(I) -> integer_to_list(I);
172
+ to_list(Str) -> unicode:characters_to_list(Str).
173
+
174
+ %% TODO: not needed after exdoc is fixed
175
+ %% @private
176
+ detect_otp_error({ok, {401, Headers, Body}}) ->
177
+ case maps:get(<<"www-authenticate">>, Headers, nil) of
178
+ <<"Bearer realm=\"hex\", error=\"totp_required\"", _/binary>> ->
179
+ {error, otp_required};
180
+ <<"Bearer realm=\"hex\", error=\"invalid_totp\"", _/binary>> ->
181
+ {error, invalid_totp};
182
+ _ ->
183
+ {ok, {401, Headers, Body}}
184
+ end;
185
+ detect_otp_error(Response) ->
186
+ Response.
deps/eini/_build/default/plugins/hex_core/src/hex_api_oauth.erl ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %% @doc
2
+ %% Hex HTTP API - OAuth.
3
+ -module(hex_api_oauth).
4
+ -export([
5
+ device_authorization/3,
6
+ device_authorization/4,
7
+ poll_device_token/3,
8
+ refresh_token/3,
9
+ revoke_token/3,
10
+ client_credentials_token/4,
11
+ client_credentials_token/5
12
+ ]).
13
+
14
+ %% @doc
15
+ %% Initiates the OAuth device authorization flow.
16
+ %%
17
+ %% @see device_authorization/4
18
+ %% @end
19
+ -spec device_authorization(hex_core:config(), binary(), binary()) -> hex_api:response().
20
+ device_authorization(Config, ClientId, Scope) ->
21
+ device_authorization(Config, ClientId, Scope, []).
22
+
23
+ %% @doc
24
+ %% Initiates the OAuth device authorization flow with optional parameters.
25
+ %%
26
+ %% Returns device code, user code, and verification URIs for user authentication.
27
+ %%
28
+ %% Options:
29
+ %% * `name' - A name to identify the token (e.g., hostname of the device)
30
+ %%
31
+ %% Examples:
32
+ %%
33
+ %% ```
34
+ %% 1> Config = hex_core:default_config().
35
+ %% 2> hex_api_oauth:device_authorization(Config, <<"cli">>, <<"api:write">>).
36
+ %% {ok,{200, ..., #{
37
+ %% <<"device_code">> => <<"...">>,
38
+ %% <<"user_code">> => <<"ABCD-1234">>,
39
+ %% <<"verification_uri">> => <<"https://hex.pm/oauth/device">>,
40
+ %% <<"verification_uri_complete">> => <<"https://hex.pm/oauth/device?user_code=ABCD-1234">>,
41
+ %% <<"expires_in">> => 600,
42
+ %% <<"interval">> => 5
43
+ %% }}}
44
+ %%
45
+ %% 3> hex_api_oauth:device_authorization(Config, <<"cli">>, <<"api:write">>, [{name, <<"MyMachine">>}]).
46
+ %% '''
47
+ %% @end
48
+ -spec device_authorization(hex_core:config(), binary(), binary(), proplists:proplist()) ->
49
+ hex_api:response().
50
+ device_authorization(Config, ClientId, Scope, Opts) ->
51
+ Path = <<"oauth/device_authorization">>,
52
+ Params0 = #{
53
+ <<"client_id">> => ClientId,
54
+ <<"scope">> => Scope
55
+ },
56
+ Params =
57
+ case proplists:get_value(name, Opts) of
58
+ undefined -> Params0;
59
+ Name -> Params0#{<<"name">> => Name}
60
+ end,
61
+ hex_api:post(Config, Path, Params).
62
+
63
+ %% @doc
64
+ %% Polls the OAuth token endpoint for device authorization completion.
65
+ %%
66
+ %% Returns:
67
+ %% - `{ok, {200, _, Token}}` - Authorization complete
68
+ %% - `{ok, {400, _, #{<<"error">> => <<"authorization_pending">>}}}` - Still waiting
69
+ %% - `{ok, {400, _, #{<<"error">> => <<"slow_down">>}}}` - Polling too fast
70
+ %% - `{ok, {400, _, #{<<"error">> => <<"expired_token">>}}}` - Code expired
71
+ %% - `{ok, {403, _, #{<<"error">> => <<"access_denied">>}}}` - User denied
72
+ %%
73
+ %% Examples:
74
+ %%
75
+ %% ```
76
+ %% 1> Config = hex_core:default_config().
77
+ %% 2> hex_api_oauth:poll_device_token(Config, <<"cli">>, DeviceCode).
78
+ %% {ok, {200, _, #{
79
+ %% <<"access_token">> => <<"...">>,
80
+ %% <<"refresh_token">> => <<"...">>,
81
+ %% <<"token_type">> => <<"Bearer">>,
82
+ %% <<"expires_in">> => 3600
83
+ %% }}}
84
+ %% '''
85
+ %% @end
86
+ -spec poll_device_token(hex_core:config(), binary(), binary()) -> hex_api:response().
87
+ poll_device_token(Config, ClientId, DeviceCode) ->
88
+ Path = <<"oauth/token">>,
89
+ Params = #{
90
+ <<"grant_type">> => <<"urn:ietf:params:oauth:grant-type:device_code">>,
91
+ <<"device_code">> => DeviceCode,
92
+ <<"client_id">> => ClientId
93
+ },
94
+ hex_api:post(Config, Path, Params).
95
+
96
+ %% @doc
97
+ %% Refreshes an access token using a refresh token.
98
+ %%
99
+ %% Examples:
100
+ %%
101
+ %% ```
102
+ %% 1> Config = hex_core:default_config().
103
+ %% 2> hex_api_oauth:refresh_token(Config, <<"cli">>, RefreshToken).
104
+ %% {ok, {200, _, #{
105
+ %% <<"access_token">> => <<"...">>,
106
+ %% <<"refresh_token">> => <<"...">>,
107
+ %% <<"token_type">> => <<"Bearer">>,
108
+ %% <<"expires_in">> => 3600
109
+ %% }}}
110
+ %% '''
111
+ %% @end
112
+ -spec refresh_token(hex_core:config(), binary(), binary()) -> hex_api:response().
113
+ refresh_token(Config, ClientId, RefreshToken) ->
114
+ Path = <<"oauth/token">>,
115
+ Params = #{
116
+ <<"grant_type">> => <<"refresh_token">>,
117
+ <<"refresh_token">> => RefreshToken,
118
+ <<"client_id">> => ClientId
119
+ },
120
+ hex_api:post(Config, Path, Params).
121
+
122
+ %% @doc
123
+ %% Exchanges an API key for an OAuth access token using the client credentials grant.
124
+ %%
125
+ %% @see client_credentials_token/5
126
+ %% @end
127
+ -spec client_credentials_token(hex_core:config(), binary(), binary(), binary()) ->
128
+ hex_api:response().
129
+ client_credentials_token(Config, ClientId, ApiKey, Scope) ->
130
+ client_credentials_token(Config, ClientId, ApiKey, Scope, []).
131
+
132
+ %% @doc
133
+ %% Exchanges an API key for an OAuth access token using the client credentials grant with optional parameters.
134
+ %%
135
+ %% This grant type allows exchanging a long-lived API key for a short-lived OAuth access token.
136
+ %% The API key is sent as the client_secret parameter.
137
+ %%
138
+ %% Options:
139
+ %% * `name' - A name to identify the token (e.g., hostname of the client)
140
+ %%
141
+ %% Returns:
142
+ %% - `{ok, {200, _, Token}}` - Token exchange successful
143
+ %% - `{ok, {400, _, #{<<"error">> => ...}}}` - Invalid request or scope
144
+ %% - `{ok, {401, _, #{<<"error">> => ...}}}` - Invalid API key
145
+ %%
146
+ %% Examples:
147
+ %%
148
+ %% ```
149
+ %% 1> Config = hex_core:default_config().
150
+ %% 2> hex_api_oauth:client_credentials_token(Config, <<"cli">>, ApiKey, <<"api">>).
151
+ %% {ok, {200, _, #{
152
+ %% <<"access_token">> => <<"...">>,
153
+ %% <<"token_type">> => <<"bearer">>,
154
+ %% <<"expires_in">> => 1800,
155
+ %% <<"scope">> => <<"api">>
156
+ %% }}}
157
+ %%
158
+ %% 3> hex_api_oauth:client_credentials_token(Config, <<"cli">>, ApiKey, <<"api">>, [{name, <<"MyMachine">>}]).
159
+ %% '''
160
+ %% @end
161
+ -spec client_credentials_token(
162
+ hex_core:config(), binary(), binary(), binary(), proplists:proplist()
163
+ ) -> hex_api:response().
164
+ client_credentials_token(Config, ClientId, ApiKey, Scope, Opts) ->
165
+ Path = <<"oauth/token">>,
166
+ Params0 = #{
167
+ <<"grant_type">> => <<"client_credentials">>,
168
+ <<"client_id">> => ClientId,
169
+ <<"client_secret">> => ApiKey,
170
+ <<"scope">> => Scope
171
+ },
172
+ Params =
173
+ case proplists:get_value(name, Opts) of
174
+ undefined -> Params0;
175
+ Name -> Params0#{<<"name">> => Name}
176
+ end,
177
+ hex_api:post(Config, Path, Params).
178
+
179
+ %% @doc
180
+ %% Revokes an OAuth token (RFC 7009).
181
+ %%
182
+ %% Can revoke either access tokens or refresh tokens.
183
+ %% Returns 200 OK regardless of whether the token was found,
184
+ %% following RFC 7009 security recommendations.
185
+ %%
186
+ %% Examples:
187
+ %%
188
+ %% ```
189
+ %% 1> Config = hex_core:default_config().
190
+ %% 2> hex_api_oauth:revoke_token(Config, <<"cli">>, Token).
191
+ %% {ok, {200, ..., nil}}
192
+ %% '''
193
+ %% @end
194
+ -spec revoke_token(hex_core:config(), binary(), binary()) -> hex_api:response().
195
+ revoke_token(Config, ClientId, Token) ->
196
+ Path = <<"oauth/revoke">>,
197
+ Params = #{
198
+ <<"token">> => Token,
199
+ <<"client_id">> => ClientId
200
+ },
201
+ hex_api:post(Config, Path, Params).
deps/eini/_build/default/plugins/hex_core/src/hex_api_package_owner.erl ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ %% @doc
2
+ %% Hex HTTP API - Package Owners.
3
+ -module(hex_api_package_owner).
4
+ -export([
5
+ add/5,
6
+ delete/3,
7
+ get/3,
8
+ list/2
9
+ ]).
10
+
11
+ %% @doc
12
+ %% Lists the packages owners.
13
+ %%
14
+ %% Examples:
15
+ %%
16
+ %% ```
17
+ %% > hex_api_package_owner:list(hex_core:default_config(), <<"package">>).
18
+ %% {ok, {200, ..., [#{
19
+ %% <<"email">> => <<"user@example.com">>,
20
+ %% <<"full_name">> => <<"John Doe">>,
21
+ %% <<"handles">> => #{...},
22
+ %% <<"inserted_at">> => <<"2014-04-21T17:20:12Z">>,
23
+ %% <<"level">> => <<"full">>,
24
+ %% <<"updated_at">> => <<"2019-08-04T19:28:05Z">>,
25
+ %% <<"url">> => <<"https://hex.pm/api/users/user">>,
26
+ %% <<"username">> => <<"user">>
27
+ %% }]}}
28
+ %% '''
29
+ %% @end
30
+ -spec list(hex_core:config(), binary()) -> hex_api:response().
31
+ list(Config, PackageName) when is_binary(PackageName) ->
32
+ Path = hex_api:build_repository_path(Config, ["packages", PackageName, "owners"]),
33
+ hex_api:get(Config, Path).
34
+
35
+ %% @doc
36
+ %% Gets a packages owner.
37
+ %%
38
+ %% Examples:
39
+ %%
40
+ %% ```
41
+ %% > hex_api_package_owner:get(hex_core:default_config(), <<"package">>, <<"user">>).
42
+ %% {ok, {200, ..., #{
43
+ %% <<"email">> => <<"user@example.com">>,
44
+ %% <<"full_name">> => <<"John Doe">>,
45
+ %% <<"handles">> => #{...},
46
+ %% <<"inserted_at">> => <<"2014-04-21T17:20:12Z">>,
47
+ %% <<"level">> => <<"full">>,
48
+ %% <<"updated_at">> => <<"2019-08-04T19:28:05Z">>,
49
+ %% <<"url">> => <<"https://hex.pm/api/users/user">>,
50
+ %% <<"username">> => <<"user">>
51
+ %% }}}
52
+ %% '''
53
+ %% @end
54
+ -spec get(hex_core:config(), binary(), binary()) -> hex_api:response().
55
+ get(Config, PackageName, UsernameOrEmail) when
56
+ is_map(Config) and is_binary(PackageName) and is_binary(UsernameOrEmail)
57
+ ->
58
+ Path = hex_api:build_repository_path(Config, [
59
+ "packages", PackageName, "owners", UsernameOrEmail
60
+ ]),
61
+ hex_api:get(Config, Path).
62
+
63
+ %% @doc
64
+ %% Adds a packages owner.
65
+ %%
66
+ %% Examples:
67
+ %%
68
+ %% ```
69
+ %% > hex_api_package_owner:add(hex_core:default_config(), <<"package">>, <<"user">>, <<"full">>, false).
70
+ %% {ok, {200, ..., #{
71
+ %% <<"email">> => <<"user@example.com">>,
72
+ %% <<"full_name">> => <<"John Doe">>,
73
+ %% <<"handles">> => #{...},
74
+ %% <<"inserted_at">> => <<"2014-04-21T17:20:12Z">>,
75
+ %% <<"level">> => <<"full">>,
76
+ %% <<"updated_at">> => <<"2019-08-04T19:28:05Z">>,
77
+ %% <<"url">> => <<"https://hex.pm/api/users/user">>,
78
+ %% <<"username">> => <<"user">>
79
+ %% }}}
80
+ %% '''
81
+ %% @end
82
+ -spec add(hex_core:config(), binary(), binary(), binary(), boolean()) -> hex_api:response().
83
+ add(Config, PackageName, UsernameOrEmail, Level, Transfer) when
84
+ is_binary(PackageName) and is_binary(UsernameOrEmail) and is_map(Config) and is_binary(Level) and
85
+ is_boolean(Transfer)
86
+ ->
87
+ Path = hex_api:build_repository_path(Config, [
88
+ "packages", PackageName, "owners", UsernameOrEmail
89
+ ]),
90
+ hex_api:put(Config, Path, #{<<"level">> => Level, <<"transfer">> => Transfer}).
91
+
92
+ %% @doc
93
+ %% Deletes a packages owner.
94
+ %%
95
+ %% Examples:
96
+ %%
97
+ %% ```
98
+ %% > hex_api_package_owner:delete(hex_core:default_config(), <<"package">>, <<"user">>).
99
+ %% {ok, {204, ..., nil}}
100
+ %% '''
101
+ %% @end
102
+ -spec delete(hex_core:config(), binary(), binary()) -> hex_api:response().
103
+ delete(Config, PackageName, UsernameOrEmail) when
104
+ is_map(Config) and is_binary(PackageName) and is_binary(UsernameOrEmail)
105
+ ->
106
+ Path = hex_api:build_repository_path(Config, [
107
+ "packages", PackageName, "owners", UsernameOrEmail
108
+ ]),
109
+ hex_api:delete(Config, Path).