Skip to content

Commit

Permalink
Merge pull request #280 from getyoti/release/v3.10.0
Browse files Browse the repository at this point in the history
Release/v3.10.0
  • Loading branch information
mehmet-yoti authored Jun 28, 2023
2 parents 650b910 + 3650bd9 commit 374fda8
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import "github.com/getyoti/yoti-go-sdk/v3"
```
or add the following line to your go.mod file (check https://github.com/getyoti/yoti-go-sdk/releases for the latest version)
```
require github.com/getyoti/yoti-go-sdk/v3 v3.9.0
require github.com/getyoti/yoti-go-sdk/v3 v3.10.0
```

## Setup
Expand Down
34 changes: 27 additions & 7 deletions _examples/idv/models.sessionspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func buildSessionSpec() (sessionSpec *create.SessionSpecification, err error) {
var textExtractionTask *task.RequestedTextExtractionTask
textExtractionTask, err = task.NewRequestedTextExtractionTaskBuilder().
WithManualCheckAlways().
WithExpandedDocumentFields(true).
Build()
if err != nil {
return nil, err
Expand Down Expand Up @@ -102,23 +103,43 @@ func buildSessionSpec() (sessionSpec *create.SessionSpecification, err error) {
return nil, err
}

passportFilter, err := filter.NewRequestedOrthogonalRestrictionsFilterBuilder().
//This section is used for Orthogonal Restriction
/*passportFilter, err := filter.NewRequestedOrthogonalRestrictionsFilterBuilder().
WithIncludedDocumentTypes(
[]string{"PASSPORT"}).
WithNonLatinDocuments(true).
WithExpiredDocuments(false).
Build()
if err != nil {
return nil, err
}*/

docRestriction, err := filter.NewRequestedDocumentRestrictionBuilder().
WithDocumentTypes([]string{"PASSPORT"}).
WithCountryCodes([]string{"GBR"}).
Build()
if err != nil {
return nil, err
}
passportDoc, err := filter.NewRequiredIDDocumentBuilder().

/*passportDoc, err := filter.NewRequiredIDDocumentBuilder().
WithFilter(passportFilter).
Build()
if err != nil {
return nil, err
}*/

docFilter, err := filter.NewRequestedDocumentRestrictionsFilterBuilder().
ForIncludeList().
WithDocumentRestriction(docRestriction).
WithAllowNonLatinDocuments(true).
WithExpiredDocuments(false).
Build()
if err != nil {
return nil, err
}

idDoc, err := filter.NewRequiredIDDocumentBuilder().Build()
idDoc, err := filter.NewRequiredIDDocumentBuilder().WithFilter(docFilter).Build()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -149,14 +170,16 @@ func buildSessionSpec() (sessionSpec *create.SessionSpecification, err error) {
WithRequestedTask(textExtractionTask).
WithRequestedTask(supplementaryDocTextExtractionTask).
WithSDKConfig(sdkConfig).
WithRequiredDocument(passportDoc).
//Below line will be enabled when orthogonal Restriction is Needed
//WithRequiredDocument(passportDoc).
WithRequiredDocument(idDoc).
WithRequiredDocument(supplementaryDoc).
Build()

if err != nil {
return nil, err
}

return sessionSpec, nil
}

Expand Down Expand Up @@ -207,8 +230,5 @@ func buildDBSSessionSpec() (sessionSpec *create.SessionSpecification, err error)
WithImportToken(importToken).
Build()

if err != nil {
return nil, err
}
return sessionSpec, nil
}
35 changes: 35 additions & 0 deletions _examples/idv/templates/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,41 @@ <h5>Media</h5>
</div>
{{ end }}

{{ if $doc.ExpandedDocumentFields }}
<div class="card">
<div class="card-header" id="document-fields-{{ $key }}">
<h4 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse"
data-target="#collapse-document-fields-{{ $key }}"
aria-expanded="true"
aria-controls="collapse-document-fields-{{ $key }}">
Expanded Document Fields
</button>
</h4>
</div>
<div id="collapse-document-fields-{{ $key }}" class="collapse"
aria-labelledby="document-fields-{{ $key }}">
<div class="card-body">
{{ if $doc.ExpandedDocumentFields.Media }}
<h5>Media</h5>
<table class="table table-striped table-light">
<tbody>
<tr>
<td>ID</td>
<td>
<a href="/media?mediaId={{ $doc.ExpandedDocumentFields.Media.ID }}">
{{ $doc.ExpandedDocumentFields.Media.ID }}
</a>
</td>
</tr>
</tbody>
</table>
{{ end }}
</div>
</div>
</div>
{{ end }}

{{ if $doc.DocumentIDPhoto }}
<div class="card">
<div class="card-header" id="document-id-photo-{{ $key }}">
Expand Down
2 changes: 1 addition & 1 deletion consts/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package consts

const (
SDKIdentifier = "Go"
SDKVersionIdentifier = "3.9.0"
SDKVersionIdentifier = "3.10.0"
)
42 changes: 32 additions & 10 deletions docscan/session/create/filter/document_restrictions_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import "encoding/json"

// RequestedDocumentRestrictionsFilter filters for a required document, allowing specification of restrictive parameters
type RequestedDocumentRestrictionsFilter struct {
inclusion string
documents []*RequestedDocumentRestriction
inclusion string
documents []*RequestedDocumentRestriction
allowExpiredDocuments *bool
allowNonLatinDocuments *bool
}

// Type is the type of the document restriction filter
Expand All @@ -16,20 +18,26 @@ func (r RequestedDocumentRestrictionsFilter) Type() string {
// MarshalJSON returns the JSON encoding
func (r *RequestedDocumentRestrictionsFilter) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
Inclusion string `json:"inclusion"`
Documents []*RequestedDocumentRestriction `json:"documents"`
Type string `json:"type"`
Inclusion string `json:"inclusion"`
Documents []*RequestedDocumentRestriction `json:"documents"`
AllowExpiredDocuments *bool `json:"allow_expired_documents,omitempty"`
AllowNonLatinDocuments *bool `json:"allow_non_latin_documents,omitempty"`
}{
Type: r.Type(),
Inclusion: r.inclusion,
Documents: r.documents,
Type: r.Type(),
Inclusion: r.inclusion,
Documents: r.documents,
AllowExpiredDocuments: r.allowExpiredDocuments,
AllowNonLatinDocuments: r.allowNonLatinDocuments,
})
}

// RequestedDocumentRestrictionsFilterBuilder builds a RequestedDocumentRestrictionsFilter
type RequestedDocumentRestrictionsFilterBuilder struct {
inclusion string
documents []*RequestedDocumentRestriction
inclusion string
documents []*RequestedDocumentRestriction
allowExpiredDocuments *bool
allowNonLatinDocuments *bool
}

// NewRequestedDocumentRestrictionsFilterBuilder creates a new RequestedDocumentRestrictionsFilterBuilder
Expand Down Expand Up @@ -57,10 +65,24 @@ func (b *RequestedDocumentRestrictionsFilterBuilder) WithDocumentRestriction(doc
return b
}

// WithExpiredDocuments sets a bool value to allowExpiredDocuments on filter
func (b *RequestedDocumentRestrictionsFilterBuilder) WithExpiredDocuments(allowExpiredDocuments bool) *RequestedDocumentRestrictionsFilterBuilder {
b.allowExpiredDocuments = &allowExpiredDocuments
return b
}

// WithExpiredDocuments sets a bool value to allowExpiredDocuments on filter
func (b *RequestedDocumentRestrictionsFilterBuilder) WithAllowNonLatinDocuments(allowNonLatinDocuments bool) *RequestedDocumentRestrictionsFilterBuilder {
b.allowNonLatinDocuments = &allowNonLatinDocuments
return b
}

// Build creates a new RequestedDocumentRestrictionsFilter
func (b *RequestedDocumentRestrictionsFilterBuilder) Build() (*RequestedDocumentRestrictionsFilter, error) {
return &RequestedDocumentRestrictionsFilter{
b.inclusion,
b.documents,
b.allowExpiredDocuments,
b.allowNonLatinDocuments,
}, nil
}
76 changes: 76 additions & 0 deletions docscan/session/create/filter/document_restrictions_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,79 @@ func ExampleRequestedDocumentRestrictionsFilterBuilder_ForExcludeList() {
fmt.Println(string(data))
// Output: {"type":"DOCUMENT_RESTRICTIONS","inclusion":"BLACKLIST","documents":[{"document_types":["PASSPORT"]}]}
}

func ExampleRequestedDocumentRestrictionsFilterBuilder_withExpiredDocuments() {
restriction, err := NewRequestedDocumentRestrictionsFilterBuilder().
WithExpiredDocuments(true).
Build()
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

data, err := json.Marshal(restriction)
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

fmt.Println(string(data))
// Output: {"type":"DOCUMENT_RESTRICTIONS","inclusion":"","documents":[],"allow_expired_documents":true}
}

func ExampleRequestedDocumentRestrictionsFilterBuilder_withDenyExpiredDocuments() {
restriction, err := NewRequestedDocumentRestrictionsFilterBuilder().
WithExpiredDocuments(false).
Build()
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

data, err := json.Marshal(restriction)
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

fmt.Println(string(data))
// Output: {"type":"DOCUMENT_RESTRICTIONS","inclusion":"","documents":[],"allow_expired_documents":false}
}

func ExampleRequestedDocumentRestrictionsFilterBuilder_withAllowNonLatinDocuments() {
restriction, err := NewRequestedDocumentRestrictionsFilterBuilder().
WithAllowNonLatinDocuments(true).
Build()
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

data, err := json.Marshal(restriction)
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

fmt.Println(string(data))
// Output: {"type":"DOCUMENT_RESTRICTIONS","inclusion":"","documents":[],"allow_non_latin_documents":true}
}

func ExampleRequestedDocumentRestrictionsFilterBuilder_withDenyNonLatinDocuments() {
restriction, err := NewRequestedDocumentRestrictionsFilterBuilder().
WithAllowNonLatinDocuments(false).
Build()
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

data, err := json.Marshal(restriction)
if err != nil {
fmt.Printf("error: %s", err.Error())
return
}

fmt.Println(string(data))
// Output: {"type":"DOCUMENT_RESTRICTIONS","inclusion":"","documents":[],"allow_non_latin_documents":false}
}
17 changes: 13 additions & 4 deletions docscan/session/create/task/text_extraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func NewRequestedTextExtractionTask(config RequestedTextExtractionTaskConfig) *R

// RequestedTextExtractionTaskConfig is the configuration applied when creating a Text Extraction Task
type RequestedTextExtractionTaskConfig struct {
ManualCheck string `json:"manual_check,omitempty"`
ChipData string `json:"chip_data,omitempty"`
ManualCheck string `json:"manual_check,omitempty"`
ChipData string `json:"chip_data,omitempty"`
CreateExpandedDocumentFields bool `json:"create_expanded_document_fields,omitempty"`
}

// NewRequestedTextExtractionTaskBuilder creates a new RequestedTextExtractionTaskBuilder
Expand All @@ -50,8 +51,9 @@ func NewRequestedTextExtractionTaskBuilder() *RequestedTextExtractionTaskBuilder

// RequestedTextExtractionTaskBuilder builds a RequestedTextExtractionTask
type RequestedTextExtractionTaskBuilder struct {
manualCheck string
chipData string
manualCheck string
chipData string
createExpandedDocumentFields bool
}

// WithManualCheckAlways sets the value of manual check to "ALWAYS"
Expand Down Expand Up @@ -84,11 +86,18 @@ func (builder *RequestedTextExtractionTaskBuilder) WithChipDataIgnore() *Request
return builder
}

// withExpandedDocumentFields sets the value of expanded document fields whether its true or false
func (builder *RequestedTextExtractionTaskBuilder) WithExpandedDocumentFields(expandedDocumentFields bool) *RequestedTextExtractionTaskBuilder {
builder.createExpandedDocumentFields = expandedDocumentFields
return builder
}

// Build builds the RequestedTextExtractionTask
func (builder *RequestedTextExtractionTaskBuilder) Build() (*RequestedTextExtractionTask, error) {
config := RequestedTextExtractionTaskConfig{
builder.manualCheck,
builder.chipData,
builder.createExpandedDocumentFields,
}

return NewRequestedTextExtractionTask(config), nil
Expand Down
12 changes: 12 additions & 0 deletions docscan/session/create/task/text_extraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,15 @@ func TestRequestedTextExtractionTaskBuilder_WithChipDataIgnore(t *testing.T) {
config := task.Config().(RequestedTextExtractionTaskConfig)
assert.Equal(t, "IGNORE", config.ChipData)
}

func TestRequestedTextExtractionTaskBuilder_WithExpandedDocumentFields(t *testing.T) {
task, err := NewRequestedTextExtractionTaskBuilder().
WithExpandedDocumentFields(true).
Build()
if err != nil {
t.Fail()
}

config := task.Config().(RequestedTextExtractionTaskConfig)
assert.Equal(t, true, config.CreateExpandedDocumentFields)
}
6 changes: 6 additions & 0 deletions docscan/session/retrieve/expanded_document_fields_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package retrieve

// DocumentFieldsResponse represents the document fields in a document
type ExpandedDocumentFieldsResponse struct {
Media *MediaResponse `json:"media"`
}
7 changes: 4 additions & 3 deletions docscan/session/retrieve/id_document_resource_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ type IDDocumentResourceResponse struct {
// Pages are the individual pages of the identity document
Pages []*PageResponse `json:"pages"`
// DocumentFields are the associated document fields of a document
DocumentFields *DocumentFieldsResponse `json:"document_fields"`
DocumentIDPhoto *DocumentIDPhotoResponse `json:"document_id_photo"`
textExtractionTasks []*TextExtractionTaskResponse
DocumentFields *DocumentFieldsResponse `json:"document_fields"`
ExpandedDocumentFields *ExpandedDocumentFieldsResponse `json:"expanded_document_fields"`
DocumentIDPhoto *DocumentIDPhotoResponse `json:"document_id_photo"`
textExtractionTasks []*TextExtractionTaskResponse
}

// TextExtractionTasks returns a slice of text extraction tasks associated with the ID document
Expand Down
2 changes: 1 addition & 1 deletion requests/signed_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRequestShouldBuildForValid(t *testing.T) {
assert.Check(t, urlCheck)
assert.Check(t, signed.Header.Get("X-Yoti-Auth-Digest") != "")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK"), "Go")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.9.0")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.10.0")
}

func TestRequestShouldAddHeaders(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.organization = getyoti
sonar.projectKey = getyoti:go
sonar.projectName = Go SDK
sonar.projectVersion = 3.9.0
sonar.projectVersion = 3.10.0
sonar.exclusions = **/yotiprotoattr/*.go,**/yotiprotocom/*.go,**/yotiprotoshare/*.go,**/**_test.go,_examples/**/*
sonar.links.scm = https://github.com/getyoti/yoti-go-sdk
sonar.host.url = https://sonarcloud.io
Expand Down

0 comments on commit 374fda8

Please sign in to comment.