From 3d411791a5570bf14e38ff6477c1790c1c4232fb Mon Sep 17 00:00:00 2001 From: Lucas Lois Date: Wed, 13 May 2026 21:14:25 +0200 Subject: [PATCH] feat(users): add create convenience wrapper with kwargs interface Mirrors the kwargs-style create wrappers in wallets, policies, and key_quorums. Includes an integration test against staging that exercises a custom-auth linked account plus a pregenerated Ethereum wallet, modeled on the Go SDK's TestUsers/New/WithCustomAuthAndWallet. Committed-By-Agent: claude --- lib/privy/public_api/services/users.rb | 26 ++++++++++++++++ test/privy/integration/services/users_test.rb | 30 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/privy/integration/services/users_test.rb diff --git a/lib/privy/public_api/services/users.rb b/lib/privy/public_api/services/users.rb index 134a93a..cd7b442 100644 --- a/lib/privy/public_api/services/users.rb +++ b/lib/privy/public_api/services/users.rb @@ -9,6 +9,32 @@ def initialize(client:, privy_client:) super(client: client) @privy_client = privy_client end + + # Create a new user with linked accounts. Optionally pre-generate embedded wallets + # for the user. + # + # @example Create a user from an email address + # client.users.create(user_create_params: { + # linked_accounts: [{address: "tom.bombadill@privy.io", type: :email}] + # }) + # + # @example Create a user with custom metadata and a pregenerated Ethereum wallet + # client.users.create(user_create_params: { + # linked_accounts: [{address: "tom.bombadill@privy.io", type: :email}], + # custom_metadata: {plan: "pro"}, + # wallets: [{chain_type: :ethereum}] + # }) + # + # @param user_create_params [Hash] Body parameters for user creation. + # @option user_create_params [Array] :linked_accounts Linked accounts to associate with the user (required). + # @option user_create_params [Hash{Symbol=>String, Float, Boolean}, nil] :custom_metadata Custom metadata associated with the user. + # @option user_create_params [Array, nil] :wallets Wallets to pregenerate for the user. + # @param request_options [Privy::RequestOptions, Hash, nil] Transport-level config (timeouts, retries). + # + # @return [Privy::Models::User] + def create(user_create_params:, request_options: nil) + super(user_create_params.merge(request_options: request_options)) + end end end end diff --git a/test/privy/integration/services/users_test.rb b/test/privy/integration/services/users_test.rb new file mode 100644 index 0000000..51f68f1 --- /dev/null +++ b/test/privy/integration/services/users_test.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require_relative "../integration_test_helper" + +class Privy::Test::Integration::UsersTest < Privy::Test::IntegrationTest + def test_create_user_with_custom_auth_and_pregenerated_ethereum_wallet + custom_user_id = "test-user-#{Time.now.to_f.to_s.tr('.', '-')}" + + user = client.users.create( + user_create_params: { + linked_accounts: [{custom_user_id: custom_user_id, type: :custom_auth}], + wallets: [{chain_type: :ethereum}] + } + ) + + refute_nil(user.id, "expected user.id to be set") + + custom_auth = user.linked_accounts.find { |a| a.type == :custom_auth } + refute_nil(custom_auth, "expected to find custom_auth linked account") + assert_equal(custom_user_id, custom_auth.custom_user_id) + + wallet = user.linked_accounts.find { |a| a.type == :wallet } + refute_nil(wallet, "expected to find wallet linked account") + assert_equal(:ethereum, wallet.chain_type) + refute_nil(wallet.address, "expected wallet.address to be set") + assert_match(/^0x[a-fA-F0-9]{40}$/, wallet.address) + ensure + client.users.delete(user.id) if user&.id + end +end