Skip to content

Commit

Permalink
migration described
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-id committed Feb 27, 2024
1 parent f4f5442 commit 154ee42
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,20 @@ changes in database.
`logout(): Promise<void>`

Logout (method: Wyloguj)

## Migrating from version 1.x, 2.x to 3.x

Please note that starting from version 3.0 of that library the following
breaking changes were introduced:

1. the module is now pure ESM module (previously CJS)
2. the keys and values are returned as is (previously they were processed)

- the keys are left intact (previously they were lowercased and a bit
trimmed)
- the empty values are now returned as empty strings (previously they were
returned as `undefined`)

See further details in the source code of [legacy](src/normalize.ts)
normalize function. This function can be used to preserve the old behavior as
shown in the [example](examples/legacy.js).
10 changes: 6 additions & 4 deletions examples/basic.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Bir from 'bir1'

// In order to get up to date data from production environment, you need to
// provide your own key. Ask for it at https://api.stat.gov.pl/Home/RegonApi
// This sample will work also without that key, but it will return old
// non-updated data.
/**
* In order to get up to date data from production environment, you need to
* provide your own key. Ask for it at https://api.stat.gov.pl/Home/RegonApi
* This sample will work also without that key, but it will return old
* non-updated data.
*/

const bir = new Bir({ key: process.env.KEY })
console.log('StanDanych: ', await bir.value('StanDanych'))
Expand Down
22 changes: 19 additions & 3 deletions examples/legacy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import Bir from 'bir1'
import { legacy } from 'bir1/normalize'

// In previous version of that library (1.0 - 2.0), there was some preprocessing
// applied to keys. This is no longer needed, but if you want to use old
// approach, you can use legacy normalize function from `bir1/normalize` module.
/**
* In previous version of that library (1.x, 2.x), there was some preprocessing
* applied to keys and values. This is no longer needed, but if you want to use
* old approach, you can use legacy normalize function from `bir1/normalize`.
*
* The implementation of legacy normalize function best describes previous
* approach. See the source code of file://src/normalize.ts for details.
*/

// legacy approach (some preprocessing)
const birLegacy = new Bir({ normalizeFn: legacy })
await birLegacy.login()
console.log(
Expand All @@ -13,3 +19,13 @@ console.log(
report: 'BIR11OsPrawna',
})
)

// new approach (no preprocessing)
const birCurrent = new Bir()
await birCurrent.login()
console.log(
await birCurrent.report({
regon: '011417295',
report: 'BIR11OsPrawna',
})
)

0 comments on commit 154ee42

Please sign in to comment.