diff --git a/CHANGELOG.md b/CHANGELOG.md index 7603089..022299d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] +### Added +- IndividualAccountAttachment resource +### Changed +- IndividualAccountRequest address as structured object ## [0.18.0] - 2026-05-04 ### Added diff --git a/README.md b/README.md index b9937b0..a8e0dc6 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ This SDK version is compatible with the Stark Infra API v2. - [IndividualIdentity](#create-individualidentities): Create individual identities - [IndividualDocument](#create-individualdocuments): Create individual documents - [IndividualAccountRequest](#create-individualaccountrequest): Create individual account requests - - [AccountRequestAttachment](#create-accountrequestattachment): Create account request attachments + - [IndividualAccountAttachment](#create-individualaccountattachments): Create individual account attachments - [Webhook](#webhook): - [Webhook](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions - [WebhookEvents](#process-webhook-events): Manage Webhook events @@ -3185,8 +3185,15 @@ await (async() => { let accounts = await starkinfra.individualAccountRequest.create([ new starkinfra.IndividualAccountRequest({ name: "Tony Stark", - taxId: "634.906.770-30", - address: "R. pamplona, 4321", + taxId: "012.345.678-90", + address: { + street: "Av. Faria Lima", + number: "4321", + neighborhood: "Itaim Bibi", + city: "Sao Paulo", + state: "SP", + zipCode: "04538133" + }, income: 50000 }) ]); @@ -3244,7 +3251,7 @@ await (async() => { })(); ``` -**Note**: Before sending your individual account request to validation by patching its status, you must send all the required documents using the create method of the AccountRequestAttachment resource. +**Note**: Before sending your individual account request to validation by patching its status, you must send all the required documents using the create method of the IndividualAccountAttachment resource. ### Query IndividualAccountRequest logs @@ -3276,81 +3283,110 @@ await (async() => { })(); ``` -### Create AccountRequestAttachment +### Create IndividualAccountAttachments -You can create an account request attachment to attach images of documents to a specific individual account request. -You must reference the desired account request by its id. +You can create an individual account attachment to attach images of documents to a specific individual account request. +You must reference the desired account request by its id. Pass the raw image bytes plus a MIME content type and the SDK +encodes them as a `data:` URL client-side before sending. ```javascript +const fs = require('fs'); + await (async() => { - let attachments = await starkinfra.accountRequestAttachment.create([ - new starkinfra.AccountRequestAttachment({ + let attachments = await starkinfra.individualAccountAttachment.create([ + new starkinfra.IndividualAccountAttachment({ 'type': "identity-front", - 'content': "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...", - 'accountRequestId': '5155165527080960', - 'tags': ["breaking", "bad"] - }) - ]); - - console.log(attachments[0]); - - attachments = await starkinfra.accountRequestAttachment.create([ - new starkinfra.AccountRequestAttachment({ - 'type': "identity-back", - 'content': "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...", - 'accountRequestId': '5155165527080960', - 'tags': ["breaking", "bad"] - }) - ]); - - console.log(attachments[0]); - - attachments = await starkinfra.accountRequestAttachment.create([ - new starkinfra.AccountRequestAttachment({ - 'type': "selfie", - 'content': "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD...", + 'content': fs.readFileSync('identity-front.png'), + 'contentType': "image/png", 'accountRequestId': '5155165527080960', 'tags': ["breaking", "bad"] }) ]); - console.log(attachments[0]); + for (let attachment of attachments) { + console.log(attachment); + } })(); ``` -**Note**: Instead of using AccountRequestAttachment objects, you can also pass each element in dictionary format +**Note**: Instead of using IndividualAccountAttachment objects, you can also pass each element in dictionary format -### Query AccountRequestAttachments +### Query IndividualAccountAttachments -You can query multiple account request attachments according to filters. +You can query multiple individual account attachments according to filters. ```javascript await (async() => { - let attachments = await starkinfra.accountRequestAttachment.query({ + let attachments = await starkinfra.individualAccountAttachment.query({ + 'limit': 10, 'after': '2022-01-01', 'before': '2022-03-01', 'status': "success", 'tags': ["breaking", "bad"], + 'ids': ["5656565656565656"] }); - - for await (let attachment of attachment) { + + for await (let attachment of attachments) { console.log(attachment); } })(); ``` -### Get an AccountRequestAttachment +### Get an IndividualAccountAttachment -After its creation, information on an account request attachment may be retrieved by its id. +After its creation, information on an individual account attachment may be retrieved by its id. ```javascript await (async() => { - let attachment = await starkinfra.accountRequestAttachment.get('5155165527080960'); - + let attachment = await starkinfra.individualAccountAttachment.get('5155165527080960'); + + console.log(attachment); +})(); +``` + +### Cancel an IndividualAccountAttachment + +You can also cancel an individual account attachment by its id. + +```javascript +await (async() => { + let attachment = await starkinfra.individualAccountAttachment.cancel('5155165527080960'); + console.log(attachment); })(); ``` +### Query IndividualAccountAttachment logs + +You can query individual account attachment logs to better understand attachment life cycles. + +```javascript +await (async() => { + let logs = await starkinfra.individualAccountAttachment.log.query({ + 'limit': 50, + 'after': '2022-01-01', + 'before': '2022-01-20', + 'attachmentIds': ["5656565656565656"] + }); + + for await (let log of logs) { + console.log(log); + } +})(); +``` + +### Get an IndividualAccountAttachment log + +You can also get a specific log by its id. + +```javascript +await (async() => { + let log = await starkinfra.individualAccountAttachment.log.get('5155165527080960'); + + console.log(log); +})(); +``` + ## Webhook ### Create a webhook subscription diff --git a/index.js b/index.js index 2504f80..243e34d 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,7 @@ exports.staticBrcode = require('./sdk/staticBrcode'); exports.brcodePreview = require('./sdk/brcodePreview'); exports.individualIdentity = require('./sdk/individualIdentity'); exports.individualDocument = require('./sdk/individualDocument'); -exports.accountRequestAttachment = require('./sdk/accountRequestAttachment'); +exports.individualAccountAttachment = require('./sdk/individualAccountAttachment'); exports.individualAccountRequest = require('./sdk/individualAccountRequest'); exports.issuingProduct = require('./sdk/issuingProduct'); exports.issuingCard = require('./sdk/issuingCard'); @@ -60,7 +60,7 @@ exports.bacenId = require('./sdk/utils/bacenId.js'); exports.returnId = require('./sdk/utils/returnId.js'); exports.endToEndId = require('./sdk/utils/endToEndId.js'); exports.key = require('./sdk/key.js'); -exports.error = require('./sdk/error.js'); +exports.error = require('./node_modules/starkcore/starkcore/error.js'); exports.request = require('./sdk/request/request.js') @@ -88,7 +88,7 @@ exports.BrcodePreview = exports.brcodePreview.BrcodePreview; exports.IndividualIdentity = exports.individualIdentity.IndividualIdentity; exports.IndividualDocument = exports.individualDocument.IndividualDocument; exports.IndividualAccountRequest = exports.individualAccountRequest.IndividualAccountRequest; -exports.AccountRequestAttachment = exports.accountRequestAttachment.AccountRequestAttachment; +exports.IndividualAccountAttachment = exports.individualAccountAttachment.IndividualAccountAttachment; exports.IssuingProduct = exports.issuingProduct.IssuingProduct; exports.IssuingCard = exports.issuingCard.IssuingCard; exports.IssuingRule = exports.issuingRule.IssuingRule; diff --git a/sdk/accountRequestAttachment/index.js b/sdk/accountRequestAttachment/index.js deleted file mode 100644 index ed9f181..0000000 --- a/sdk/accountRequestAttachment/index.js +++ /dev/null @@ -1,9 +0,0 @@ -const accountRequestAttachment = require('./accountRequestAttachment.js'); - -exports.log = require('./log'); -exports.create = accountRequestAttachment.create; -exports.get = accountRequestAttachment.get; -exports.query = accountRequestAttachment.query; -exports.page = accountRequestAttachment.page; - -exports.AccountRequestAttachment = accountRequestAttachment.AccountRequestAttachment; diff --git a/sdk/individualAccountAttachment/index.js b/sdk/individualAccountAttachment/index.js new file mode 100644 index 0000000..65ed3d1 --- /dev/null +++ b/sdk/individualAccountAttachment/index.js @@ -0,0 +1,10 @@ +const individualAccountAttachment = require('./individualAccountAttachment.js'); + +exports.log = require('./log'); +exports.create = individualAccountAttachment.create; +exports.get = individualAccountAttachment.get; +exports.query = individualAccountAttachment.query; +exports.page = individualAccountAttachment.page; +exports.cancel = individualAccountAttachment.cancel; + +exports.IndividualAccountAttachment = individualAccountAttachment.IndividualAccountAttachment; diff --git a/sdk/accountRequestAttachment/accountRequestAttachment.js b/sdk/individualAccountAttachment/individualAccountAttachment.js similarity index 51% rename from sdk/accountRequestAttachment/accountRequestAttachment.js rename to sdk/individualAccountAttachment/individualAccountAttachment.js index a31959d..227dbee 100644 --- a/sdk/accountRequestAttachment/accountRequestAttachment.js +++ b/sdk/individualAccountAttachment/individualAccountAttachment.js @@ -3,42 +3,44 @@ const check = require('starkcore').check; const Resource = require('starkcore').Resource; -class AccountRequestAttachment extends Resource { +class IndividualAccountAttachment extends Resource { /** * - * AccountRequestAttachment object + * IndividualAccountAttachment object * - * @description You can create an Account Request Attachment to attach images of documents + * @description You can create an Individual Account Attachment to attach images of documents * to a specific Individual Account Request. You must reference the desired Individual Account Request by its id. - * - * When you initialize a AccountRequestAttachment, the entity will not be automatically + * + * When you initialize a IndividualAccountAttachment, the entity will not be automatically * created in the Stark Infra API. The 'create' function sends the objects * to the Stark Infra API and returns the list of created objects. * * Parameters (required): - * @param type [string]: type of the AccountRequestAttachment. Options: 'drivers-license-front', 'drivers-license-back', 'identity-front', 'identity-back' or 'selfie' - * @param content [string]: Base64 data url of the picture. ex: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD... - * @param accountRequestId [string]: Unique id of IndividualAccountRequest. ex: '5656565656565656' + * @param type [string]: type of the IndividualAccountAttachment. Options: 'drivers-license-front', 'drivers-license-back', 'identity-front', 'identity-back' or 'selfie' + * @param content [string]: raw image bytes at constructor time. After encoding, becomes the data:;base64, URL sent on the wire. ex: fs.readFileSync('identity-front.png') * @param contentType [string]: content MIME type. This parameter is required as input only. ex: 'image/png' or 'image/jpeg' - * + * @param accountRequestId [string]: Unique id of IndividualAccountRequest. ex: '5656565656565656' + * * Parameters (optional): - * @param tags [list of strings, default []]: list of strings for reference when searching for AccountRequestAttachments. ex: ['employees', 'monthly'] - * + * @param tags [list of strings, default []]: list of strings for reference when searching for IndividualAccountAttachments. ex: ['employees', 'monthly'] + * * Attributes (return-only): - * @param id [string]: unique id returned when AccountRequestAttachment is created. ex: '5656565656565656' - * @param status [string]: current status of the AccountRequestAttachment. ex: 'created' - * @param created [string]: creation datetime for the AccountRequestAttachment. ex: '2020-03-10 10:30:00.000' - * + * @param id [string]: unique id returned when IndividualAccountAttachment is created. ex: '5656565656565656' + * @param status [string]: current status of the IndividualAccountAttachment. Options: 'created', 'success', 'failed', 'deleted' + * @param created [string]: creation datetime for the IndividualAccountAttachment. ex: '2020-03-10 10:30:00.000' + * */ constructor({ - type, content = null, accountRequestId, contentType, created = null, status = null, id = null + type, content = null, contentType, accountRequestId, tags = null, + id = null, status = null, created = null }) { super(id); this.type = type; this.content = content; this.accountRequestId = accountRequestId; - this.created = check.datetime(created); + this.tags = tags; this.status = status; + this.created = check.datetime(created); if(contentType) { if(!content) { @@ -50,24 +52,24 @@ class AccountRequestAttachment extends Resource { } } -exports.AccountRequestAttachment = AccountRequestAttachment; -let resource = {'class': exports.AccountRequestAttachment, 'name': 'AccountRequestAttachment'}; +exports.IndividualAccountAttachment = IndividualAccountAttachment; +let resource = {'class': exports.IndividualAccountAttachment, 'name': 'IndividualAccountAttachment'}; exports.create = async function (attachments, { user } = {}) { /** * - * Create AccountRequestAttachments + * Create IndividualAccountAttachments * - * @description Send a list of AccountRequestAttachment objects for creation in the Stark Infra API + * @description Send a list of IndividualAccountAttachment objects for creation in the Stark Infra API * * Parameters (required): - * @param attachments [list of AccountRequestAttachment objects]: list of AccountRequestAttachment objects to be created in the API + * @param attachments [list of IndividualAccountAttachment objects]: list of IndividualAccountAttachment objects to be created in the API * * Parameters (optional): * @param user [Organization/Project object]: Organization or Project object. Not necessary if starkinfra.user was set before function call * * Return: - * @returns list of AccountRequestAttachment objects with updated attributes + * @returns list of IndividualAccountAttachment objects with updated attributes * */ return rest.post(resource, attachments, user); @@ -76,9 +78,9 @@ exports.create = async function (attachments, { user } = {}) { exports.get = async function (id, { user } = {}) { /** * - * Retrieve a specific AccountRequestAttachment + * Retrieve a specific IndividualAccountAttachment * - * @description Receive a single AccountRequestAttachment object previously created in the Stark Infra API by passing its id + * @description Receive a single IndividualAccountAttachment object previously created in the Stark Infra API by passing its id * * Parameters (required): * @param id [string]: object unique id. ex: '5656565656565656' @@ -87,7 +89,7 @@ exports.get = async function (id, { user } = {}) { * @param user [Organization/Project object]: Organization or Project object. Not necessary if starkinfra.user was set before function call * * Return: - * @returns AccountRequestAttachment object with updated attributes + * @returns IndividualAccountAttachment object with updated attributes * */ return rest.getId(resource, id, user); @@ -96,21 +98,21 @@ exports.get = async function (id, { user } = {}) { exports.query = async function ({ limit, after, before, status, tags, ids, user } = {}) { /** * - * Retrieve AccountRequestAttachments + * Retrieve IndividualAccountAttachments * - * @description Receive a generator of AccountRequestAttachment objects previously created in the Stark Infra API and the cursor to the next page. + * @description Receive a generator of IndividualAccountAttachment objects previously created in the Stark Infra API and the cursor to the next page. * * Parameters (optional): * @param limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35 * @param after [string, default null]: date filter for objects created after this date. ex: '2020-03-10' * @param before [string, default null]: date filter for objects created before this date. ex: '2020-03-10' - * @param status [string, default null]: filter for status of the retrieved objects. ex: 'created', 'canceled', 'processing', 'failed', 'success' - * @param tags [list of strings, default null]: list of strings for reference when searching for AccountRequestAttachments. ex: ['employees', 'monthly'] - * @param ids [list of strings, default null]: list of AccountRequestAttachment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] + * @param status [string, default null]: filter for status of the retrieved objects. ex: 'created', 'success', 'failed', 'deleted' + * @param tags [list of strings, default null]: list of strings for reference when searching for IndividualAccountAttachments. ex: ['employees', 'monthly'] + * @param ids [list of strings, default null]: list of IndividualAccountAttachment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call * * Return: - * @returns list of AccountRequestAttachment objects with updated attributes + * @returns list of IndividualAccountAttachment objects with updated attributes * */ let query = { @@ -127,22 +129,22 @@ exports.query = async function ({ limit, after, before, status, tags, ids, user exports.page = async function ({ cursor, limit, after, before, status, tags, ids, user } = {}) { /** * - * Retrieve paged AccountRequestAttachments + * Retrieve paged IndividualAccountAttachments * - * @description Receive a list of AccountRequestAttachment objects previously created in the Stark Infra API and the cursor to the next page. + * @description Receive a list of IndividualAccountAttachment objects previously created in the Stark Infra API and the cursor to the next page. * * Parameters (optional): * @param cursor [string, default null]: cursor returned on the previous page function call * @param limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35 * @param after [string, default null]: date filter for objects created after this date. ex: '2020-03-10' * @param before [string, default null]: date filter for objects created before this date. ex: '2020-03-10' - * @param status [string, default null]: filter for status of the retrieved objects. ex: 'created', 'canceled', 'processing', 'failed', 'success' - * @param tags [list of strings, default null]: list of strings for reference when searching for AccountRequestAttachments. ex: ['employees', 'monthly'] - * @param ids [list of strings, default null]: list of AccountRequestAttachment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] + * @param status [string, default null]: filter for status of the retrieved objects. ex: 'created', 'success', 'failed', 'deleted' + * @param tags [list of strings, default null]: list of strings for reference when searching for IndividualAccountAttachments. ex: ['employees', 'monthly'] + * @param ids [list of strings, default null]: list of IndividualAccountAttachment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call * * Return: - * @returns list of AccountRequestAttachment objects with updated attributes and a cursor to the next page + * @returns list of IndividualAccountAttachment objects with updated attributes and a cursor to the next page * */ let query = { @@ -156,3 +158,23 @@ exports.page = async function ({ cursor, limit, after, before, status, tags, ids }; return rest.getPage(resource, query, user); }; + +exports.cancel = async function (id, { user } = {}) { + /** + * + * Cancel an IndividualAccountAttachment + * + * @description Cancel an IndividualAccountAttachment entity previously created in the Stark Infra API + * + * Parameters (required): + * @param id [string]: IndividualAccountAttachment unique id. ex: '5656565656565656' + * + * Parameters (optional): + * @param user [Organization/Project object]: Organization or Project object. Not necessary if starkinfra.user was set before function call + * + * Return: + * @returns deleted IndividualAccountAttachment object + * + */ + return rest.deleteId(resource, id, user); +}; diff --git a/sdk/accountRequestAttachment/log/index.js b/sdk/individualAccountAttachment/log/index.js similarity index 82% rename from sdk/accountRequestAttachment/log/index.js rename to sdk/individualAccountAttachment/log/index.js index 91ee194..af3ddf3 100644 --- a/sdk/accountRequestAttachment/log/index.js +++ b/sdk/individualAccountAttachment/log/index.js @@ -1,6 +1,5 @@ const log = require('./log.js'); -exports.Log = log.Log; exports.get = log.get; exports.query = log.query; exports.page = log.page; diff --git a/sdk/accountRequestAttachment/log/log.js b/sdk/individualAccountAttachment/log/log.js similarity index 66% rename from sdk/accountRequestAttachment/log/log.js rename to sdk/individualAccountAttachment/log/log.js index 0610066..ec259e6 100644 --- a/sdk/accountRequestAttachment/log/log.js +++ b/sdk/individualAccountAttachment/log/log.js @@ -2,19 +2,20 @@ const rest = require('../../utils/rest.js'); const check = require('starkcore').check; const Resource = require('../../utils/resource.js').Resource + class Log extends Resource { /** * - * AccountRequestAttachment.Log object + * IndividualAccountAttachment.Log object * - * @description Every time an AccountRequestAttachment entity is modified, a corresponding AccountRequestAttachment.Log + * @description Every time an IndividualAccountAttachment entity is modified, a corresponding IndividualAccountAttachment.Log * is generated for the entity. This log is never generated by the user. * * Attributes: * @param id [string]: unique id returned when the log is created. ex: '5656565656565656' - * @param attachment [AccountRequestAttachment]: AccountRequestAttachment entity to which the log refers to. - * @param errors [list of strings]: list of errors linked to this AccountRequestAttachment event - * @param type [string]: type of the AccountRequestAttachment event which triggered the log creation. ex: "created", "canceled", "processing", "failed", "success" + * @param attachment [IndividualAccountAttachment]: IndividualAccountAttachment entity to which the log refers to. + * @param errors [list of strings]: list of errors linked to this IndividualAccountAttachment event + * @param type [string]: type of the IndividualAccountAttachment event which triggered the log creation. ex: "created", "success", "failed", "deleted" * @param created [string]: creation datetime for the log. ex: '2020-03-10 10:30:00.000' * */ @@ -30,14 +31,14 @@ class Log extends Resource { } exports.Log = Log; -let resource = {'class': exports.Log, 'name': 'AccountRequestAttachmentLog'}; +let resource = {'class': exports.Log, 'name': 'IndividualAccountAttachmentLog'}; exports.get = async function (id, { user } = {}) { /** * - * Retrieve a specific AccountRequestAttachment Log + * Retrieve a specific IndividualAccountAttachment Log * - * @description Receive a single AccountRequestAttachment Log object previously created by the Stark Infra API by passing its id + * @description Receive a single IndividualAccountAttachment Log object previously created by the Stark Infra API by passing its id * * Parameters (required): * @param id [string]: object unique id. ex: '5656565656565656' @@ -46,7 +47,7 @@ exports.get = async function (id, { user } = {}) { * @param user [Organization/Project object]: Organization or Project object. Not necessary if starkinfra.user was set before function call * * Return: - * @returns AccountRequestAttachment Log object with updated attributes + * @returns IndividualAccountAttachment Log object with updated attributes * */ return rest.getId(resource, id, user); @@ -55,20 +56,20 @@ exports.get = async function (id, { user } = {}) { exports.query = async function ({ limit, after, before, types, attachmentIds, user } = {}) { /** * - * Retrieve AccountRequestAttachment Logs + * Retrieve IndividualAccountAttachment Logs * - * @description Receive a generator of AccountRequestAttachment Log objects previously created in the Stark Infra API + * @description Receive a generator of IndividualAccountAttachment Log objects previously created in the Stark Infra API * * Parameters (optional): * @param limit [integer, default null]: maximum number of objects to be retrieved. Unlimited if null. ex: 35 * @param after [string, default null]: date filter for objects created only after specified date. ex: '2020-03-10' * @param before [string, default null]: date filter for objects created only before specified date. ex: '2020-03-10' - * @param types [list of strings, default null]: filter retrieved objects by types. ex: ["created", "canceled", "processing", "failed", "success"] - * @param attachmentIds [list of strings, default null]: list of AccountRequestAttachment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] + * @param types [list of strings, default null]: filter retrieved objects by types. ex: ["created", "success", "failed", "deleted"] + * @param attachmentIds [list of strings, default null]: list of IndividualAccountAttachment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call * * Return: - * @returns list of AccountRequestAttachment Log objects with updated attributes + * @returns list of IndividualAccountAttachment Log objects with updated attributes * */ let query = { @@ -84,9 +85,9 @@ exports.query = async function ({ limit, after, before, types, attachmentIds, us exports.page = async function ({ cursor, limit, after, before, types, attachmentIds, user } = {}) { /** * - * Retrieve paged AccountRequestAttachment Logs + * Retrieve paged IndividualAccountAttachment Logs * - * @description Receive a list of up to 100 AccountRequestAttachment.Log objects previously created in the Stark Infra API and the cursor to the next page. + * @description Receive a list of up to 100 IndividualAccountAttachment.Log objects previously created in the Stark Infra API and the cursor to the next page. * Use this function instead of query if you want to manually page your attachment logs. * * Parameters (optional): @@ -94,12 +95,12 @@ exports.page = async function ({ cursor, limit, after, before, types, attachment * @param limit [integer, default 100]: maximum number of objects to be retrieved. It must be an integer between 1 and 100. ex: 35 * @param after [string, default null]: date filter for objects created only after specified date. ex: '2020-03-10' * @param before [string, default null]: date filter for objects created only before specified date. ex: '2020-03-10' - * @param types [list of strings, default null]: filter retrieved objects by types. ex: ["created", "canceled", "processing", "failed", "success"] - * @param attachmentIds [list of strings, default null]: list of AccountRequestAttachment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] + * @param types [list of strings, default null]: filter retrieved objects by types. ex: ["created", "success", "failed", "deleted"] + * @param attachmentIds [list of strings, default null]: list of IndividualAccountAttachment ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545'] * @param user [Organization/Project object, default null]: Project object. Not necessary if starkinfra.user was set before function call * * Return: - * @returns list of AccountRequestAttachment Log objects with updated attributes and cursor to retrieve the next page of AccountRequestAttachment Log objects + * @returns list of IndividualAccountAttachment Log objects with updated attributes and cursor to retrieve the next page of IndividualAccountAttachment Log objects * */ let query = { diff --git a/sdk/individualAccountRequest/address.js b/sdk/individualAccountRequest/address.js new file mode 100644 index 0000000..2599859 --- /dev/null +++ b/sdk/individualAccountRequest/address.js @@ -0,0 +1,36 @@ +const SubResource = require('starkcore').SubResource; + + +class Address extends SubResource { + /** + * + * IndividualAccountRequest.Address object + * + * @description Structured residential address of the individual. It is exposed only as the + * 'address' field on an IndividualAccountRequest and is serialized as a nested JSON object on + * the wire — never flattened into addressStreet / addressCity / etc. + * + * Parameters (required): + * @param street [string]: street name. ex: 'Rua do Estilo Barroco' + * @param number [string]: street number. String, not integer (may contain non-digit chars). ex: '648' + * @param neighborhood [string]: neighborhood / district. ex: 'Santo Amaro' + * @param city [string]: city. ex: 'Sao Paulo' + * @param state [string]: state (BR 2-letter code). ex: 'SP' + * @param zipCode [string]: ZIP code (BR CEP). Accepts formatted or digit-only. ex: '05724005' + * + */ + constructor({ + street, number, neighborhood, city, state, zipCode + }) { + super(); + this.street = street; + this.number = number; + this.neighborhood = neighborhood; + this.city = city; + this.state = state; + this.zipCode = zipCode; + } +} + +exports.Address = Address; +exports.subResource = {'class': exports.Address, 'name': 'Address'}; diff --git a/sdk/individualAccountRequest/index.js b/sdk/individualAccountRequest/index.js index b23ea1d..529a1cd 100644 --- a/sdk/individualAccountRequest/index.js +++ b/sdk/individualAccountRequest/index.js @@ -1,6 +1,7 @@ const individualAccountRequest = require('./individualAccountRequest.js'); exports.log = require('./log'); +exports.Address = require('./address.js').Address; exports.create = individualAccountRequest.create; exports.get = individualAccountRequest.get; exports.query = individualAccountRequest.query; diff --git a/sdk/individualAccountRequest/individualAccountRequest.js b/sdk/individualAccountRequest/individualAccountRequest.js index 4225358..c6ecd31 100644 --- a/sdk/individualAccountRequest/individualAccountRequest.js +++ b/sdk/individualAccountRequest/individualAccountRequest.js @@ -1,6 +1,7 @@ const rest = require('../utils/rest.js'); const check = require('starkcore').check; const Resource = require('starkcore').Resource; +const {Address} = require('./address.js'); class IndividualAccountRequest extends Resource { @@ -15,11 +16,11 @@ class IndividualAccountRequest extends Resource { * to the Stark Infra API and returns the list of created objects. * * Parameters (required): - * @param address [string]: Address of the individual. ex: 'R. pamplona, 123' - * @param income [number]: Income of the individual. ex: 5000 + * @param address [IndividualAccountRequest.Address object or dictionary]: Structured residential address of the individual. ex: new starkinfra.individualAccountRequest.Address({street: 'Rua do Estilo Barroco', number: '648', neighborhood: 'Santo Amaro', city: 'Sao Paulo', state: 'SP', zipCode: '05724005'}) + * @param income [number]: Income of the individual in cents. ex: 5000 * @param name [string]: Name of the individual. ex: 'John Doe' * @param taxId [string]: Tax ID of the individual. ex: '012.345.678-90' - * + * * Parameters (optional): * @param tags [list of strings, default []]: list of strings for reference when searching for IndividualAccountRequests. ex: ['employees', 'monthly'] * @@ -37,7 +38,7 @@ class IndividualAccountRequest extends Resource { id = null, status = null, created = null, updated = null }) { super(id); - this.address = address; + this.address = parseAddress(address); this.income = income; this.name = name; this.taxId = taxId; @@ -53,6 +54,16 @@ class IndividualAccountRequest extends Resource { exports.IndividualAccountRequest = IndividualAccountRequest; let resource = {'class': exports.IndividualAccountRequest, 'name': 'IndividualAccountRequest'}; +const parseAddress = function (address) { + // address is a structured nested object (M2) — never flattened. A plain dictionary is + // coerced into an Address instance; an existing Address instance is kept as-is; null passes through. + if (address == null) + return address; + if (address instanceof Address) + return address; + return Object.assign(new Address(address), address); +}; + exports.create = async function (accountRequests, { user } = {}) { /** * @@ -163,8 +174,8 @@ exports.update = async function (id, { address, income, name, taxId, status, tag * @param id [string]: IndividualAccountRequest id. ex: '5656565656565656' * * Parameters (optional): - * @param address [string]: Address of the individual. ex: 'R. pamplona, 123' - * @param income [number]: Income of the individual. ex: 5000 + * @param address [IndividualAccountRequest.Address object or dictionary]: Structured residential address of the individual. Replaces the address as a whole object — there is no partial/deep-merge PATCH. ex: new starkinfra.individualAccountRequest.Address({street: 'Av. Faria Lima', number: '4321', neighborhood: 'Itaim Bibi', city: 'Sao Paulo', state: 'SP', zipCode: '04538133'}) + * @param income [number]: Income of the individual in cents. ex: 5000 * @param name [string]: Name of the individual. ex: 'John Doe' * @param taxId [string]: Tax ID of the individual. ex: '012.345.678-90' * @param status [string]: Status of the individual account request. ex: 'processing' diff --git a/sdk/individualAccountRequest/log/log.js b/sdk/individualAccountRequest/log/log.js index d4f217a..a521ad1 100644 --- a/sdk/individualAccountRequest/log/log.js +++ b/sdk/individualAccountRequest/log/log.js @@ -84,7 +84,7 @@ exports.query = async function ({ limit, after, before, types, accountRequestIds return rest.getList(resource, query, user); }; -exports.page = async function ({ cursor, ids, limit, after, before, types, accountRequestIds, user } = {}) { +exports.page = async function ({ cursor, limit, after, before, types, accountRequestIds, user } = {}) { /** * * Retrieve paged IndividualAccountRequest Logs @@ -107,7 +107,6 @@ exports.page = async function ({ cursor, ids, limit, after, before, types, accou */ let query = { cursor: cursor, - ids: ids, limit: limit, after: after, before: before, diff --git a/tests/testAccountRequestAttachment.js b/tests/testAccountRequestAttachment.js deleted file mode 100644 index 723db09..0000000 --- a/tests/testAccountRequestAttachment.js +++ /dev/null @@ -1,124 +0,0 @@ -const fs = require('fs'); -const assert = require("assert"); -const starkinfra = require("../index.js"); -const {generateExampleIndividualAccountRequest} = require('./utils/individualAccountRequest'); - -starkinfra.user = require("./utils/user").exampleProject; - - -describe("TestAccountRequestAttachmentPost", function() { - this.timeout(10000); - it("test_success", async () => { - let requests = await starkinfra.individualAccountRequest.create([generateExampleIndividualAccountRequest()]); - for await (let request of requests) { - let image = fs.readFileSync('tests/utils/identity/identity-front-face.png'); - let attachments = await starkinfra.accountRequestAttachment.create([ - new starkinfra.AccountRequestAttachment({ - content: image, - contentType: "image/png", - type: "identity-back", - accountRequestId: request.id, - }) - ]); - assert(typeof attachments[0].id == 'string'); - } - }); -}); - -describe("TestAccountRequestAttachmentGet", function() { - this.timeout(10000); - it("test_success", async () => { - let i = 0; - const requests = await starkinfra.accountRequestAttachment.query({limit: 10}); - for await (let request of requests) { - assert(typeof request.id == "string"); - i += 1; - } - assert(i === 10); - }); -}); - -describe("TestAccountRequestAttachmentInfoGet", function() { - this.timeout(10000); - it("test_success", async () => { - let requests = await starkinfra.accountRequestAttachment.query({limit: 3}); - for await (let request of requests) { - assert(typeof request.id == "string"); - request = await starkinfra.accountRequestAttachment.get(request.id); - assert(typeof request.id == "string"); - } - }); - - it("test_success_ids", async () => { - let requests = await starkinfra.accountRequestAttachment.query({limit: 10}); - let requestsIdsExpected = []; - for await (let request of requests) { - requestsIdsExpected.push(request.id); - } - - let requestsResult = await starkinfra.accountRequestAttachment.query({ids: requestsIdsExpected}); - let requestsIdsResult = []; - for await (let request of requestsResult){ - requestsIdsResult.push(request.id); - } - - requestsIdsExpected.sort(); - requestsIdsResult.sort(); - assert(requestsIdsExpected.length === requestsIdsResult.length); - for (let i=0; i { - let ids = []; - let cursor = null; - let page = null; - for (let i = 0; i < 2; i++) { - [page, cursor] = await starkinfra.accountRequestAttachment.page({ limit: 5, cursor: cursor }); - for (let entity of page) { - assert(!ids.includes(entity.id)); - ids.push(entity.id); - } - if (cursor == null) { - break; - } - } - assert(ids.length === 10); - }); -}); - -describe("TestAccountRequestAttachmentQueryParams", function() { - this.timeout(10000); - it("test_success", async () => { - const requests = await starkinfra.accountRequestAttachment.query({ - limit: 2, - after: "2020-04-01", - before: "2021-04-30", - status: "created", - tags: ["food","drink"], - ids: ["1","2"] - }); - assert(requests.length===undefined) - }); -}); - -describe("TestAccountRequestAttachmentPageParams", function() { - this.timeout(10000); - it("test_success", async () => { - let cursor = null; - let requests = null; - [requests, cursor] = await starkinfra.accountRequestAttachment.page({ - limit: 2, - after: "2020-04-01", - before: "2021-04-30", - status: "created", - tags: ["food","drink"], - ids: ["1","2"] - }); - assert(requests.length===0) - }); -}); diff --git a/tests/testIndividualAccountAttachment.js b/tests/testIndividualAccountAttachment.js new file mode 100644 index 0000000..fe89430 --- /dev/null +++ b/tests/testIndividualAccountAttachment.js @@ -0,0 +1,317 @@ +const assert = require("assert"); +const starkinfra = require("../index.js"); +const {generateExampleIndividualAccountRequest} = require('./utils/individualAccountRequest'); +const {generateExampleIndividualAccountAttachment, exampleImageContent} = require('./utils/individualAccountAttachment'); + +starkinfra.user = require("./utils/user").exampleProject; + +async function freshAccountRequestId() { + let requests = await starkinfra.individualAccountRequest.create([ + new starkinfra.IndividualAccountRequest(generateExampleIndividualAccountRequest()) + ]); + return requests[0].id; +} + + +describe("TestIndividualAccountAttachmentExposure", function() { + this.timeout(10000); + it("test_success", async () => { + assert(typeof starkinfra.individualAccountAttachment === "object"); + assert(typeof starkinfra.IndividualAccountAttachment === "function"); + assert(typeof starkinfra.individualAccountAttachment.create === "function"); + assert(typeof starkinfra.individualAccountAttachment.get === "function"); + assert(typeof starkinfra.individualAccountAttachment.query === "function"); + assert(typeof starkinfra.individualAccountAttachment.page === "function"); + assert(typeof starkinfra.individualAccountAttachment.cancel === "function"); + assert(starkinfra.accountRequestAttachment === undefined); + assert(starkinfra.AccountRequestAttachment === undefined); + }); +}); + +describe("TestIndividualAccountAttachmentDataUrlEncoding", function() { + this.timeout(10000); + it("test_success", async () => { + let raw = exampleImageContent(); + let attachment = new starkinfra.IndividualAccountAttachment({ + type: "identity-front", + content: raw, + contentType: "image/png", + accountRequestId: "5189530608992256" + }); + assert(typeof attachment.content === "string"); + assert(attachment.content.startsWith("data:image/png;base64,")); + assert(attachment.content === "data:image/png;base64," + raw.toString("base64")); + }); +}); + +describe("TestIndividualAccountAttachmentContentTypeInputOnly", function() { + this.timeout(10000); + it("test_success", async () => { + let attachment = new starkinfra.IndividualAccountAttachment({ + type: "identity-front", + content: exampleImageContent(), + contentType: "image/png", + accountRequestId: "5189530608992256" + }); + assert(attachment.contentType === null); + }); +}); + +describe("TestIndividualAccountAttachmentPost", function() { + this.timeout(10000); + it("test_success", async () => { + let requests = await starkinfra.individualAccountRequest.create([generateExampleIndividualAccountRequest()]); + for await (let request of requests) { + let attachments = await starkinfra.individualAccountAttachment.create([ + new starkinfra.IndividualAccountAttachment(generateExampleIndividualAccountAttachment(request.id)) + ]); + for (let attachment of attachments) { + assert(typeof attachment.id == "string"); + } + } + }); +}); + +describe("TestIndividualAccountAttachmentTypeEnum", function() { + this.timeout(10000); + it("test_success", async () => { + const allowed = ["drivers-license-front", "drivers-license-back", "identity-front", "identity-back"]; + for (let t of allowed) { + let attachment = new starkinfra.IndividualAccountAttachment({ + type: t, + content: exampleImageContent(), + contentType: "image/png", + accountRequestId: "5189530608992256" + }); + assert(attachment.type === t); + } + }); +}); + +describe("TestIndividualAccountAttachmentGet", function() { + this.timeout(10000); + it("test_success", async () => { + let i = 0; + const attachments = await starkinfra.individualAccountAttachment.query({limit: 10}); + for await (let attachment of attachments) { + assert(typeof attachment.id == "string"); + i += 1; + } + assert(i === 10); + }); +}); + +describe("TestIndividualAccountAttachmentInfoGet", function() { + this.timeout(10000); + it("test_success", async () => { + let attachments = await starkinfra.individualAccountAttachment.query({limit: 3}); + for await (let attachment of attachments) { + assert(typeof attachment.id == "string"); + attachment = await starkinfra.individualAccountAttachment.get(attachment.id); + assert(typeof attachment.id == "string"); + } + }); + + it("test_success_ids", async () => { + let attachments = await starkinfra.individualAccountAttachment.query({limit: 10}); + let idsExpected = []; + for await (let attachment of attachments) { + idsExpected.push(attachment.id); + } + + let attachmentsResult = await starkinfra.individualAccountAttachment.query({ids: idsExpected}); + let idsResult = []; + for await (let attachment of attachmentsResult){ + idsResult.push(attachment.id); + } + + idsExpected.sort(); + idsResult.sort(); + assert(idsExpected.length === idsResult.length); + for (let i=0; i { + let ids = []; + let cursor = null; + let page = null; + for (let i = 0; i < 2; i++) { + [page, cursor] = await starkinfra.individualAccountAttachment.page({ limit: 5, cursor: cursor }); + for (let entity of page) { + assert(!ids.includes(entity.id)); + ids.push(entity.id); + } + if (cursor == null) { + break; + } + } + assert(ids.length === 10); + }); +}); + +describe("TestIndividualAccountAttachmentQueryParams", function() { + this.timeout(10000); + it("test_success", async () => { + const attachments = await starkinfra.individualAccountAttachment.query({ + limit: 2, + after: "2020-04-01", + before: "2021-04-30", + status: "created", + tags: ["food","drink"], + ids: ["1","2"] + }); + assert(attachments.length===undefined) + }); +}); + +describe("TestIndividualAccountAttachmentPageParams", function() { + this.timeout(10000); + it("test_success", async () => { + let cursor = null; + let attachments = null; + [attachments, cursor] = await starkinfra.individualAccountAttachment.page({ + limit: 2, + after: "2020-04-01", + before: "2021-04-30", + status: "created", + tags: ["food","drink"], + ids: ["1","2"] + }); + assert(attachments.length===0) + }); +}); + +describe("TestIndividualAccountAttachmentPostAndCancel", function() { + this.timeout(10000); + it("test_success", async () => { + let requests = await starkinfra.individualAccountRequest.create([generateExampleIndividualAccountRequest()]); + for await (let request of requests) { + let attachments = await starkinfra.individualAccountAttachment.create([ + new starkinfra.IndividualAccountAttachment(generateExampleIndividualAccountAttachment(request.id)) + ]); + for (let attachment of attachments) { + let deleted = await starkinfra.individualAccountAttachment.cancel(attachment.id); + assert(deleted.status === "deleted"); + } + } + }); +}); + +describe("TestIndividualAccountAttachmentDatetimeParsing", function () { + this.timeout(10000); + it("test_success", async () => { + const attachments = await starkinfra.individualAccountAttachment.query({ limit: 1 }); + for await (let attachment of attachments) { + assert(typeof attachment.created === 'string'); + } + }); +}); + +describe("TestIndividualAccountAttachmentInvalidType", function () { + this.timeout(10000); + it("test_invalid_type", async () => { + let ok = false; + let accountRequestId = await freshAccountRequestId(); + let params = generateExampleIndividualAccountAttachment(accountRequestId); + params.type = "not-a-real-type"; + try { + await starkinfra.individualAccountAttachment.create([new starkinfra.IndividualAccountAttachment(params)]); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountAttachmentInvalidContent", function () { + this.timeout(10000); + it("test_invalid_content", async () => { + let ok = false; + let accountRequestId = await freshAccountRequestId(); + let params = generateExampleIndividualAccountAttachment(accountRequestId); + params.content = ""; + delete params.contentType; + try { + await starkinfra.individualAccountAttachment.create([new starkinfra.IndividualAccountAttachment(params)]); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountAttachmentInvalidContentType", function () { + this.timeout(10000); + it("test_invalid_content_type", async () => { + let ok = false; + let accountRequestId = await freshAccountRequestId(); + let params = generateExampleIndividualAccountAttachment(accountRequestId); + delete params.contentType; + try { + await starkinfra.individualAccountAttachment.create([new starkinfra.IndividualAccountAttachment(params)]); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountAttachmentAccountRequestNotFound", function () { + this.timeout(10000); + it("test_account_request_not_found", async () => { + let ok = false; + let attachment = new starkinfra.IndividualAccountAttachment(generateExampleIndividualAccountAttachment("0")); + try { + await starkinfra.individualAccountAttachment.create([attachment]); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountAttachmentCancelIdempotent", function () { + this.timeout(10000); + it("test_second_cancel_succeeds", async () => { + let requests = await starkinfra.individualAccountRequest.create([generateExampleIndividualAccountRequest()]); + for await (let request of requests) { + let attachments = await starkinfra.individualAccountAttachment.create([ + new starkinfra.IndividualAccountAttachment(generateExampleIndividualAccountAttachment(request.id)) + ]); + for (let attachment of attachments) { + let firstCancel = await starkinfra.individualAccountAttachment.cancel(attachment.id); + assert(firstCancel.status === "deleted"); + let secondCancel = await starkinfra.individualAccountAttachment.cancel(attachment.id); + assert(secondCancel.status === "deleted"); + } + } + }); +}); + +describe("TestIndividualAccountAttachmentNotFound", function () { + this.timeout(10000); + it("test_not_found", async () => { + let ok = false; + try { + await starkinfra.individualAccountAttachment.get("0"); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); diff --git a/tests/testAccountRequestAttachmentLog.js b/tests/testIndividualAccountAttachmentLog.js similarity index 61% rename from tests/testAccountRequestAttachmentLog.js rename to tests/testIndividualAccountAttachmentLog.js index c1ce0f7..dbe7670 100644 --- a/tests/testAccountRequestAttachmentLog.js +++ b/tests/testIndividualAccountAttachmentLog.js @@ -4,40 +4,41 @@ const starkinfra = require('../index.js'); starkinfra.user = require('./utils/user').exampleProject; -describe('TestAccountRequestAttachmentLogGet', function(){ +describe('TestIndividualAccountAttachmentLogGet', function(){ this.timeout(10000); it('test_success', async () => { let i = 0; - const logs = await starkinfra.accountRequestAttachment.log.query({limit: 5}); + const logs = await starkinfra.individualAccountAttachment.log.query({limit: 5}); for await (let log of logs) { assert(typeof log.id == 'string'); i += 1; } - assert(i > 1); + assert(i === 5); }); }); -describe('TestAccountRequestAttachmentLogInfoGet', function(){ +describe('TestIndividualAccountAttachmentLogInfoGet', function(){ this.timeout(10000); it('test_success', async () => { - let logs = await starkinfra.accountRequestAttachment.log.query({limit: 10}); + let logs = await starkinfra.individualAccountAttachment.log.query({limit: 1}); for await (let log of logs) { assert(typeof log.id == 'string'); - log = await starkinfra.accountRequestAttachment.log.get(log.id); + log = await starkinfra.individualAccountAttachment.log.get(log.id); assert(typeof log.id == 'string'); + assert(typeof log.attachment === 'object' && log.attachment !== null); } }); }); -describe('TestAccountRequestAttachmentLogGetPage', function () { +describe('TestIndividualAccountAttachmentLogGetPage', function () { this.timeout(10000); it('test_success', async () => { let ids = []; let cursor = null; let page = null; for (let i = 0; i < 2; i++) { - [page, cursor] = await starkinfra.accountRequestAttachment.log.page({ limit: 5, cursor: cursor }); + [page, cursor] = await starkinfra.individualAccountAttachment.log.page({ limit: 5, cursor: cursor }); for (let entity of page) { assert(!ids.includes(entity.id)); ids.push(entity.id); @@ -46,14 +47,15 @@ describe('TestAccountRequestAttachmentLogGetPage', function () { break; } } - assert(ids.length > 1); + assert(ids.length === 10); }); }); -describe('TestAccountRequestAttachmentLogQueryParams', function(){ + +describe('TestIndividualAccountAttachmentLogQueryParams', function(){ this.timeout(10000); it('test_success', async () => { - let logs = await starkinfra.accountRequestAttachment.log.query({ + let logs = await starkinfra.individualAccountAttachment.log.query({ limit: 2, after: '2020-04-01', before: '2021-04-30', @@ -64,12 +66,12 @@ describe('TestAccountRequestAttachmentLogQueryParams', function(){ }); }); -describe('TestAccountRequestAttachmentLogPageParams', function(){ +describe('TestIndividualAccountAttachmentLogPageParams', function(){ this.timeout(10000); it('test_success', async () => { let cursor = null; let logs = null; - [logs, cursor] = await starkinfra.accountRequestAttachment.log.page({ + [logs, cursor] = await starkinfra.individualAccountAttachment.log.page({ limit: 2, after: '2020-04-01', before: '2021-04-30', diff --git a/tests/testIndividualAccountRequest.js b/tests/testIndividualAccountRequest.js index b5a17a7..47de997 100644 --- a/tests/testIndividualAccountRequest.js +++ b/tests/testIndividualAccountRequest.js @@ -17,6 +17,28 @@ describe("TestIndividualAccountRequestPost", function() { }); }); +describe("TestIndividualAccountRequestAddressObject", function() { + this.timeout(10000); + it("test_address_is_nested_object", async () => { + let example = generateExampleIndividualAccountRequest(); + let request = new starkinfra.IndividualAccountRequest(example); + + assert(typeof request.address === "object" && request.address !== null); + assert(typeof request.address !== "string"); + + assert(request.address.street === "Rua do Estilo Barroco"); + assert(request.address.number === "648"); + assert(request.address.neighborhood === "Santo Amaro"); + assert(request.address.city === "Sao Paulo"); + assert(request.address.state === "SP"); + assert(request.address.zipCode === "05724005"); + + assert(request.addressStreet === undefined); + assert(request.addressCity === undefined); + assert(request.addressZipCode === undefined); + }); +}); + describe("TestIndividualAccountRequestGet", function() { this.timeout(10000); it("test_success", async () => { @@ -123,10 +145,146 @@ describe("TestIndividualAccountRequestPatch", function () { for await (let request of requests) { assert(typeof request.id == "string"); const updatedRequest = await starkinfra.individualAccountRequest.update(request.id, patchData); - - for (let key in patchData) { - assert(updatedRequest[key] === patchData[key]); - } + assert(updatedRequest.address.street === patchData.address.street); + assert(updatedRequest.address.zipCode === patchData.address.zipCode); + assert(updatedRequest.name === patchData.name); + } + }); +}); + +describe("TestIndividualAccountRequestStatusEnum", function () { + this.timeout(10000); + it("test_success", async () => { + const allowed = ["approved", "created", "denied", "processing", "updated"]; + const requests = await starkinfra.individualAccountRequest.query({ limit: 10 }); + for await (let request of requests) { + assert(allowed.includes(request.status)); + } + }); +}); + +describe("TestIndividualAccountRequestDatetimeParsing", function () { + this.timeout(10000); + it("test_success", async () => { + const requests = await starkinfra.individualAccountRequest.query({ limit: 1 }); + for await (let request of requests) { + assert(typeof request.created === 'string'); + assert(typeof request.updated === 'string'); + } + }); +}); + +describe("TestIndividualAccountRequestOutputOnlyFields", function () { + this.timeout(10000); + it("test_success", async () => { + let example = generateExampleIndividualAccountRequest(); + example.id = "5189530608992256"; + example.status = "processing"; + example.accountType = "individual"; + let request = new starkinfra.IndividualAccountRequest(example); + assert(request.id === "5189530608992256"); + assert(request.status === "processing"); + assert(request.accountType === "individual"); + }); +}); + +describe("TestIndividualAccountRequestInvalidName", function () { + this.timeout(10000); + it("test_invalid_name", async () => { + let ok = false; + let example = generateExampleIndividualAccountRequest(); + example.name = ""; + try { + await starkinfra.individualAccountRequest.create([new starkinfra.IndividualAccountRequest(example)]); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountRequestInvalidTaxId", function () { + this.timeout(10000); + it("test_invalid_tax_id", async () => { + let ok = false; + let example = generateExampleIndividualAccountRequest(); + example.taxId = "000.000.000-00"; + try { + await starkinfra.individualAccountRequest.create([new starkinfra.IndividualAccountRequest(example)]); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountRequestInvalidAddress", function () { + this.timeout(10000); + it("test_invalid_address", async () => { + let ok = false; + let example = generateExampleIndividualAccountRequest(); + example.address = { street: "Rua do Estilo Barroco" }; + try { + await starkinfra.individualAccountRequest.create([new starkinfra.IndividualAccountRequest(example)]); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountRequestInvalidIncome", function () { + this.timeout(10000); + it("test_invalid_income", async () => { + let ok = false; + let example = generateExampleIndividualAccountRequest(); + example.income = -1; + try { + await starkinfra.individualAccountRequest.create([new starkinfra.IndividualAccountRequest(example)]); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountRequestInvalidStatus", function () { + this.timeout(10000); + it("test_invalid_status", async () => { + let ok = false; + let request = (await starkinfra.individualAccountRequest.create([ + new starkinfra.IndividualAccountRequest(generateExampleIndividualAccountRequest()) + ]))[0]; + try { + await starkinfra.individualAccountRequest.update(request.id, {status: "not-a-real-status"}); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; + } + assert(ok); + }); +}); + +describe("TestIndividualAccountRequestNotFound", function () { + this.timeout(10000); + it("test_not_found", async () => { + let ok = false; + try { + await starkinfra.individualAccountRequest.get("0"); + } catch (e) { + if (!(e instanceof starkinfra.error.InputErrors)) + throw e; + ok = true; } + assert(ok); }); }); diff --git a/tests/testIndividualAccountRequestLog.js b/tests/testIndividualAccountRequestLog.js index cf4b672..1e93d46 100644 --- a/tests/testIndividualAccountRequestLog.js +++ b/tests/testIndividualAccountRequestLog.js @@ -13,7 +13,7 @@ describe('TestIndividualAccountRequestLogGet', function(){ assert(typeof log.id == 'string'); i += 1; } - assert(i > 1); + assert(i === 5); }); }); @@ -21,13 +21,24 @@ describe('TestIndividualAccountRequestLogGet', function(){ describe('TestIndividualAccountRequestLogInfoGet', function(){ this.timeout(10000); it('test_success', async () => { - let logs = await starkinfra.individualAccountRequest.log.query({ - 'limit': 1, + let logs = await starkinfra.individualAccountRequest.log.query({limit: 1}); + for await (let log of logs) { + assert(typeof log.id == 'string'); + log = await starkinfra.individualAccountRequest.log.get(log.id); + assert(typeof log.id == 'string'); + assert(typeof log.request === 'object' && log.request !== null); + } }); - - for await (let log of logs) { - console.log(log); - } +}); + +describe('TestIndividualAccountRequestLogTypeEnum', function(){ + this.timeout(10000); + it('test_success', async () => { + const allowed = ["approved", "created", "denied", "processing", "updated"]; + const logs = await starkinfra.individualAccountRequest.log.query({limit: 10}); + for await (let log of logs) { + assert(allowed.includes(log.type)); + } }); }); @@ -47,7 +58,7 @@ describe('TestIndividualAccountRequestLogGetPage', function () { break; } } - assert(ids.length > 1); + assert(ids.length === 10); }); }); @@ -59,7 +70,7 @@ describe('TestIndividualAccountRequestLogQueryParams', function(){ limit: 2, after: '2020-04-01', before: '2021-04-30', - types: 'denied', + types: 'created', accountRequestIds: ['1','2'], }); assert(requests.length===undefined) @@ -75,7 +86,7 @@ describe('TestIndividualAccountRequestLogPageParams', function(){ limit: 2, after: '2020-04-01', before: '2021-04-30', - types: 'denied', + types: 'created', accountRequestIds: ['1','2'], }); assert(requests.length===0) diff --git a/tests/utils/individualAccountAttachment.js b/tests/utils/individualAccountAttachment.js new file mode 100644 index 0000000..d596256 --- /dev/null +++ b/tests/utils/individualAccountAttachment.js @@ -0,0 +1,18 @@ +const fs = require('fs'); +const starkinfra = require('../../index.js'); + +const EXAMPLE_IMAGE_PATH = 'tests/utils/identity/identity-front-face.png'; + +exports.exampleImageContent = function () { + return fs.readFileSync(EXAMPLE_IMAGE_PATH); +}; + +exports.generateExampleIndividualAccountAttachment = function (accountRequestId) { + return { + type: "identity-front", + content: exports.exampleImageContent(), + contentType: "image/png", + accountRequestId: accountRequestId, + tags: ["attachment-test"] + }; +}; diff --git a/tests/utils/individualAccountRequest.js b/tests/utils/individualAccountRequest.js index ec4accb..31bbe6a 100644 --- a/tests/utils/individualAccountRequest.js +++ b/tests/utils/individualAccountRequest.js @@ -4,7 +4,14 @@ exports.generateExampleIndividualAccountRequest = function () { return { name: "John Doe", taxId: "012.345.678-90", - address: "R. pamplona, 123", + address: { + street: "Rua do Estilo Barroco", + number: "648", + neighborhood: "Santo Amaro", + city: "Sao Paulo", + state: "SP", + zipCode: "05724005" + }, income: 100000, tags: ["savings"] }; @@ -14,7 +21,14 @@ exports.generateExampleIndividualAccountRequestToUpdate = function () { return { name: "Tony Stark", taxId: "634.906.770-30", - address: "R. pamplona, 4321", + address: { + street: "Av. Faria Lima", + number: "4321", + neighborhood: "Itaim Bibi", + city: "Sao Paulo", + state: "SP", + zipCode: "04538133" + }, income: 50000 }; };