@kensio/yulin 1.21.30 → 1.21.31

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.
@@ -35,9 +35,10 @@ interface SimLambdaAwsApiOutboundProperties {
35
35
  * operation it names.
36
36
  */
37
37
  export declare class SimLambdaAwsApiOutbound implements SimLambdaOutboundHttp {
38
+ private readonly simAws;
38
39
  private readonly dispatcher;
39
40
  private readonly s3;
40
- constructor(properties: SimLambdaAwsApiOutboundProperties);
41
+ constructor({ simAws, regionName }: SimLambdaAwsApiOutboundProperties);
41
42
  /**
42
43
  * Whether a hostname is one of the AWS service API endpoints.
43
44
  */
@@ -51,6 +52,11 @@ export declare class SimLambdaAwsApiOutbound implements SimLambdaOutboundHttp {
51
52
  * credentials the runtime puts in the environment, and the invocation is
52
53
  * already running as the execution Role, the ambient caller every other call
53
54
  * out of function code runs as.
55
+ *
56
+ * Every answer is stamped with simulated time, as real AWS stamps every API
57
+ * response with server time. The SDK corrects its clock skew from that
58
+ * header, and an answer missing it would be stamped with host time by the
59
+ * HTTP/2 server answering it.
54
60
  */
55
61
  fetch(request: Request): Promise<Response>;
56
62
  }
@@ -75,11 +75,13 @@ export function isSimAwsApiRequest(request) {
75
75
  * operation it names.
76
76
  */
77
77
  export class SimLambdaAwsApiOutbound {
78
+ simAws;
78
79
  dispatcher;
79
80
  s3;
80
- constructor(properties) {
81
- this.dispatcher = new SimSdkWireDispatcher(properties.simAws, properties.regionName);
82
- this.s3 = new SimS3ApiEndpoint({ simAws: properties.simAws });
81
+ constructor({ simAws, regionName }) {
82
+ this.simAws = simAws;
83
+ this.dispatcher = new SimSdkWireDispatcher(simAws, regionName);
84
+ this.s3 = new SimS3ApiEndpoint({ simAws });
83
85
  }
84
86
  /**
85
87
  * Whether a hostname is one of the AWS service API endpoints.
@@ -96,13 +98,19 @@ export class SimLambdaAwsApiOutbound {
96
98
  * credentials the runtime puts in the environment, and the invocation is
97
99
  * already running as the execution Role, the ambient caller every other call
98
100
  * out of function code runs as.
101
+ *
102
+ * Every answer is stamped with simulated time, as real AWS stamps every API
103
+ * response with server time. The SDK corrects its clock skew from that
104
+ * header, and an answer missing it would be stamped with host time by the
105
+ * HTTP/2 server answering it.
99
106
  */
100
107
  async fetch(request) {
101
108
  const wireRequest = await simLambdaOutboundWireRequest(request);
102
109
  const scope = readSimSdkWireCredentialScope(wireRequest);
103
- if (scope?.signingName === s3SigningName) {
104
- return await this.s3.handle(request, wireRequest.body, undefined, scope.regionName);
105
- }
106
- return simLambdaOutboundWireResponse(await this.dispatcher.dispatch(wireRequest));
110
+ const response = scope?.signingName === s3SigningName
111
+ ? await this.s3.handle(request, wireRequest.body, undefined, scope.regionName)
112
+ : simLambdaOutboundWireResponse(await this.dispatcher.dispatch(wireRequest));
113
+ response.headers.set("date", this.simAws.now().toUTCString());
114
+ return response;
107
115
  }
108
116
  }
@@ -26,6 +26,9 @@ export declare class SimLambdaHttp2Session {
26
26
  *
27
27
  * A request the simulation cannot answer fails the client's stream with the
28
28
  * error that explains it, which is what the SDK rejects the call with.
29
+ *
30
+ * The answer carries the `date` the simulation gave it, or none. The server
31
+ * would otherwise date it from the host clock.
29
32
  */
30
33
  private respond;
31
34
  }
@@ -42,11 +42,15 @@ export class SimLambdaHttp2Session {
42
42
  *
43
43
  * A request the simulation cannot answer fails the client's stream with the
44
44
  * error that explains it, which is what the SDK rejects the call with.
45
+ *
46
+ * The answer carries the `date` the simulation gave it, or none. The server
47
+ * would otherwise date it from the host clock.
45
48
  */
46
49
  async respond(request, response, clientStream) {
47
50
  try {
48
51
  const answered = await this.outbound.fetch(await simLambdaHttp2Request(this.authority, this.outbound, request));
49
52
  const body = Buffer.from(await answered.arrayBuffer());
53
+ response.sendDate = false;
50
54
  response.writeHead(answered.status, simLambdaHttp2ResponseHeaders(answered.headers));
51
55
  response.end(body);
52
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kensio/yulin",
3
- "version": "1.21.30",
3
+ "version": "1.21.31",
4
4
  "description": "AWS system behaviour simulation for isolated unit testing",
5
5
  "repository": "https://github.com/KensioSoftware/yulin",
6
6
  "homepage": "https://yulinsim.dev/",