Skip to content

Commit

Permalink
fix: deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Oct 15, 2023
1 parent 82a90ee commit 780727b
Show file tree
Hide file tree
Showing 9 changed files with 1,203 additions and 1,386 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
NODE_OPTIONS: '--max-old-space-size=3200'
CC_TEST_REPORTER_ID: 2420941f712b3f0a35c2225ac757fad68076cc107e256a57b7bd6a3bb5a481ac
steps:
- { uses: actions/checkout@v3, with: { persist-credentials: false } }
- { uses: actions/checkout@v4, with: { persist-credentials: false } }
- { uses: actions/setup-node@v3, with: { node-version: 18, cache: 'yarn' } }
- { name: yarn, run: yarn --frozen-lockfile }

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
env: { NODE_OPTIONS: '--max-old-space-size=3200' }
steps:
- { uses: actions/checkout@v3, with: { persist-credentials: true } }
- { uses: actions/checkout@v4, with: { persist-credentials: true } }
- { uses: actions/setup-node@v3, with: { node-version: 18, cache: 'yarn' } }

# Cache for npm/npx in ~/.npm
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@naturalcycles/js-lib": "^14.55.0",
"nanoid": "^3.1.12"
"@naturalcycles/nodejs-lib": "^13.1.4"
},
"devDependencies": {
"@naturalcycles/dev-lib": "^13.14.2",
Expand Down
57 changes: 3 additions & 54 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
import { Scrubber } from './scrubber'
import { ScrubberConfig } from './scrubber.model'
import { undefinedScrubber, UndefinedScrubberFn } from './scrubbers'
import { preserveOriginalScrubber, PreserveOriginalScrubberFn } from './scrubbers'
import { staticScrubber, StaticScrubberFn, StaticScrubberParams } from './scrubbers'
import {
isoDateStringScrubber,
ISODateStringScrubberFn,
ISODateStringScrubberParams,
} from './scrubbers'
import {
unixTimestampScrubber,
UnixTimestampScrubberFn,
UnixTimestampScrubberParams,
} from './scrubbers'
import {
charsFromRightScrubber,
CharsFromRightScrubberFn,
CharsFromRightScrubberParams,
} from './scrubbers'
import { randomScrubber, RandomScrubberFn, RandomScrubberParams } from './scrubbers'
import { randomEmailScrubber, RandomEmailScrubberFn, RandomEmailScrubberParams } from './scrubbers'
import { saltedHashScrubber, SaltedHashScrubberFn, SaltedHashScrubberParams } from './scrubbers'

export type {
ScrubberConfig,
UndefinedScrubberFn,
PreserveOriginalScrubberFn,
StaticScrubberParams,
StaticScrubberFn,
UnixTimestampScrubberFn,
UnixTimestampScrubberParams,
ISODateStringScrubberFn,
ISODateStringScrubberParams,
CharsFromRightScrubberFn,
CharsFromRightScrubberParams,
RandomScrubberFn,
RandomScrubberParams,
RandomEmailScrubberFn,
RandomEmailScrubberParams,
SaltedHashScrubberFn,
SaltedHashScrubberParams,
}

export { Scrubber }
export { undefinedScrubber }
export { preserveOriginalScrubber }
export { staticScrubber }
export { unixTimestampScrubber }
export { isoDateStringScrubber }
export { charsFromRightScrubber }
export { randomScrubber }
export { randomEmailScrubber }
export { saltedHashScrubber }
export * from './scrubber'
export * from './scrubber.model'
export * from './scrubbers'
20 changes: 10 additions & 10 deletions src/scrubber.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nanoid } from 'nanoid'
import { deepFreeze } from '@naturalcycles/dev-lib/dist/testing'
import { _deepFreeze } from '@naturalcycles/js-lib'
import { nanoid } from '@naturalcycles/nodejs-lib'
import { Scrubber } from './scrubber'
import { ScrubberConfig, ScrubberFn, ScrubbersMap } from './scrubber.model'
import { saltedHashEmailScrubber, saltedHashScrubber } from './scrubbers'
Expand Down Expand Up @@ -36,22 +36,22 @@ test('returns an array with one object when input is an array with one object',

test('applies to more than a field', () => {
const data = [{ pw: 'secret', name: 'Real Name' }]
deepFreeze(data) // Ensure data doesnt mutate
_deepFreeze(data) // Ensure data doesnt mutate
const result = scrub(data)
expect(result).toEqual([{ pw: 'notsecret', name: 'Jane Doe' }])
})

test('applies to nested fields (deep transverse, 2 levels)', () => {
const data = [{ account: { pw: 'secret', name: 'Real Name' } }]
deepFreeze(data) // Ensure data doesnt mutate
_deepFreeze(data) // Ensure data doesnt mutate

const result = scrub(data)
expect(result).toEqual([{ account: { pw: 'notsecret', name: 'Jane Doe' } }])
})

test('applies to nested fields (deep transverse, 3 levels)', () => {
const data = [{ object: { account: { pw: 'secret', name: 'Real Name' } } }]
deepFreeze(data) // Ensure data doesnt mutate
_deepFreeze(data) // Ensure data doesnt mutate

const result = scrub(data)
expect(result).toEqual([{ object: { account: { pw: 'notsecret', name: 'Jane Doe' } } }])
Expand All @@ -61,7 +61,7 @@ test('applies to nested arrays', () => {
const obj1 = { pw: 'shouldChange', safe: 'shouldStay' }
const obj2 = { name: 'personalInformation', safe2: 'isSafe' }
const users = [{ users: [obj1, obj2] }]
deepFreeze(users)
_deepFreeze(users)

const result = scrub(users)
expect(result[0]!['users'][0]).toEqual({ pw: 'notsecret', safe: 'shouldStay' })
Expand All @@ -71,7 +71,7 @@ test('applies to nested arrays', () => {

test('keeps not modified fields', () => {
const data = [{ safeField: 'keep', email: '[email protected]' }]
deepFreeze(data) // Ensure data doesnt mutate
_deepFreeze(data) // Ensure data doesnt mutate

const result = scrub(data, configEmailScrubberMock())
expect(result).toEqual([{ safeField: 'keep', email: '[email protected]' }])
Expand All @@ -90,15 +90,15 @@ test('supports additional scrubbers', () => {
}

const data = [{ target: 'original' }]
deepFreeze(data) // Ensure data doesnt mutate
_deepFreeze(data) // Ensure data doesnt mutate

const result = scrub(data, cfg, additionalScrubbers)
expect(result).toEqual([{ target: 'modified' }])
})

test('supports comma-separated fields in field name', () => {
const data = [{ field1: 'orig1', field2: 'orig2' }]
deepFreeze(data) // Ensure data doesnt mutate
_deepFreeze(data) // Ensure data doesnt mutate

const result = scrub(data, configMultiFieldMock())
expect(result).toEqual([{ field1: 'modified', field2: 'modified' }])
Expand Down Expand Up @@ -216,7 +216,7 @@ test('initializationVector is passed as param to scrubbers', () => {
}

const data = [{ pw: 'secret' }]
deepFreeze(data) // Ensure data doesnt mutate
_deepFreeze(data) // Ensure data doesnt mutate

const scrubber = new Scrubber(cfg, additionalScrubbers)
scrubber.scrub(data)
Expand Down
2 changes: 1 addition & 1 deletion src/scrubber.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nanoid } from 'nanoid'
import { _assert, _deepEquals, StringMap } from '@naturalcycles/js-lib'
import { nanoid } from '@naturalcycles/nodejs-lib'
import { ScrubberConfig, ScrubbersMap, ScrubbersSQLMap } from './scrubber.model'
import { defaultScrubbers, defaultScrubbersSQL } from './scrubbers'

Expand Down
2 changes: 1 addition & 1 deletion src/scrubbers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nanoid } from 'nanoid'
import { nanoid } from '@naturalcycles/nodejs-lib'
import {
bcryptStringScrubber,
bcryptStringScrubberSQL,
Expand Down
10 changes: 5 additions & 5 deletions src/scrubbers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as crypto from 'node:crypto'
import { _assert } from '@naturalcycles/js-lib'
import { customAlphabet } from 'nanoid'
import { nanoIdCustomAlphabet } from '@naturalcycles/nodejs-lib'
import { ScrubberFn, ScrubbersMap, ScrubberSQLFn, ScrubbersSQLMap } from './scrubber.model'

function encloseValueForSQL(value: string | number, type: string): string {
Expand Down Expand Up @@ -250,7 +250,7 @@ export type RandomScrubberSQLFn = ScrubberSQLFn<RandomScrubberParams>

export const randomScrubber: RandomScrubberFn = (value, additionalParams) => {
const params = { alphabet: ALPHABET_ALPHANUMERIC_LOWERCASE, length: 16, ...additionalParams }
return customAlphabet(params.alphabet, params['length'])()
return nanoIdCustomAlphabet(params.alphabet, params['length'])()
}

export const randomScrubberSQL: RandomScrubberSQLFn = additionalParams => {
Expand Down Expand Up @@ -282,7 +282,7 @@ export const randomEmailScrubber: RandomEmailScrubberFn = (value, additionalPara
domain: '@example.com',
...additionalParams,
}
return customAlphabet(params.alphabet, params['length'])() + params.domain
return nanoIdCustomAlphabet(params.alphabet, params['length'])() + params.domain
}

export const randomEmailScrubberSQL: RandomEmailScrubberSQLFn = additionalParams => {
Expand Down Expand Up @@ -428,7 +428,7 @@ export const bcryptStringScrubber: BcryptStringScrubberFn = (value, params) => {

// Keep value until 3rd $
const cutoff = nthChar(value, '$', 3)
if (!cutoff) return `$2a$12$${customAlphabet(ALPHABET_ALPHANUMERIC_LOWERCASE, 53)()}`
if (!cutoff) return `$2a$12$${nanoIdCustomAlphabet(ALPHABET_ALPHANUMERIC_LOWERCASE, 53)()}`

const prefix = value.substring(0, cutoff)

Expand All @@ -439,7 +439,7 @@ export const bcryptStringScrubber: BcryptStringScrubberFn = (value, params) => {
}
}

return `${prefix}${customAlphabet(ALPHABET_ALPHANUMERIC_LOWERCASE, 53)()}`
return `${prefix}${nanoIdCustomAlphabet(ALPHABET_ALPHANUMERIC_LOWERCASE, 53)()}`
}
export const bcryptStringScrubberSQL: BcryptStringScrubberSQLFn = params => {
// to have at least one WHEN clause, so the ELSE clause is valid
Expand Down
Loading

0 comments on commit 780727b

Please sign in to comment.