mirror of
https://github.com/we-promise/sure.git
synced 2026-05-11 14:45:01 +00:00
feat(api): accept Sure NDJSON imports (#1601)
* feat(api): accept Sure NDJSON imports * fix(api): preserve uploaded Sure imports on publish errors * fix(api): reset preserved Sure imports after enqueue failure * fix(api): tighten Sure import upload handling * test(api): align import API key fixtures * docs(api): document import publish failure IDs
This commit is contained in:
@@ -76,7 +76,7 @@ RSpec.describe 'API V1 Imports', type: :request do
|
||||
schema: { type: :string, enum: %w[pending complete importing reverting revert_failed failed] }
|
||||
parameter name: :type, in: :query, required: false,
|
||||
description: 'Filter by import type',
|
||||
schema: { type: :string, enum: %w[TransactionImport TradeImport AccountImport MintImport CategoryImport RuleImport] }
|
||||
schema: { type: :string, enum: %w[TransactionImport TradeImport AccountImport MintImport CategoryImport RuleImport SureImport] }
|
||||
|
||||
response '200', 'imports listed' do
|
||||
schema '$ref' => '#/components/schemas/ImportCollection'
|
||||
@@ -102,22 +102,22 @@ RSpec.describe 'API V1 Imports', type: :request do
|
||||
end
|
||||
|
||||
post 'Create import' do
|
||||
description 'Create a new import from raw CSV content.'
|
||||
description 'Create a new import from raw CSV content, inline Sure NDJSON content, or an uploaded Sure NDJSON file.'
|
||||
tags 'Imports'
|
||||
security [ { apiKeyAuth: [] } ]
|
||||
consumes 'application/json'
|
||||
consumes 'application/json', 'multipart/form-data'
|
||||
produces 'application/json'
|
||||
|
||||
parameter name: :body, in: :body, required: true, schema: {
|
||||
parameter name: :body, in: :body, required: false, schema: {
|
||||
type: :object,
|
||||
properties: {
|
||||
raw_file_content: {
|
||||
type: :string,
|
||||
description: 'The raw CSV content as a string'
|
||||
description: 'Raw CSV or Sure NDJSON content as a string. Required for SureImport unless a multipart file is uploaded.'
|
||||
},
|
||||
type: {
|
||||
type: :string,
|
||||
enum: %w[TransactionImport TradeImport AccountImport MintImport CategoryImport RuleImport],
|
||||
enum: %w[TransactionImport TradeImport AccountImport MintImport CategoryImport RuleImport SureImport],
|
||||
description: 'Import type (defaults to TransactionImport)'
|
||||
},
|
||||
account_id: {
|
||||
@@ -131,46 +131,83 @@ RSpec.describe 'API V1 Imports', type: :request do
|
||||
},
|
||||
date_col_label: {
|
||||
type: :string,
|
||||
description: 'Header name for the date column'
|
||||
description: 'CSV imports only. Header name for the date column'
|
||||
},
|
||||
amount_col_label: {
|
||||
type: :string,
|
||||
description: 'Header name for the amount column'
|
||||
description: 'CSV imports only. Header name for the amount column'
|
||||
},
|
||||
name_col_label: {
|
||||
type: :string,
|
||||
description: 'Header name for the transaction name column'
|
||||
description: 'CSV imports only. Header name for the transaction name column'
|
||||
},
|
||||
category_col_label: {
|
||||
type: :string,
|
||||
description: 'Header name for the category column'
|
||||
description: 'CSV imports only. Header name for the category column'
|
||||
},
|
||||
tags_col_label: {
|
||||
type: :string,
|
||||
description: 'Header name for the tags column'
|
||||
description: 'CSV imports only. Header name for the tags column'
|
||||
},
|
||||
notes_col_label: {
|
||||
type: :string,
|
||||
description: 'Header name for the notes column'
|
||||
description: 'CSV imports only. Header name for the notes column'
|
||||
},
|
||||
account_col_label: {
|
||||
type: :string,
|
||||
description: 'CSV imports only. Header name for the account column when importing rows across multiple accounts'
|
||||
},
|
||||
qty_col_label: {
|
||||
type: :string,
|
||||
description: 'CSV trade imports only. Header name for the quantity column'
|
||||
},
|
||||
ticker_col_label: {
|
||||
type: :string,
|
||||
description: 'CSV trade imports only. Header name for the ticker column'
|
||||
},
|
||||
price_col_label: {
|
||||
type: :string,
|
||||
description: 'CSV trade imports only. Header name for the price column'
|
||||
},
|
||||
entity_type_col_label: {
|
||||
type: :string,
|
||||
description: 'CSV imports only. Header name for the entity type column'
|
||||
},
|
||||
currency_col_label: {
|
||||
type: :string,
|
||||
description: 'CSV imports only. Header name for the currency column'
|
||||
},
|
||||
exchange_operating_mic_col_label: {
|
||||
type: :string,
|
||||
description: 'CSV trade imports only. Header name for the exchange operating MIC column'
|
||||
},
|
||||
date_format: {
|
||||
type: :string,
|
||||
description: 'Date format pattern (e.g., "%m/%d/%Y")'
|
||||
description: 'CSV imports only. Date format pattern (e.g., "%m/%d/%Y")'
|
||||
},
|
||||
number_format: {
|
||||
type: :string,
|
||||
enum: [ '1,234.56', '1.234,56', '1 234,56', '1,234' ],
|
||||
description: 'Number format for parsing amounts'
|
||||
description: 'CSV imports only. Number format for parsing amounts'
|
||||
},
|
||||
signage_convention: {
|
||||
type: :string,
|
||||
enum: %w[inflows_positive inflows_negative],
|
||||
description: 'How to interpret positive/negative amounts'
|
||||
description: 'CSV imports only. How to interpret positive/negative amounts'
|
||||
},
|
||||
col_sep: {
|
||||
type: :string,
|
||||
enum: [ ',', ';' ],
|
||||
description: 'Column separator'
|
||||
description: 'CSV imports only. Column separator'
|
||||
},
|
||||
amount_type_strategy: {
|
||||
type: :string,
|
||||
enum: %w[signed_amount custom_column],
|
||||
description: 'CSV imports only. Amount parsing strategy'
|
||||
},
|
||||
amount_type_inflow_value: {
|
||||
type: :string,
|
||||
description: 'CSV imports only. Column value that marks an amount as an inflow when using custom_column strategy'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,7 +230,10 @@ RSpec.describe 'API V1 Imports', type: :request do
|
||||
end
|
||||
|
||||
response '422', 'validation error - file too large' do
|
||||
schema '$ref' => '#/components/schemas/ErrorResponse'
|
||||
schema oneOf: [
|
||||
{ '$ref' => '#/components/schemas/ErrorResponse' },
|
||||
{ '$ref' => '#/components/schemas/ErrorResponseWithImportId' }
|
||||
]
|
||||
|
||||
let(:body) do
|
||||
{
|
||||
@@ -204,6 +244,20 @@ RSpec.describe 'API V1 Imports', type: :request do
|
||||
|
||||
run_test!
|
||||
end
|
||||
|
||||
response '500', 'import uploaded but publish enqueue failed' do
|
||||
schema '$ref' => '#/components/schemas/ErrorResponseWithImportId'
|
||||
|
||||
let(:body) do
|
||||
{
|
||||
raw_file_content: { type: 'Account', data: { id: 'account_1', name: 'Checking' } }.to_json,
|
||||
type: 'SureImport',
|
||||
publish: 'true'
|
||||
}
|
||||
end
|
||||
|
||||
run_test!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user