@@ -46,13 +46,15 @@ def __init__(
46
46
period_in_days : Optional [int ],
47
47
report_options : Optional [str ],
48
48
max_wait_seconds : Optional [int ],
49
+ replication_end_date : Optional [str ],
49
50
* args ,
50
51
** kwargs ,
51
52
):
52
53
super ().__init__ (* args , ** kwargs )
53
54
54
55
self ._url_base = url_base .rstrip ("/" ) + "/"
55
56
self ._replication_start_date = replication_start_date
57
+ self ._replication_end_date = replication_end_date
56
58
self .marketplace_id = marketplace_id
57
59
self ._session .auth = aws_signature
58
60
@@ -75,6 +77,11 @@ class IncrementalAmazonSPStream(AmazonSPStream, ABC):
75
77
def replication_start_date_field (self ) -> str :
76
78
pass
77
79
80
+ @property
81
+ @abstractmethod
82
+ def replication_end_date_field (self ) -> str :
83
+ pass
84
+
78
85
@property
79
86
@abstractmethod
80
87
def next_page_token_field (self ) -> str :
@@ -97,9 +104,14 @@ def request_params(
97
104
return dict (next_page_token )
98
105
99
106
params = {self .replication_start_date_field : self ._replication_start_date , self .page_size_field : self .page_size }
107
+
100
108
if self ._replication_start_date and self .cursor_field :
101
109
start_date = max (stream_state .get (self .cursor_field , self ._replication_start_date ), self ._replication_start_date )
102
110
params .update ({self .replication_start_date_field : start_date })
111
+
112
+ if self ._replication_end_date :
113
+ params [self .replication_end_date_field ] = self ._replication_end_date
114
+
103
115
return params
104
116
105
117
def next_page_token (self , response : requests .Response ) -> Optional [Mapping [str , Any ]]:
@@ -154,13 +166,15 @@ def __init__(
154
166
period_in_days : Optional [int ],
155
167
report_options : Optional [str ],
156
168
max_wait_seconds : Optional [int ],
169
+ replication_end_date : Optional [str ],
157
170
authenticator : HttpAuthenticator = None ,
158
171
):
159
172
self ._authenticator = authenticator
160
173
self ._session = requests .Session ()
161
174
self ._url_base = url_base .rstrip ("/" ) + "/"
162
175
self ._session .auth = aws_signature
163
176
self ._replication_start_date = replication_start_date
177
+ self ._replication_end_date = replication_end_date
164
178
self .marketplace_id = marketplace_id
165
179
self .period_in_days = period_in_days
166
180
self ._report_options = report_options
@@ -223,12 +237,21 @@ def _report_data(
223
237
) -> Mapping [str , Any ]:
224
238
replication_start_date = max (pendulum .parse (self ._replication_start_date ), pendulum .now ("utc" ).subtract (days = 90 ))
225
239
226
- return {
240
+ params = {
227
241
"reportType" : self .name ,
228
242
"marketplaceIds" : [self .marketplace_id ],
229
243
"dataStartTime" : replication_start_date .strftime (DATE_TIME_FORMAT ),
230
244
}
231
245
246
+ if self ._replication_end_date and sync_mode == SyncMode .full_refresh :
247
+ params ["dataEndTime" ] = self ._replication_end_date
248
+ # if replication_start_date is older than 90 days(from current date), we are overriding the value above.
249
+ # when replication_end_date is present, we should use the user provided replication_start_date.
250
+ # user may provide a date range which is older than 90 days.
251
+ params ["dataStartTime" ] = self ._replication_start_date
252
+
253
+ return params
254
+
232
255
def _create_report (
233
256
self ,
234
257
sync_mode : SyncMode ,
@@ -539,6 +562,8 @@ def stream_slices(
539
562
540
563
start_date = pendulum .parse (self ._replication_start_date )
541
564
end_date = pendulum .now ()
565
+ if self ._replication_end_date and sync_mode == SyncMode .full_refresh :
566
+ end_date = pendulum .parse (self ._replication_end_date )
542
567
543
568
if stream_state :
544
569
state = stream_state .get (self .cursor_field )
@@ -648,6 +673,7 @@ class Orders(IncrementalAmazonSPStream):
648
673
primary_key = "AmazonOrderId"
649
674
cursor_field = "LastUpdateDate"
650
675
replication_start_date_field = "LastUpdatedAfter"
676
+ replication_end_date_field = "LastUpdatedBefore"
651
677
next_page_token_field = "NextToken"
652
678
page_size_field = "MaxResultsPerPage"
653
679
default_backoff_time = 60
@@ -686,16 +712,11 @@ class VendorDirectFulfillmentShipping(AmazonSPStream):
686
712
name = "VendorDirectFulfillmentShipping"
687
713
primary_key = None
688
714
replication_start_date_field = "createdAfter"
715
+ replication_end_date_field = "createdBefore"
689
716
next_page_token_field = "nextToken"
690
717
page_size_field = "limit"
691
718
time_format = "%Y-%m-%dT%H:%M:%SZ"
692
719
693
- def __init__ (self , * args , ** kwargs ):
694
- super ().__init__ (* args , ** kwargs )
695
- self .replication_start_date_field = max (
696
- pendulum .parse (self ._replication_start_date ), pendulum .now ("utc" ).subtract (days = 7 , hours = 1 )
697
- ).strftime (self .time_format )
698
-
699
720
def path (self , ** kwargs ) -> str :
700
721
return f"vendor/directFulfillment/shipping/{ VENDORS_API_VERSION } /shippingLabels"
701
722
@@ -704,7 +725,15 @@ def request_params(
704
725
) -> MutableMapping [str , Any ]:
705
726
params = super ().request_params (stream_state = stream_state , next_page_token = next_page_token , ** kwargs )
706
727
if not next_page_token :
707
- params .update ({"createdBefore" : pendulum .now ("utc" ).strftime (self .time_format )})
728
+ end_date = pendulum .now ("utc" ).strftime (self .time_format )
729
+ if self ._replication_end_date :
730
+ end_date = self ._replication_end_date
731
+
732
+ start_date = max (pendulum .parse (self ._replication_start_date ), pendulum .parse (end_date ).subtract (days = 7 , hours = 1 )).strftime (
733
+ self .time_format
734
+ )
735
+
736
+ params .update ({self .replication_start_date_field : start_date , self .replication_end_date_field : end_date })
708
737
return params
709
738
710
739
def parse_response (self , response : requests .Response , stream_state : Mapping [str , Any ], ** kwargs ) -> Iterable [Mapping ]:
0 commit comments