Skip to content

Commit

Permalink
feat: updade moysklad api, update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Dec 7, 2023
1 parent b9e8f61 commit e2991d8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moysklad-helpers",
"version": "3.2.1",
"version": "4.0.0",
"description": "Вспомогательные функции для работы с библиотекой moysklad",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down Expand Up @@ -32,15 +32,16 @@
},
"homepage": "https://github.com/wmakeev/moysklad-helpers#readme",
"devDependencies": {
"@types/tape": "^4.13.1",
"@types/node": "^20.10.3",
"@types/tape": "^5.6.4",
"auto-changelog": "^2.4.0",
"json": "^11.0.0",
"moysklad": "^0.10.0",
"prettier": "^2.3.2",
"tape": "^5.2.2",
"typescript": "^4.3.5"
"moysklad": "^0.16.0",
"prettier": "^3.1.0",
"tape": "^5.7.2",
"typescript": "^5.3.3"
},
"dependencies": {
"moysklad-api-model": "^0.5.6"
"moysklad-api-model": "^3.0.0"
}
}
17 changes: 10 additions & 7 deletions src/helpers/getHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,18 @@ export function getHelpers(ms: { buildUrl: (path: string) => string }) {
srcEntity: T,
fieldNames: Array<K>
) {
return fieldNames.reduce((res, fieldName) => {
const curFieldVal = srcEntity[fieldName]
return fieldNames.reduce(
(res, fieldName) => {
const curFieldVal = srcEntity[fieldName]

if (curFieldVal != null) {
res[fieldName] = curFieldVal
}
if (curFieldVal != null) {
res[fieldName] = curFieldVal
}

return res
}, {} as { [P in K]: T[P] })
return res
},
{} as { [P in K]: T[P] }
)
}

return {
Expand Down
16 changes: 8 additions & 8 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Moysklad from 'moysklad'
import { EntityRef, getHelpers } from '../src'
import { noop } from './tools'

const ENDPOINT = 'https://online.moysklad.ru/api/remap/1.2'
const ENDPOINT = 'https://api.moysklad.ru/api/remap/1.2'

test('href', t => {
const ms = Moysklad({ apiVersion: '1.2' })
Expand All @@ -22,11 +22,11 @@ test('href', t => {
}
} as EntityRef<'attributemetadata'>

const h1: 'https://online.moysklad.ru/api/remap/1.2/entity/customerorder/metadata/attributes/39f9f7bc-d4da-11e4-95df-0cc47a05161a' =
const h1: 'https://api.moysklad.ru/api/remap/1.2/entity/customerorder/metadata/attributes/39f9f7bc-d4da-11e4-95df-0cc47a05161a' =
href(href1)
t.equal(h1, href1, 'should return href for href')

const h2: `https://online.moysklad.ru/api/remap/${string}/entity/customerorder/metadata/attributes/39f9f7bc-d4da-11e4-95df-0cc47a05161a` =
const h2: `https://api.moysklad.ru/api/remap/${string}/entity/customerorder/metadata/attributes/39f9f7bc-d4da-11e4-95df-0cc47a05161a` =
href(ref1)
t.equal(h2, href1, 'should return href for ref')

Expand All @@ -39,8 +39,8 @@ test('href', t => {
h3_2

t.equal(
href('https://online.moysklad.ru/api/remap/1.1/entity/customerorder'),
'https://online.moysklad.ru/api/remap/1.2/entity/customerorder',
href('https://api.moysklad.ru/api/remap/1.1/entity/customerorder'),
'https://api.moysklad.ru/api/remap/1.2/entity/customerorder',
'should rebuild url with other api version'
)

Expand All @@ -52,13 +52,13 @@ test('href', t => {

const h6Ref = 'entity/customerorder' as 'entity/customerorder' | null
const h6:
| `https://online.moysklad.ru/api/remap/${string}/entity/customerorder`
| `https://api.moysklad.ru/api/remap/${string}/entity/customerorder`
| null = href(h6Ref)
h6

const h7Ref = 'entity/customerorder' as 'entity/customerorder' | undefined
const h7:
| `https://online.moysklad.ru/api/remap/${string}/entity/customerorder`
| `https://api.moysklad.ru/api/remap/${string}/entity/customerorder`
| undefined = href(h7Ref)
h7

Expand Down Expand Up @@ -296,7 +296,7 @@ test('positionRef', t => {

const ref1 = 'entity/customerorder/39f9f7bc-d4da-11e4-95df-0cc47a05161a'

const posHref1: `https://online.moysklad.ru/api/remap/${string}/entity/customerorder/39f9f7bc-d4da-11e4-95df-0cc47a05161a/positions/39f9f7bc-d4da-11e4-95df-0cc47a051618` =
const posHref1: `https://api.moysklad.ru/api/remap/${string}/entity/customerorder/39f9f7bc-d4da-11e4-95df-0cc47a05161a/positions/39f9f7bc-d4da-11e4-95df-0cc47a051618` =
href(`${ref1}/positions/${posId}`)

const positionRef1: EntityRef<'customerorderposition'> = ref(posHref1)
Expand Down
4 changes: 2 additions & 2 deletions tests/types/HrefMetaType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const t10: HrefMetaType<'entity/demand/metadata/attributes/123-456'> =
// never
const e11: HrefMetaType<'entity/demand/metadata/attributes3/123-456'> = 'demand'

const t12: HrefMetaType<'https://online.moysklad.ru/api/remap/1.2/entity/demand/metadata/attributes/123-456'> =
const t12: HrefMetaType<'https://api.moysklad.ru/api/remap/1.2/entity/demand/metadata/attributes/123-456'> =
'attributemetadata'

// @ts-expect-error
// never
const e12: HrefMetaType<'https://online.moysklad.ru/FOO/remap/1.2/entity/demand/metadata/attributes/123-456'> =
const e12: HrefMetaType<'https://api.moysklad.ru/FOO/remap/1.2/entity/demand/metadata/attributes/123-456'> =
'never'

const t20: HrefMetaType<'entity/invoiceout/metadata/states/123-456'> = 'state'
Expand Down
4 changes: 2 additions & 2 deletions tests/types/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { ref } = getHelpers(ms)
const t10: EntityRef<'customentity'> = ref('entity/customentity/123-456')

const t11: EntityRef<'customentity'> = ref(
'https://online.moysklad.ru/api/remap/1.2/entity/customentity/123-456'
'https://api.moysklad.ru/api/remap/1.2/entity/customentity/123-456'
)

// attributemetadata
Expand All @@ -22,7 +22,7 @@ const t20: EntityRef<'attributemetadata'> = ref(
)

const t21: EntityRef<'customentity'> = ref(
'https://online.moysklad.ru/api/remap/1.2/entity/customentity/123-456'
'https://api.moysklad.ru/api/remap/1.2/entity/customentity/123-456'
)

const account = {} as Account
Expand Down

0 comments on commit e2991d8

Please sign in to comment.