@labdigital/commercetools-mock 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/index.cjs +117 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +117 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/constants.ts +2 -2
- package/src/ctMock.ts +176 -176
- package/src/exceptions.ts +10 -10
- package/src/helpers.ts +26 -26
- package/src/index.test.ts +173 -173
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +19 -19
- package/src/lib/haversine.test.ts +13 -13
- package/src/lib/haversine.ts +14 -14
- package/src/lib/masking.ts +15 -15
- package/src/lib/parser.ts +2 -2
- package/src/lib/predicateParser.test.ts +204 -204
- package/src/lib/predicateParser.ts +398 -398
- package/src/lib/projectionSearchFilter.test.ts +168 -168
- package/src/lib/projectionSearchFilter.ts +272 -269
- package/src/lib/proxy.ts +8 -8
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.ts +103 -101
- package/src/oauth/store.ts +27 -27
- package/src/priceSelector.test.ts +68 -68
- package/src/priceSelector.ts +70 -70
- package/src/product-projection-search.ts +296 -296
- package/src/projectAPI.test.ts +3 -3
- package/src/projectAPI.ts +46 -46
- package/src/repositories/abstract.ts +190 -190
- package/src/repositories/associate-role.ts +10 -7
- package/src/repositories/attribute-group.ts +63 -8
- package/src/repositories/business-unit.ts +10 -7
- package/src/repositories/cart-discount.ts +134 -134
- package/src/repositories/cart.ts +517 -514
- package/src/repositories/category.ts +170 -167
- package/src/repositories/channel.ts +114 -111
- package/src/repositories/custom-object.ts +66 -63
- package/src/repositories/customer-group.ts +72 -69
- package/src/repositories/customer.ts +90 -90
- package/src/repositories/discount-code.ts +171 -168
- package/src/repositories/errors.ts +15 -15
- package/src/repositories/extension.ts +79 -76
- package/src/repositories/helpers.ts +180 -180
- package/src/repositories/index.ts +39 -39
- package/src/repositories/inventory-entry.ts +98 -95
- package/src/repositories/my-order.ts +11 -11
- package/src/repositories/order-edit.ts +29 -29
- package/src/repositories/order.test.ts +191 -191
- package/src/repositories/order.ts +393 -393
- package/src/repositories/payment.ts +155 -155
- package/src/repositories/product-discount.ts +149 -149
- package/src/repositories/product-projection.ts +135 -50
- package/src/repositories/product-selection.ts +31 -31
- package/src/repositories/product-type.ts +156 -156
- package/src/repositories/product.ts +600 -597
- package/src/repositories/project.ts +136 -135
- package/src/repositories/quote-request.ts +19 -19
- package/src/repositories/quote.ts +19 -19
- package/src/repositories/review.ts +24 -24
- package/src/repositories/shipping-method.ts +217 -217
- package/src/repositories/shopping-list.ts +49 -49
- package/src/repositories/staged-quote.ts +20 -20
- package/src/repositories/standalone-price.ts +72 -61
- package/src/repositories/state.ts +84 -84
- package/src/repositories/store.ts +114 -114
- package/src/repositories/subscription.ts +40 -40
- package/src/repositories/tax-category.ts +98 -98
- package/src/repositories/type.ts +157 -157
- package/src/repositories/zone.ts +71 -71
- package/src/server.ts +2 -2
- package/src/services/abstract.ts +173 -173
- package/src/services/attribute-group.ts +16 -0
- package/src/services/cart-discount.ts +8 -8
- package/src/services/cart.test.ts +409 -409
- package/src/services/cart.ts +50 -50
- package/src/services/category.test.ts +25 -25
- package/src/services/category.ts +8 -8
- package/src/services/channel.ts +8 -8
- package/src/services/custom-object.test.ts +184 -184
- package/src/services/custom-object.ts +48 -48
- package/src/services/customer-group.ts +8 -8
- package/src/services/customer.test.ts +151 -151
- package/src/services/customer.ts +27 -27
- package/src/services/discount-code.ts +8 -8
- package/src/services/extension.ts +8 -8
- package/src/services/index.ts +52 -44
- package/src/services/inventory-entry.test.ts +162 -162
- package/src/services/inventory-entry.ts +8 -8
- package/src/services/my-cart.test.ts +78 -78
- package/src/services/my-cart.ts +28 -28
- package/src/services/my-customer.test.ts +44 -44
- package/src/services/my-customer.ts +53 -53
- package/src/services/my-order.ts +20 -20
- package/src/services/my-payment.test.ts +65 -65
- package/src/services/my-payment.ts +8 -8
- package/src/services/order.test.ts +527 -527
- package/src/services/order.ts +31 -31
- package/src/services/payment.test.ts +65 -65
- package/src/services/payment.ts +8 -8
- package/src/services/product-discount.ts +8 -8
- package/src/services/product-projection.test.ts +502 -428
- package/src/services/product-projection.ts +32 -18
- package/src/services/product-type.test.ts +56 -56
- package/src/services/product-type.ts +8 -8
- package/src/services/product.test.ts +510 -510
- package/src/services/product.ts +8 -8
- package/src/services/project.ts +34 -34
- package/src/services/shipping-method.test.ts +81 -81
- package/src/services/shipping-method.ts +12 -12
- package/src/services/shopping-list.ts +8 -8
- package/src/services/standalone-price.test.ts +256 -256
- package/src/services/standalone-price.ts +8 -8
- package/src/services/state.test.ts +42 -42
- package/src/services/state.ts +8 -8
- package/src/services/store.test.ts +57 -57
- package/src/services/store.ts +8 -8
- package/src/services/subscription.ts +8 -8
- package/src/services/tax-category.test.ts +61 -61
- package/src/services/tax-category.ts +8 -8
- package/src/services/type.ts +8 -8
- package/src/services/zone.ts +8 -8
- package/src/storage/abstract.ts +58 -58
- package/src/storage/in-memory.ts +419 -419
- package/src/types.ts +82 -82
package/src/index.test.ts
CHANGED
|
@@ -5,200 +5,200 @@ import nock from 'nock'
|
|
|
5
5
|
import got from 'got'
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
nock.disableNetConnect()
|
|
9
|
+
nock.enableNetConnect('127.0.0.1') // supertest
|
|
10
10
|
})
|
|
11
11
|
afterEach(() => {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
nock.enableNetConnect()
|
|
13
|
+
nock.cleanAll()
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
test('Default mock endpoints', async () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
17
|
+
const ctMock = new CommercetoolsMock({
|
|
18
|
+
enableAuthentication: true,
|
|
19
|
+
validateCredentials: true,
|
|
20
|
+
})
|
|
21
|
+
ctMock.start()
|
|
22
|
+
|
|
23
|
+
let response = await got.post<{ access_token: string }>(
|
|
24
|
+
'https://auth.europe-west1.gcp.commercetools.com/oauth/token',
|
|
25
|
+
{
|
|
26
|
+
searchParams: {
|
|
27
|
+
grant_type: 'client_credentials',
|
|
28
|
+
scope: 'manage_project:commercetools-node-mock',
|
|
29
|
+
},
|
|
30
|
+
username: 'foo',
|
|
31
|
+
password: 'bar',
|
|
32
|
+
responseType: 'json',
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
expect(response.statusCode).toBe(200)
|
|
36
|
+
|
|
37
|
+
const token = response.body.access_token
|
|
38
|
+
expect(response.body.access_token).toBeDefined()
|
|
39
|
+
response = await got.get(
|
|
40
|
+
'https://api.europe-west1.gcp.commercetools.com/my-project/orders',
|
|
41
|
+
{
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `Bearer ${token}`,
|
|
44
|
+
},
|
|
45
|
+
responseType: 'json',
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
expect(response.statusCode).toBe(200)
|
|
49
|
+
expect(response.body).toStrictEqual({
|
|
50
|
+
count: 0,
|
|
51
|
+
total: 0,
|
|
52
|
+
offset: 0,
|
|
53
|
+
limit: 20,
|
|
54
|
+
results: [],
|
|
55
|
+
})
|
|
56
|
+
ctMock.stop()
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
test('Options.validateCredentials: true (error)', async () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
60
|
+
const ctMock = new CommercetoolsMock({
|
|
61
|
+
enableAuthentication: true,
|
|
62
|
+
validateCredentials: true,
|
|
63
|
+
})
|
|
64
|
+
ctMock.start()
|
|
65
|
+
|
|
66
|
+
const response = await got.get<InvalidTokenError>(
|
|
67
|
+
'https://api.europe-west1.gcp.commercetools.com/my-project/orders',
|
|
68
|
+
{
|
|
69
|
+
headers: {
|
|
70
|
+
Authorization: `Bearer foobar`,
|
|
71
|
+
},
|
|
72
|
+
responseType: 'json',
|
|
73
|
+
throwHttpErrors: false,
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
expect(response.statusCode).toBe(401)
|
|
77
|
+
expect(response.body.message).toBe('invalid_token')
|
|
78
|
+
ctMock.stop()
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
test('Options.validateCredentials: false', async () => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
82
|
+
const ctMock = new CommercetoolsMock({
|
|
83
|
+
enableAuthentication: true,
|
|
84
|
+
validateCredentials: false,
|
|
85
|
+
})
|
|
86
|
+
ctMock.start()
|
|
87
|
+
|
|
88
|
+
const response = await got.get(
|
|
89
|
+
'https://api.europe-west1.gcp.commercetools.com/my-project/orders',
|
|
90
|
+
{
|
|
91
|
+
headers: {
|
|
92
|
+
Authorization: `Bearer foobar`,
|
|
93
|
+
},
|
|
94
|
+
responseType: 'json',
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
expect(response.statusCode).toBe(200)
|
|
98
|
+
expect(response.body).toStrictEqual({
|
|
99
|
+
count: 0,
|
|
100
|
+
total: 0,
|
|
101
|
+
offset: 0,
|
|
102
|
+
limit: 20,
|
|
103
|
+
results: [],
|
|
104
|
+
})
|
|
105
|
+
ctMock.stop()
|
|
106
106
|
})
|
|
107
107
|
|
|
108
108
|
test('Options.enableAuthentication: false', async () => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
109
|
+
const ctMock = new CommercetoolsMock({
|
|
110
|
+
enableAuthentication: false,
|
|
111
|
+
validateCredentials: false,
|
|
112
|
+
})
|
|
113
|
+
ctMock.start()
|
|
114
|
+
|
|
115
|
+
const response = await got.get(
|
|
116
|
+
'https://api.europe-west1.gcp.commercetools.com/my-project/orders',
|
|
117
|
+
{
|
|
118
|
+
responseType: 'json',
|
|
119
|
+
}
|
|
120
|
+
)
|
|
121
|
+
expect(response.statusCode).toBe(200)
|
|
122
|
+
expect(response.body).toStrictEqual({
|
|
123
|
+
count: 0,
|
|
124
|
+
total: 0,
|
|
125
|
+
offset: 0,
|
|
126
|
+
limit: 20,
|
|
127
|
+
results: [],
|
|
128
|
+
})
|
|
129
|
+
ctMock.stop()
|
|
130
130
|
})
|
|
131
131
|
|
|
132
132
|
test('Options.apiHost: is overridden is set', async () => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
133
|
+
const ctMock = new CommercetoolsMock({
|
|
134
|
+
enableAuthentication: false,
|
|
135
|
+
validateCredentials: false,
|
|
136
|
+
apiHost: 'http://api.localhost',
|
|
137
|
+
})
|
|
138
|
+
ctMock.start()
|
|
139
|
+
|
|
140
|
+
const response = await got.get('http://api.localhost/my-project/orders', {
|
|
141
|
+
responseType: 'json',
|
|
142
|
+
})
|
|
143
|
+
expect(response.statusCode).toBe(200)
|
|
144
|
+
expect(response.body).toStrictEqual({
|
|
145
|
+
count: 0,
|
|
146
|
+
total: 0,
|
|
147
|
+
offset: 0,
|
|
148
|
+
limit: 20,
|
|
149
|
+
results: [],
|
|
150
|
+
})
|
|
151
|
+
ctMock.stop()
|
|
152
152
|
})
|
|
153
153
|
|
|
154
154
|
test('Options.authHost: is set', async () => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
155
|
+
const ctMock = new CommercetoolsMock({
|
|
156
|
+
enableAuthentication: true,
|
|
157
|
+
validateCredentials: true,
|
|
158
|
+
authHost: 'http://auth.localhost',
|
|
159
|
+
})
|
|
160
|
+
ctMock.start()
|
|
161
|
+
|
|
162
|
+
const response = await got.post<{ access_token: string }>(
|
|
163
|
+
'http://auth.localhost/oauth/token',
|
|
164
|
+
{
|
|
165
|
+
searchParams: {
|
|
166
|
+
grant_type: 'client_credentials',
|
|
167
|
+
scope: 'manage_project:commercetools-node-mock',
|
|
168
|
+
},
|
|
169
|
+
username: 'foo',
|
|
170
|
+
password: 'bar',
|
|
171
|
+
responseType: 'json',
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
expect(response.statusCode).toBe(200)
|
|
175
|
+
|
|
176
|
+
const token = response.body.access_token
|
|
177
|
+
expect(token).toBeDefined()
|
|
178
178
|
})
|
|
179
179
|
|
|
180
180
|
test('apiHost mock proxy: querystring', async () => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
181
|
+
const ctMock = new CommercetoolsMock({
|
|
182
|
+
enableAuthentication: false,
|
|
183
|
+
validateCredentials: false,
|
|
184
|
+
apiHost: 'http://api.localhost',
|
|
185
|
+
})
|
|
186
|
+
ctMock.start()
|
|
187
|
+
|
|
188
|
+
const response = await got.get('http://api.localhost/my-project/orders', {
|
|
189
|
+
responseType: 'json',
|
|
190
|
+
searchParams: {
|
|
191
|
+
where: 'orderNumber="foobar"',
|
|
192
|
+
expand: 'custom.type',
|
|
193
|
+
},
|
|
194
|
+
})
|
|
195
|
+
expect(response.statusCode).toBe(200)
|
|
196
|
+
expect(response.body).toStrictEqual({
|
|
197
|
+
count: 0,
|
|
198
|
+
total: 0,
|
|
199
|
+
offset: 0,
|
|
200
|
+
limit: 20,
|
|
201
|
+
results: [],
|
|
202
|
+
})
|
|
203
|
+
ctMock.stop()
|
|
204
204
|
})
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CommercetoolsMock, CommercetoolsMockOptions } from './ctMock.js'
|
|
|
2
2
|
import { getBaseResourceProperties } from './helpers.js'
|
|
3
3
|
|
|
4
4
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
CommercetoolsMock,
|
|
6
|
+
getBaseResourceProperties,
|
|
7
|
+
type CommercetoolsMockOptions,
|
|
8
8
|
}
|
package/src/lib/expandParser.ts
CHANGED
|
@@ -7,28 +7,28 @@
|
|
|
7
7
|
* TODO: implement support for multi-dimensional array
|
|
8
8
|
*/
|
|
9
9
|
type ExpandResult = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
element: string
|
|
11
|
+
index?: string | number
|
|
12
|
+
rest?: string
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export const parseExpandClause = (clause: string): ExpandResult => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const result: ExpandResult = {
|
|
17
|
+
element: clause,
|
|
18
|
+
index: undefined,
|
|
19
|
+
rest: undefined,
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const pos = clause.indexOf('.')
|
|
23
|
+
if (pos > 0) {
|
|
24
|
+
result.element = clause.substring(0, pos)
|
|
25
|
+
result.rest = clause.substring(pos + 1)
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const match = result.element.match(/\[([^\]+])]/)
|
|
29
|
+
if (match) {
|
|
30
|
+
result.index = match[1] === '*' ? '*' : parseInt(match[1], 10)
|
|
31
|
+
result.element = result.element.substring(0, match.index)
|
|
32
|
+
}
|
|
33
|
+
return result
|
|
34
34
|
}
|
|
@@ -2,19 +2,19 @@ import { expect, test } from 'vitest'
|
|
|
2
2
|
import { haversineDistance, Location } from './haversine.js'
|
|
3
3
|
|
|
4
4
|
test('haversine', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
// Lab Digital
|
|
6
|
+
const src: Location = {
|
|
7
|
+
latitude: 5.110230209615395,
|
|
8
|
+
longitude: 52.06969591642097,
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
// Dom Tower
|
|
12
|
+
const dst: Location = {
|
|
13
|
+
latitude: 5.121310867198959,
|
|
14
|
+
longitude: 52.09068804569714,
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const dist = haversineDistance(src, dst)
|
|
18
|
+
expect(dist).toBeGreaterThan(2631)
|
|
19
|
+
expect(dist).toBeLessThan(2632)
|
|
20
20
|
})
|
package/src/lib/haversine.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export type Location = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
latitude: number
|
|
3
|
+
longitude: number
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns the distance between src and dst as meters
|
|
8
8
|
*/
|
|
9
9
|
export const haversineDistance = (src: Location, dst: Location) => {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const RADIUS_OF_EARTH_IN_KM = 6371
|
|
11
|
+
const toRadian = (deg: number) => deg * (Math.PI / 180)
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const dLat = toRadian(dst.latitude - src.latitude)
|
|
14
|
+
const dLon = toRadian(dst.longitude - src.longitude)
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
const a =
|
|
17
|
+
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
18
|
+
Math.cos(toRadian(src.latitude)) *
|
|
19
|
+
Math.cos(toRadian(dst.latitude)) *
|
|
20
|
+
Math.sin(dLon / 2) *
|
|
21
|
+
Math.sin(dLon / 2)
|
|
22
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
23
|
+
return RADIUS_OF_EARTH_IN_KM * c * 1000
|
|
24
24
|
}
|
package/src/lib/masking.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { cloneObject } from '../helpers.js'
|
|
2
2
|
|
|
3
3
|
export const maskSecretValue = <T>(resource: T, path: string): T => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const parts = path.split('.')
|
|
5
|
+
const clone = cloneObject(resource) as any
|
|
6
|
+
let val = clone
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const target = parts.pop()
|
|
9
|
+
for (let i = 0; i < parts.length; i++) {
|
|
10
|
+
const part = parts[i]
|
|
11
|
+
val = val[part]
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if (val === undefined) {
|
|
14
|
+
return resource
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
if (val && target && val[target]) {
|
|
19
|
+
val[target] = '****'
|
|
20
|
+
}
|
|
21
|
+
return clone
|
|
22
22
|
}
|
package/src/lib/parser.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Lexer } from '~vendor/perplex/lexer.js'
|
|
2
|
-
export { Parser, type ITokenPosition } from '~vendor/pratt/index.js'
|
|
1
|
+
export { Lexer } from '~vendor/perplex/lexer.js'
|
|
2
|
+
export { Parser, type ITokenPosition } from '~vendor/pratt/index.js'
|