Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func StartInternal(config APIConfig) {
func baseMiddleware(logger *zerolog.Logger, e *echo.Echo) {
e.Use(middleware.Tracer())
e.Use(middleware.CORS())
e.Use(middleware.RequestID())
e.Use(middleware.RequestId())
e.Use(middleware.Recover())
e.Use(middleware.Logger(logger))
e.Use(middleware.LogRequest())
Expand Down
4 changes: 2 additions & 2 deletions api/handler/auth_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ func (o authAPIKey) Approve(c echo.Context) error {
return NotAllowedError(c)
}
params := struct {
ID string `param:"id"`
Id string `param:"id"`
}{}
err := c.Bind(&params)

if err != nil {
LogStringError(c, err, "authKey approve: bind")
return echo.NewHTTPError(http.StatusInternalServerError, "Unable to process request")
}
err = o.service.Approve(params.ID)
err = o.service.Approve(params.Id)
if err != nil {
LogStringError(c, err, "authKey approve: approve")
return echo.NewHTTPError(http.StatusInternalServerError, "Unable to process request")
Expand Down
6 changes: 3 additions & 3 deletions api/handler/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestStatus200LoginNoncePayload(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "/?"+q.Encode(), nil)
request.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)

handler := NewLogin(nil, stubs.Auth{})
handler := NewLogin(nil, stubs.Auth{}, stubs.Device{})
handler.RegisterRoutes(e.Group("/login"))
rec := httptest.NewRecorder()
c := e.NewContext(request, rec)
Expand All @@ -53,7 +53,7 @@ func TestStatus200LoginVerifySignature(t *testing.T) {
request := httptest.NewRequest(http.MethodPost, "/sign", strings.NewReader(string(jsonBody)))
request.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)

handler := NewLogin(nil, stubs.Auth{})
handler := NewLogin(nil, stubs.Auth{}, stubs.Device{})
handler.RegisterRoutes(e.Group("/login"))
rec := httptest.NewRecorder()
c := e.NewContext(request, rec)
Expand All @@ -68,7 +68,7 @@ func TestStatus400MissingWalletLoginNoncePayload(t *testing.T) {
request := httptest.NewRequest(http.MethodGet, "/", nil)
request.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)

handler := NewLogin(nil, stubs.Auth{})
handler := NewLogin(nil, stubs.Auth{}, stubs.Device{})
handler.RegisterRoutes(e.Group("/login"))
rec := httptest.NewRecorder()
c := e.NewContext(request, rec)
Expand Down
16 changes: 8 additions & 8 deletions api/handler/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (u user) Create(c echo.Context) error {
}

func (u user) Status(c echo.Context) error {
valid, userId := validUserID(IDParam(c), c)
valid, userId := validUserId(IdParam(c), c)
if !valid {
return Unauthorized(c)
}
Expand All @@ -92,7 +92,7 @@ func (u user) Update(c echo.Context) error {
LogStringError(c, err, "user: update bind")
return BadRequestError(c)
}
_, userId := validUserID(IDParam(c), c)
_, userId := validUserId(IdParam(c), c)
user, err := u.userService.Update(userId, body)
if err != nil {
LogStringError(c, err, "user: update")
Expand All @@ -105,7 +105,7 @@ func (u user) Update(c echo.Context) error {
// VerifyEmail send an email with a link, the user must click on the link for the email to be verified
// the link sent is handled by (verification.VerifyEmail) handler
func (u user) VerifyEmail(c echo.Context) error {
_, userId := validUserID(IDParam(c), c)
_, userId := validUserId(IdParam(c), c)
email := c.QueryParam("email")
if email == "" {
return BadRequestError(c, "Missing or invalid email")
Expand Down Expand Up @@ -145,12 +145,12 @@ func (u user) RegisterRoutes(g *echo.Group, ms ...echo.MiddlewareFunc) {
}

// get userId from context and also compare if both are valid
// this is useful for path params validation and userID from JWT
func validUserID(userID string, c echo.Context) (bool, string) {
userId := c.Get("userId").(string)
return userId == userID, userId
// this is useful for path params validation and userId from JWT
func validUserId(userId string, c echo.Context) (bool, string) {
_userId := c.Get("userId").(string)
return _userId == userId, _userId
}

func IDParam(c echo.Context) string {
func IdParam(c echo.Context) string {
return c.Param("id")
}
2 changes: 1 addition & 1 deletion api/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func LogRequest() echo.MiddlewareFunc {
}

// RequestID generates a unique request ID
func RequestID() echo.MiddlewareFunc {
func RequestId() echo.MiddlewareFunc {
return echoMiddleware.RequestID()
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/internal/common/cost.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package common

func NativeTokenBuffer(chainID uint64) float64 {
func NativeTokenBuffer(chainId uint64) float64 {
return 0.05
}

func GasBuffer(chainID uint64) float64 {
func GasBuffer(chainId uint64) float64 {
return 0.05
}

Expand Down
24 changes: 12 additions & 12 deletions pkg/internal/common/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type FPVisitIpLocation struct {
}

type FPVisitorVisit struct {
RequestID string `json:"requestId"`
RequestId string `json:"requestId"`
Incognito bool `json:"incognito"`
LinkedId string `json:"linkedId"`
Time string `json:"time"`
Expand All @@ -66,7 +66,7 @@ type FPVisitorVisit struct {
}

type FPVisitor struct {
ID string `json:"visitorId"`
Id string `json:"visitorId"`
Visits []FPVisitorVisit `json:"visits"`
}

Expand All @@ -80,19 +80,19 @@ type HTTPConfig struct {

type FPVisitorOpts struct {
Limit int
RequestID string
LinkedID string
RequestId string
LinkedId string
}

func NewHTTPClient(config HTTPConfig) HTTPClient {
return &http.Client{Timeout: config.Timeout}
}

type FingerprintClient interface {
// GetVisitorByID get the fingerprint visitor by its id
// GetVisitorById get the fingerprint visitor by its id
// it returns the most up to date information for the visitor
// The limit should always be 1 so we can get the latest information
GetVisitorByID(VisitorID string, opts FPVisitorOpts) (FPVisitor, error)
GetVisitorById(VisitorId string, opts FPVisitorOpts) (FPVisitor, error)
Request(method, url string, body io.Reader) (*http.Request, error)
}

Expand All @@ -108,9 +108,9 @@ func NewFingerprint(client HTTPClient) FingerprintClient {
return &fingerprint{client: client, apiKey: apiKey, baseURL: baseURL}
}

func (f fingerprint) GetVisitorByID(visitorID string, opts FPVisitorOpts) (FPVisitor, error) {
func (f fingerprint) GetVisitorById(visitorId string, opts FPVisitorOpts) (FPVisitor, error) {
m := FPVisitor{}
r, err := f.Request(http.MethodGet, f.baseURL+"visitors/"+visitorID, nil)
r, err := f.Request(http.MethodGet, f.baseURL+"visitors/"+visitorId, nil)
if err != nil {
return m, err
}
Expand Down Expand Up @@ -152,11 +152,11 @@ func (f fingerprint) optionsToQuery(opts FPVisitorOpts) url.Values {
if opts.Limit != 0 {
q.Add("limit", strconv.Itoa(opts.Limit))
}
if opts.RequestID != "" {
q.Add("request_id", opts.RequestID)
if opts.RequestId != "" {
q.Add("request_id", opts.RequestId)
}
if opts.LinkedID != "" {
q.Add("linked_id", opts.LinkedID)
if opts.LinkedId != "" {
q.Add("linked_id", opts.LinkedId)
}
return q
}
4 changes: 2 additions & 2 deletions pkg/internal/unit21/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func (a action) Create(
actionData := actionData{
ActionType: instrument.Type,
ActionDetails: actionDetails,
EntityId: instrument.UserID,
EntityId: instrument.UserId,
EntityType: "user",
InstrumentId: instrument.ID,
InstrumentId: instrument.Id,
}

url := "https://" + os.Getenv("UNIT21_ENV") + ".unit21.com/v1/events/create"
Expand Down
18 changes: 9 additions & 9 deletions pkg/internal/unit21/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ func (e entity) Create(user model.User) (unit21Id string, err error) {

// ultimately may want a join here.

communications, err := e.getCommunications(user.ID)
communications, err := e.getCommunications(user.Id)
if err != nil {
log.Err(err).Msg("Failed to gather Unit21 entity communications")
return "", common.StringError(err)
}

digitalData, err := e.getEntityDigitalData(user.ID)
digitalData, err := e.getEntityDigitalData(user.Id)
if err != nil {
log.Err(err).Msg("Failed to gather Unit21 entity digitalData")
return "", common.StringError(err)
}

customData, err := e.getCustomData(user.ID)
customData, err := e.getCustomData(user.Id)
if err != nil {
log.Err(err).Msg("Failed to gather Unit21 entity customData")
return "", common.StringError(err)
Expand Down Expand Up @@ -77,29 +77,29 @@ func (e entity) Update(user model.User) (unit21Id string, err error) {

// ultimately may want a join here.

communications, err := e.getCommunications(user.ID)
communications, err := e.getCommunications(user.Id)
if err != nil {
log.Err(err).Msg("Failed to gather Unit21 entity communications")
err = common.StringError(err)
return
}

digitalData, err := e.getEntityDigitalData(user.ID)
digitalData, err := e.getEntityDigitalData(user.Id)
if err != nil {
log.Err(err).Msg("Failed to gather Unit21 entity digitalData")
err = common.StringError(err)
return
}

customData, err := e.getCustomData(user.ID)
customData, err := e.getCustomData(user.Id)
if err != nil {
log.Err(err).Msg("Failed to gather Unit21 entity customData")
err = common.StringError(err)
return
}

orgName := os.Getenv("UNIT21_ORG_NAME")
url := "https://" + os.Getenv("UNIT21_ENV") + ".unit21.com/v1/" + orgName + "/entities/" + user.ID + "/update"
url := "https://" + os.Getenv("UNIT21_ENV") + ".unit21.com/v1/" + orgName + "/entities/" + user.Id + "/update"
body, err := u21Put(url, mapUserToEntity(user, communications, digitalData, customData))

if err != nil {
Expand Down Expand Up @@ -182,7 +182,7 @@ func (e entity) getCustomData(userId string) (customData entityCustomData, err e
}

for _, platform := range devices {
customData.Platforms = append(customData.Platforms, platform.PlatformID)
customData.Platforms = append(customData.Platforms, platform.PlatformId)
}
return
}
Expand All @@ -197,7 +197,7 @@ func mapUserToEntity(user model.User, communication entityCommunication, digital

jsonBody := &u21Entity{
GeneralData: &entityGeneral{
EntityId: user.ID,
EntityId: user.Id,
EntityType: "user",
Status: user.Status,
RegisteredAt: int(user.CreatedAt.Unix()),
Expand Down
16 changes: 9 additions & 7 deletions pkg/internal/unit21/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestUpdateEntity(t *testing.T) {
assert.Greater(t, len([]rune(u21EntityId)), 0)

user := model.User{
ID: entityId,
Id: entityId,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
DeactivatedAt: nil,
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestAddInstruments(t *testing.T) {
func createMockUser(mock sqlmock.Sqlmock, sqlxDB *sqlx.DB) (entityId string, unit21Id string, err error) {
entityId = uuid.NewString()
user := model.User{
ID: entityId,
Id: entityId,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
DeactivatedAt: nil,
Expand Down Expand Up @@ -161,7 +161,7 @@ func createMockInstrumentForUser(userId string, mock sqlmock.Sqlmock, sqlxDB *sq
locationId := uuid.NewString()

instrument = model.Instrument{
ID: instrumentId,
Id: instrumentId,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
DeactivatedAt: nil,
Expand All @@ -171,8 +171,8 @@ func createMockInstrumentForUser(userId string, mock sqlmock.Sqlmock, sqlxDB *sq
Network: "Visa",
PublicKey: "",
Last4: "1234",
UserID: userId,
LocationID: sql.NullString{String: locationId},
UserId: userId,
LocationId: sql.NullString{String: locationId},
}

mockedUserRow1 := sqlmock.NewRows([]string{"id", "type", "status", "tags", "first_name", "middle_name", "last_name"}).
Expand All @@ -191,13 +191,15 @@ func createMockInstrumentForUser(userId string, mock sqlmock.Sqlmock, sqlxDB *sq
AddRow(locationId, "Home", "Verified", "20181", "411", "Lark Avenue", "Somerville", "MA", "01443", "USA")
mock.ExpectQuery("SELECT * FROM location WHERE id = $1 AND deactivated_at IS NULL").WithArgs(locationId).WillReturnRows(mockedLocationRow)

repo := InstrumentRepo{
repos := InstrumentRepos{
User: repository.NewUser(sqlxDB),
Device: repository.NewDevice(sqlxDB),
Location: repository.NewLocation(sqlxDB),
}

u21Instrument := NewInstrument(repo)
action := NewAction()

u21Instrument := NewInstrument(repos, action)

u21InstrumentId, err := u21Instrument.Create(instrument)

Expand Down
15 changes: 4 additions & 11 deletions pkg/internal/unit21/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,10 @@ func TestEvaluateTransactionManyLinkedCards(t *testing.T) {
assert.NoError(t, err)
assert.Greater(t, len([]rune(u21InstrumentId)), 0)

// Log create instrument action w/ Unit21
u21ActionRepo := ActionRepo{
User: repository.NewUser(sqlxDB),
Device: repository.NewDevice(sqlxDB),
Location: repository.NewLocation(sqlxDB),
}

u21Action := NewAction(u21ActionRepo)
u21Action := NewAction()
_, err = u21Action.Create(instrument, "Creation", u21InstrumentId, "Creation")
if err != nil {
fmt.Printf("Error creating a new instrument action in Unit21")
t.Log("Error creating a new instrument action in Unit21")
return
}
}
Expand Down Expand Up @@ -174,13 +167,13 @@ func TestEvaluateTransactionNewUserHighSpend(t *testing.T) {
}

func evaluateMockTransaction(transaction model.Transaction, sqlxDB *sqlx.DB) (pass bool, err error) {
repo := TransactionRepo{
repos := TransactionRepos{
TxLeg: repository.NewTxLeg((sqlxDB)),
User: repository.NewUser(sqlxDB),
Asset: repository.NewAsset(sqlxDB),
}

u21Transaction := NewTransaction(repo)
u21Transaction := NewTransaction(repos)

pass, err = u21Transaction.Evaluate(transaction)

Expand Down
Loading