@@ -101,6 +101,8 @@ import {
101
101
DeleteRequest ,
102
102
Filter_ValueType ,
103
103
ReadRequest ,
104
+ Resource ,
105
+ ResourceResponse ,
104
106
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/resource_base.js' ;
105
107
import {
106
108
OperationStatus ,
@@ -118,61 +120,7 @@ import {
118
120
VAT
119
121
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/amount.js' ;
120
122
import { Subject } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth.js' ;
121
-
122
- export type BigVAT = {
123
- tax_id : string ;
124
- vat : BigNumber ;
125
- } ;
126
-
127
- export type BigAmount = {
128
- currency_id : string ;
129
- gross : BigNumber ;
130
- net : BigNumber ;
131
- vats : VAT [ ] ;
132
- } ;
133
-
134
- export type RatioedTax = Tax & {
135
- tax_ratio ?: number ;
136
- } ;
137
-
138
- export const toObjectMap = < T extends object > ( items : any [ ] ) => items . reduce (
139
- ( a , b ) => {
140
- a [ b . id ?? b . payload ?. id ] = b ;
141
- return a ;
142
- } ,
143
- { } as T
144
- ) ?? { } ;
145
-
146
- export type OrderMap = { [ key : string ] : OrderResponse } ;
147
- export type ProductMap = { [ key : string ] : ProductResponse } ;
148
- export type FulfillmentMap = { [ key : string ] : FulfillmentResponse [ ] } ;
149
- export type RatioedTaxMap = { [ key : string ] : RatioedTax } ;
150
- export type CustomerMap = { [ key : string ] : CustomerResponse } ;
151
- export type CurrencyMap = { [ key : string ] : CurrencyResponse } ;
152
- export type ShopMap = { [ key : string ] : ShopResponse } ;
153
- export type OrganizationMap = { [ key : string ] : OrganizationResponse } ;
154
- export type ContactPointMap = { [ key : string ] : ContactPointResponse } ;
155
- export type AddressMap = { [ key : string ] : AddressResponse } ;
156
- export type CountryMap = { [ key : string ] : CountryResponse } ;
157
- export type FulfillmentSolutionMap = { [ key : string ] : FulfillmentSolutionResponse } ;
158
- export type PositionMap = { [ key : string ] : Position } ;
159
- export type StatusMap = { [ key : string ] : Status } ;
160
- export type OperationStatusMap = { [ key : string ] : OperationStatus } ;
161
- export type VATMap = { [ key : string ] : VAT } ;
162
- export type ProductNature = PhysicalProduct & VirtualProduct & ServiceProduct ;
163
- export type ProductVariant = PhysicalVariant & VirtualVariant & ServiceVariant ;
164
- export type CRUDClient = Client < ProductServiceDefinition >
165
- | Client < TaxServiceDefinition >
166
- | Client < CustomerServiceDefinition >
167
- | Client < ShopServiceDefinition >
168
- | Client < OrganizationServiceDefinition >
169
- | Client < ContactPointServiceDefinition >
170
- | Client < AddressServiceDefinition >
171
- | Client < CountryServiceDefinition >
172
- | Client < FulfillmentServiceDefinition >
173
- | Client < FulfillmentProductServiceDefinition >
174
- | Client < CurrencyServiceDefinition >
175
- | Client < InvoiceServiceDefinition > ;
123
+ import { AddressMap , BigAmount , BigVAT , ContactPointMap , CountryMap , CRUDClient , CurrencyMap , CustomerMap , DefaultUrns , FulfillmentMap , FulfillmentSolutionMap , OrderMap , OrganizationMap , PositionMap , ProductMap , ProductNature , ProductVariant , RatioedTax , RatioedTaxMap , ShopMap , toObjectMap , VATMap } from './utils.js' ;
176
124
177
125
const CREATE_FULFILLMENT = 'createFulfillment' ;
178
126
@@ -200,39 +148,7 @@ export class OrderingService
200
148
} ;
201
149
}
202
150
203
- private readonly urns = {
204
- instanceType : 'urn:restorecommerce:acs:model:order:Order' ,
205
- disableFulfillment : 'urn:restorecommerce:order:preferences:disableFulfillment' ,
206
- disableInvoice : 'urn:restorecommerce:order:preferences:disableInvoice' ,
207
- entity : 'urn:restorecommerce:acs:names:model:entity' ,
208
- user : 'urn:restorecommerce:acs:model:user.User' ,
209
- model : 'urn:restorecommerce:acs:model' ,
210
- role : 'urn:restorecommerce:acs:names:role' ,
211
- roleScopingEntity : 'urn:restorecommerce:acs:names:roleScopingEntity' ,
212
- roleScopingInstance : 'urn:restorecommerce:acs:names:roleScopingInstance' ,
213
- unauthenticated_user : 'urn:restorecommerce:acs:names:unauthenticated-user' ,
214
- property : 'urn:restorecommerce:acs:names:model:property' ,
215
- ownerIndicatoryEntity : 'urn:restorecommerce:acs:names:ownerIndicatoryEntity' ,
216
- ownerInstance : 'urn:restorecommerce:acs:names:ownerInstance' ,
217
- orgScope : 'urn:restorecommerce:acs:model:organization.Organization' ,
218
- subjectID : 'urn:oasis:names:tc:xacml:1.0:subject:subject-id' ,
219
- resourceID : 'urn:oasis:names:tc:xacml:1.0:resource:resource-id' ,
220
- actionID : 'urn:oasis:names:tc:xacml:1.0:action:action-id' ,
221
- action : 'urn:restorecommerce:acs:names:action' ,
222
- operation : 'urn:restorecommerce:acs:names:operation' ,
223
- execute : 'urn:restorecommerce:acs:names:action:execute' ,
224
- permitOverrides : 'urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides' ,
225
- denyOverrides : 'urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides' ,
226
- create : 'urn:restorecommerce:acs:names:action:create' ,
227
- read : 'urn:restorecommerce:acs:names:action:read' ,
228
- modify : 'urn:restorecommerce:acs:names:action:modify' ,
229
- delete : 'urn:restorecommerce:acs:names:action:delete' ,
230
- organization : 'urn:restorecommerce:acs:model:organization.Organization' ,
231
- aclIndicatoryEntity : 'urn:restorecommerce:acs:names:aclIndicatoryEntity' ,
232
- aclInstance : 'urn:restorecommerce:acs:names:aclInstance' ,
233
- skipACL : 'urn:restorecommerce:acs:names:skipACL' ,
234
- maskedProperty : 'urn:restorecommerce:acs:names:obligation:maskedProperty' ,
235
- } ;
151
+ private readonly urns = DefaultUrns ;
236
152
237
153
private readonly status_codes = {
238
154
OK : {
@@ -334,16 +250,6 @@ export class OrderingService
334
250
billing : 'billing' ,
335
251
} ;
336
252
337
- get ApiKey ( ) : Subject {
338
- const apiKey = this . cfg . get ( 'authentication:apiKey' ) ;
339
- return apiKey
340
- ? {
341
- id : 'apiKey' ,
342
- token : apiKey ,
343
- }
344
- : undefined ;
345
- }
346
-
347
253
get entityName ( ) {
348
254
return this . name ;
349
255
}
@@ -641,13 +547,7 @@ export class OrderingService
641
547
) . then (
642
548
response => {
643
549
if ( response . operation_status ?. code === 200 ) {
644
- return response ?. items ?. reduce (
645
- ( a , b ) => {
646
- a [ b . payload . id ] = b as OrderResponse ;
647
- return a ;
648
- } ,
649
- { } as OrderMap
650
- ) ?? { } ;
550
+ return toObjectMap ( response . items ) ;
651
551
}
652
552
else {
653
553
throw response . operation_status ;
@@ -851,12 +751,7 @@ export class OrderingService
851
751
) ;
852
752
}
853
753
else {
854
- return response . items ! . reduce (
855
- ( a , b ) => {
856
- a [ b . payload . id ] = b ;
857
- return a ;
858
- } , { } as ProductMap
859
- ) ;
754
+ return toObjectMap ( response . items ) ;
860
755
}
861
756
}
862
757
) ;
@@ -1405,7 +1300,6 @@ export class OrderingService
1405
1300
const vats = taxes . filter (
1406
1301
t => (
1407
1302
t . country_id === country ?. id &&
1408
- order . customer_type === CustomerType . PRIVATE &&
1409
1303
country ?. economic_areas ?. some (
1410
1304
ea => billing_country ?. payload ?. economic_areas ?. includes ( ea )
1411
1305
) && (
@@ -1853,10 +1747,10 @@ export class OrderingService
1853
1747
items : orders . items ?. map ( item => ( {
1854
1748
order_id : item . payload . id ,
1855
1749
} ) ) ,
1856
- subject : this . fulfillment_tech_user ?? this . ApiKey ?? request . subject ,
1750
+ subject : this . fulfillment_tech_user ?? request . subject ,
1857
1751
} ,
1858
1752
context ,
1859
- toObjectMap < OrderMap > ( orders . items ) ,
1753
+ toObjectMap ( orders . items ) ,
1860
1754
) . then (
1861
1755
r => {
1862
1756
r . items ?. forEach (
@@ -2328,7 +2222,7 @@ export class OrderingService
2328
2222
{
2329
2223
items : valids . map ( item => item . payload ) ,
2330
2224
total_count : valids . length ,
2331
- subject : this . fulfillment_tech_user ?? this . ApiKey ?? request . subject ,
2225
+ subject : this . fulfillment_tech_user ?? request . subject ,
2332
2226
} ,
2333
2227
context
2334
2228
) . then (
@@ -2407,7 +2301,7 @@ export class OrderingService
2407
2301
{
2408
2302
items : valids . map ( item => item . payload ) ,
2409
2303
total_count : valids . length ,
2410
- subject : this . fulfillment_tech_user ?? this . ApiKey ?? request . subject ,
2304
+ subject : this . fulfillment_tech_user ?? request . subject ,
2411
2305
} ,
2412
2306
context
2413
2307
) . then (
@@ -2801,14 +2695,16 @@ export class OrderingService
2801
2695
proto => proto . payload !
2802
2696
) ;
2803
2697
2804
- const response = await this . invoice_service ! . render (
2698
+ const action = this . invoice_service . create ;
2699
+ const response = await action (
2805
2700
{
2806
2701
items : valids ,
2807
2702
total_count : valids . length ,
2808
- subject : this . invoice_tech_user ?? this . ApiKey ?? request . subject ,
2703
+ subject : this . invoice_tech_user ?? request . subject ,
2809
2704
} ,
2810
2705
context
2811
2706
) ;
2707
+
2812
2708
2813
2709
return {
2814
2710
items : [
0 commit comments