@ts-pf/protocol 0.2.2 → 0.5.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/PROTOCOL.md +186 -65
- package/README.md +17 -2
- package/conformance/README.md +187 -0
- package/conformance/http-stream.json +308 -0
- package/conformance/http.json +641 -0
- package/conformance/ws.json +1045 -0
- package/dist/conformance.d.ts +149 -0
- package/dist/conformance.d.ts.map +1 -0
- package/dist/conformance.js +14 -0
- package/dist/conformance.js.map +1 -0
- package/dist/error.d.ts +1 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +12 -1
- package/dist/error.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/is-unexpected-error.d.ts +8 -0
- package/dist/is-unexpected-error.d.ts.map +1 -0
- package/dist/is-unexpected-error.js +11 -0
- package/dist/is-unexpected-error.js.map +1 -0
- package/package.json +7 -2
- package/skills/ts-pf-protocol/SKILL.md +8 -3
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": 1,
|
|
3
|
+
"revision": "1.2",
|
|
4
|
+
"binding": "http",
|
|
5
|
+
"description": "Unary JSON over HTTP: the request a client sends and how it classifies each response. See README.md in this directory.",
|
|
6
|
+
"cases": [
|
|
7
|
+
{
|
|
8
|
+
"id": "http-success-output",
|
|
9
|
+
"description": "A success envelope resolves the call to its output. PROTOCOL.md: HTTP Fetch binding; Classifying an HTTP response, step 2.",
|
|
10
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
11
|
+
"expectRequest": {
|
|
12
|
+
"method": "POST",
|
|
13
|
+
"path": "/planet/find",
|
|
14
|
+
"headers": {
|
|
15
|
+
"content-type": "application/json",
|
|
16
|
+
"x-ts-pf-protocol": "1"
|
|
17
|
+
},
|
|
18
|
+
"body": { "input": { "id": 1 } }
|
|
19
|
+
},
|
|
20
|
+
"response": {
|
|
21
|
+
"status": 200,
|
|
22
|
+
"headers": {
|
|
23
|
+
"content-type": "application/json",
|
|
24
|
+
"x-ts-pf-protocol": "1"
|
|
25
|
+
},
|
|
26
|
+
"body": "{\"ok\":true,\"output\":{\"id\":1,\"name\":\"Earth\"}}"
|
|
27
|
+
},
|
|
28
|
+
"expect": { "kind": "success", "output": { "id": 1, "name": "Earth" } }
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "http-success-void",
|
|
32
|
+
"description": "No input: the body omits input (or sends null). A success envelope without output resolves to no value. PROTOCOL.md: Envelope; Classifying an HTTP response, step 2.",
|
|
33
|
+
"request": { "procedure": ["planet", "reset"] },
|
|
34
|
+
"expectRequest": {
|
|
35
|
+
"method": "POST",
|
|
36
|
+
"path": "/planet/reset",
|
|
37
|
+
"headers": {
|
|
38
|
+
"content-type": "application/json",
|
|
39
|
+
"x-ts-pf-protocol": "1"
|
|
40
|
+
},
|
|
41
|
+
"bodyOneOf": [{}, { "input": null }]
|
|
42
|
+
},
|
|
43
|
+
"response": {
|
|
44
|
+
"status": 200,
|
|
45
|
+
"headers": {
|
|
46
|
+
"content-type": "application/json",
|
|
47
|
+
"x-ts-pf-protocol": "1"
|
|
48
|
+
},
|
|
49
|
+
"body": "{\"ok\":true}"
|
|
50
|
+
},
|
|
51
|
+
"expect": { "kind": "success" }
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "http-success-null-output",
|
|
55
|
+
"description": "output: null is a value, not an omitted output. PROTOCOL.md: Envelope; Classifying an HTTP response, step 2.",
|
|
56
|
+
"request": { "procedure": ["planet", "moon"], "input": { "id": 2 } },
|
|
57
|
+
"expectRequest": {
|
|
58
|
+
"method": "POST",
|
|
59
|
+
"path": "/planet/moon",
|
|
60
|
+
"headers": {
|
|
61
|
+
"content-type": "application/json",
|
|
62
|
+
"x-ts-pf-protocol": "1"
|
|
63
|
+
},
|
|
64
|
+
"body": { "input": { "id": 2 } }
|
|
65
|
+
},
|
|
66
|
+
"response": {
|
|
67
|
+
"status": 200,
|
|
68
|
+
"headers": {
|
|
69
|
+
"content-type": "application/json",
|
|
70
|
+
"x-ts-pf-protocol": "1"
|
|
71
|
+
},
|
|
72
|
+
"body": "{\"ok\":true,\"output\":null}"
|
|
73
|
+
},
|
|
74
|
+
"expect": { "kind": "success", "output": null }
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"id": "http-declared-error-with-data",
|
|
78
|
+
"description": "A procedure-declared code with data, sent with the status on its error definition. Switch on error.code. PROTOCOL.md: Protocol errors.",
|
|
79
|
+
"request": {
|
|
80
|
+
"procedure": ["planet", "create"],
|
|
81
|
+
"input": { "name": "Earth" }
|
|
82
|
+
},
|
|
83
|
+
"expectRequest": {
|
|
84
|
+
"method": "POST",
|
|
85
|
+
"path": "/planet/create",
|
|
86
|
+
"headers": {
|
|
87
|
+
"content-type": "application/json",
|
|
88
|
+
"x-ts-pf-protocol": "1"
|
|
89
|
+
},
|
|
90
|
+
"body": { "input": { "name": "Earth" } }
|
|
91
|
+
},
|
|
92
|
+
"response": {
|
|
93
|
+
"status": 409,
|
|
94
|
+
"headers": {
|
|
95
|
+
"content-type": "application/json",
|
|
96
|
+
"x-ts-pf-protocol": "1"
|
|
97
|
+
},
|
|
98
|
+
"body": "{\"ok\":false,\"error\":{\"code\":\"PLANET_EXISTS\",\"message\":\"Planet already exists\",\"data\":{\"name\":\"Earth\"}}}"
|
|
99
|
+
},
|
|
100
|
+
"expect": {
|
|
101
|
+
"kind": "error",
|
|
102
|
+
"code": "PLANET_EXISTS",
|
|
103
|
+
"message": "Planet already exists",
|
|
104
|
+
"data": { "name": "Earth" }
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "http-declared-error-default-status",
|
|
109
|
+
"description": "A declared code whose definition has no status is sent as HTTP 400; the code, not the status, identifies it. PROTOCOL.md: Protocol errors.",
|
|
110
|
+
"request": { "procedure": ["shop", "buy"], "input": { "sku": "A1" } },
|
|
111
|
+
"expectRequest": {
|
|
112
|
+
"method": "POST",
|
|
113
|
+
"path": "/shop/buy",
|
|
114
|
+
"headers": {
|
|
115
|
+
"content-type": "application/json",
|
|
116
|
+
"x-ts-pf-protocol": "1"
|
|
117
|
+
},
|
|
118
|
+
"body": { "input": { "sku": "A1" } }
|
|
119
|
+
},
|
|
120
|
+
"response": {
|
|
121
|
+
"status": 400,
|
|
122
|
+
"headers": {
|
|
123
|
+
"content-type": "application/json",
|
|
124
|
+
"x-ts-pf-protocol": "1"
|
|
125
|
+
},
|
|
126
|
+
"body": "{\"ok\":false,\"error\":{\"code\":\"OUT_OF_STOCK\",\"message\":\"Out of stock\"}}"
|
|
127
|
+
},
|
|
128
|
+
"expect": {
|
|
129
|
+
"kind": "error",
|
|
130
|
+
"code": "OUT_OF_STOCK",
|
|
131
|
+
"message": "Out of stock"
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"id": "http-unknown-code",
|
|
136
|
+
"description": "A code the client has never seen is still a failure envelope: surface it (catch-all), never drop it or read the status instead. PROTOCOL.md: Protocol errors.",
|
|
137
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
138
|
+
"expectRequest": {
|
|
139
|
+
"method": "POST",
|
|
140
|
+
"path": "/planet/find",
|
|
141
|
+
"headers": {
|
|
142
|
+
"content-type": "application/json",
|
|
143
|
+
"x-ts-pf-protocol": "1"
|
|
144
|
+
},
|
|
145
|
+
"body": { "input": { "id": 1 } }
|
|
146
|
+
},
|
|
147
|
+
"response": {
|
|
148
|
+
"status": 418,
|
|
149
|
+
"headers": {
|
|
150
|
+
"content-type": "application/json",
|
|
151
|
+
"x-ts-pf-protocol": "1"
|
|
152
|
+
},
|
|
153
|
+
"body": "{\"ok\":false,\"error\":{\"code\":\"SOMETHING_NEW\",\"message\":\"Added after this client shipped\"}}"
|
|
154
|
+
},
|
|
155
|
+
"expect": {
|
|
156
|
+
"kind": "error",
|
|
157
|
+
"code": "SOMETHING_NEW",
|
|
158
|
+
"message": "Added after this client shipped"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"id": "http-protocol-validation",
|
|
163
|
+
"description": "VALIDATION carries data.issues as { message, path }[]. PROTOCOL.md: Protocol errors.",
|
|
164
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": "one" } },
|
|
165
|
+
"expectRequest": {
|
|
166
|
+
"method": "POST",
|
|
167
|
+
"path": "/planet/find",
|
|
168
|
+
"headers": {
|
|
169
|
+
"content-type": "application/json",
|
|
170
|
+
"x-ts-pf-protocol": "1"
|
|
171
|
+
},
|
|
172
|
+
"body": { "input": { "id": "one" } }
|
|
173
|
+
},
|
|
174
|
+
"response": {
|
|
175
|
+
"status": 422,
|
|
176
|
+
"headers": {
|
|
177
|
+
"content-type": "application/json",
|
|
178
|
+
"x-ts-pf-protocol": "1"
|
|
179
|
+
},
|
|
180
|
+
"body": "{\"ok\":false,\"error\":{\"code\":\"VALIDATION\",\"message\":\"Validation failed\",\"data\":{\"issues\":[{\"message\":\"Expected number\",\"path\":[\"id\"]}]}}}"
|
|
181
|
+
},
|
|
182
|
+
"expect": {
|
|
183
|
+
"kind": "error",
|
|
184
|
+
"code": "VALIDATION",
|
|
185
|
+
"message": "Validation failed",
|
|
186
|
+
"data": { "issues": [{ "message": "Expected number", "path": ["id"] }] }
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"id": "http-protocol-not-found",
|
|
191
|
+
"description": "NOT_FOUND from the server (the procedure is missing) is a decoded envelope, unlike a proxy's HTML 404. PROTOCOL.md: Protocol errors.",
|
|
192
|
+
"request": { "procedure": ["planet", "missing"] },
|
|
193
|
+
"expectRequest": {
|
|
194
|
+
"method": "POST",
|
|
195
|
+
"path": "/planet/missing",
|
|
196
|
+
"headers": {
|
|
197
|
+
"content-type": "application/json",
|
|
198
|
+
"x-ts-pf-protocol": "1"
|
|
199
|
+
},
|
|
200
|
+
"bodyOneOf": [{}, { "input": null }]
|
|
201
|
+
},
|
|
202
|
+
"response": {
|
|
203
|
+
"status": 404,
|
|
204
|
+
"headers": {
|
|
205
|
+
"content-type": "application/json",
|
|
206
|
+
"x-ts-pf-protocol": "1"
|
|
207
|
+
},
|
|
208
|
+
"body": "{\"ok\":false,\"error\":{\"code\":\"NOT_FOUND\",\"message\":\"Procedure not found\"}}"
|
|
209
|
+
},
|
|
210
|
+
"expect": {
|
|
211
|
+
"kind": "error",
|
|
212
|
+
"code": "NOT_FOUND",
|
|
213
|
+
"message": "Procedure not found"
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"id": "http-protocol-bad-request",
|
|
218
|
+
"description": "BAD_REQUEST from the server (it could not read the request) is a decoded envelope, unlike a response body the client cannot read. PROTOCOL.md: Protocol errors.",
|
|
219
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
220
|
+
"expectRequest": {
|
|
221
|
+
"method": "POST",
|
|
222
|
+
"path": "/planet/find",
|
|
223
|
+
"headers": {
|
|
224
|
+
"content-type": "application/json",
|
|
225
|
+
"x-ts-pf-protocol": "1"
|
|
226
|
+
},
|
|
227
|
+
"body": { "input": { "id": 1 } }
|
|
228
|
+
},
|
|
229
|
+
"response": {
|
|
230
|
+
"status": 400,
|
|
231
|
+
"headers": {
|
|
232
|
+
"content-type": "application/json",
|
|
233
|
+
"x-ts-pf-protocol": "1"
|
|
234
|
+
},
|
|
235
|
+
"body": "{\"ok\":false,\"error\":{\"code\":\"BAD_REQUEST\",\"message\":\"Request body must be a JSON object\"}}"
|
|
236
|
+
},
|
|
237
|
+
"expect": {
|
|
238
|
+
"kind": "error",
|
|
239
|
+
"code": "BAD_REQUEST",
|
|
240
|
+
"message": "Request body must be a JSON object"
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"id": "http-headerless-envelope-trusted",
|
|
245
|
+
"description": "A response without x-ts-pf-protocol whose body decodes is trusted (a cross-origin browser may not see the header). PROTOCOL.md: Classifying an HTTP response, step 4.",
|
|
246
|
+
"request": { "procedure": ["admin", "purge"] },
|
|
247
|
+
"expectRequest": {
|
|
248
|
+
"method": "POST",
|
|
249
|
+
"path": "/admin/purge",
|
|
250
|
+
"headers": {
|
|
251
|
+
"content-type": "application/json",
|
|
252
|
+
"x-ts-pf-protocol": "1"
|
|
253
|
+
},
|
|
254
|
+
"bodyOneOf": [{}, { "input": null }]
|
|
255
|
+
},
|
|
256
|
+
"response": {
|
|
257
|
+
"status": 403,
|
|
258
|
+
"headers": { "content-type": "application/json" },
|
|
259
|
+
"body": "{\"ok\":false,\"error\":{\"code\":\"FORBIDDEN\",\"message\":\"Admins only\"}}"
|
|
260
|
+
},
|
|
261
|
+
"expect": {
|
|
262
|
+
"kind": "error",
|
|
263
|
+
"code": "FORBIDDEN",
|
|
264
|
+
"message": "Admins only"
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"id": "http-headerless-success-trusted",
|
|
269
|
+
"description": "A headerless success envelope is trusted too. PROTOCOL.md: Classifying an HTTP response, step 4.",
|
|
270
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
271
|
+
"expectRequest": {
|
|
272
|
+
"method": "POST",
|
|
273
|
+
"path": "/planet/find",
|
|
274
|
+
"headers": {
|
|
275
|
+
"content-type": "application/json",
|
|
276
|
+
"x-ts-pf-protocol": "1"
|
|
277
|
+
},
|
|
278
|
+
"body": { "input": { "id": 1 } }
|
|
279
|
+
},
|
|
280
|
+
"response": {
|
|
281
|
+
"status": 200,
|
|
282
|
+
"headers": { "content-type": "application/json" },
|
|
283
|
+
"body": "{\"ok\":true,\"output\":{\"id\":1,\"name\":\"Earth\"}}"
|
|
284
|
+
},
|
|
285
|
+
"expect": { "kind": "success", "output": { "id": 1, "name": "Earth" } }
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"id": "http-version-header-trimmed",
|
|
289
|
+
"description": "The version header is compared after trimming surrounding whitespace. PROTOCOL.md: Classifying an HTTP response, step 1.",
|
|
290
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
291
|
+
"expectRequest": {
|
|
292
|
+
"method": "POST",
|
|
293
|
+
"path": "/planet/find",
|
|
294
|
+
"headers": {
|
|
295
|
+
"content-type": "application/json",
|
|
296
|
+
"x-ts-pf-protocol": "1"
|
|
297
|
+
},
|
|
298
|
+
"body": { "input": { "id": 1 } }
|
|
299
|
+
},
|
|
300
|
+
"response": {
|
|
301
|
+
"status": 200,
|
|
302
|
+
"headers": {
|
|
303
|
+
"content-type": "application/json",
|
|
304
|
+
"x-ts-pf-protocol": " 1 "
|
|
305
|
+
},
|
|
306
|
+
"body": "{\"ok\":true,\"output\":{\"id\":1,\"name\":\"Earth\"}}"
|
|
307
|
+
},
|
|
308
|
+
"expect": { "kind": "success", "output": { "id": 1, "name": "Earth" } }
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"id": "http-version-mismatch",
|
|
312
|
+
"description": "x-ts-pf-protocol present and not 1: fail the call without decoding the body (here a success envelope a decoding client would wrongly accept). PROTOCOL.md: Classifying an HTTP response, step 1; Versioning.",
|
|
313
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
314
|
+
"expectRequest": {
|
|
315
|
+
"method": "POST",
|
|
316
|
+
"path": "/planet/find",
|
|
317
|
+
"headers": {
|
|
318
|
+
"content-type": "application/json",
|
|
319
|
+
"x-ts-pf-protocol": "1"
|
|
320
|
+
},
|
|
321
|
+
"body": { "input": { "id": 1 } }
|
|
322
|
+
},
|
|
323
|
+
"response": {
|
|
324
|
+
"status": 200,
|
|
325
|
+
"headers": {
|
|
326
|
+
"content-type": "application/json",
|
|
327
|
+
"x-ts-pf-protocol": "2"
|
|
328
|
+
},
|
|
329
|
+
"body": "{\"ok\":true,\"output\":{\"id\":1,\"name\":\"Earth\"}}"
|
|
330
|
+
},
|
|
331
|
+
"expect": { "kind": "version-mismatch" }
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
"id": "http-version-mismatch-error-body",
|
|
335
|
+
"description": "Another major's failure envelope is not decoded either: the outcome is the version mismatch, not its code. PROTOCOL.md: Classifying an HTTP response, step 1.",
|
|
336
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
337
|
+
"expectRequest": {
|
|
338
|
+
"method": "POST",
|
|
339
|
+
"path": "/planet/find",
|
|
340
|
+
"headers": {
|
|
341
|
+
"content-type": "application/json",
|
|
342
|
+
"x-ts-pf-protocol": "1"
|
|
343
|
+
},
|
|
344
|
+
"body": { "input": { "id": 1 } }
|
|
345
|
+
},
|
|
346
|
+
"response": {
|
|
347
|
+
"status": 400,
|
|
348
|
+
"headers": {
|
|
349
|
+
"content-type": "application/json",
|
|
350
|
+
"x-ts-pf-protocol": "2"
|
|
351
|
+
},
|
|
352
|
+
"body": "{\"ok\":false,\"error\":{\"code\":\"BAD_REQUEST\",\"message\":\"Unsupported protocol version\"}}"
|
|
353
|
+
},
|
|
354
|
+
"expect": { "kind": "version-mismatch" }
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
"id": "http-proxy-html-404",
|
|
358
|
+
"description": "A proxy's HTML 404 is a transport failure, never NOT_FOUND. PROTOCOL.md: Classifying an HTTP response, step 3.",
|
|
359
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
360
|
+
"expectRequest": {
|
|
361
|
+
"method": "POST",
|
|
362
|
+
"path": "/planet/find",
|
|
363
|
+
"headers": {
|
|
364
|
+
"content-type": "application/json",
|
|
365
|
+
"x-ts-pf-protocol": "1"
|
|
366
|
+
},
|
|
367
|
+
"body": { "input": { "id": 1 } }
|
|
368
|
+
},
|
|
369
|
+
"response": {
|
|
370
|
+
"status": 404,
|
|
371
|
+
"headers": { "content-type": "text/html" },
|
|
372
|
+
"body": "<!doctype html><title>404 Not Found</title><h1>Not Found</h1>"
|
|
373
|
+
},
|
|
374
|
+
"expect": { "kind": "transport-failure" }
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
"id": "http-proxy-html-401",
|
|
378
|
+
"description": "An auth gateway's HTML 401 is a transport failure, never an application \"unauthenticated\" outcome. PROTOCOL.md: Classifying an HTTP response, step 3.",
|
|
379
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
380
|
+
"expectRequest": {
|
|
381
|
+
"method": "POST",
|
|
382
|
+
"path": "/planet/find",
|
|
383
|
+
"headers": {
|
|
384
|
+
"content-type": "application/json",
|
|
385
|
+
"x-ts-pf-protocol": "1"
|
|
386
|
+
},
|
|
387
|
+
"body": { "input": { "id": 1 } }
|
|
388
|
+
},
|
|
389
|
+
"response": {
|
|
390
|
+
"status": 401,
|
|
391
|
+
"headers": {
|
|
392
|
+
"content-type": "text/html",
|
|
393
|
+
"www-authenticate": "Basic realm=\"edge\""
|
|
394
|
+
},
|
|
395
|
+
"body": "<!doctype html><title>401 Unauthorized</title>"
|
|
396
|
+
},
|
|
397
|
+
"expect": { "kind": "transport-failure" }
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"id": "http-proxy-502",
|
|
401
|
+
"description": "A load balancer's 502 is a transport failure (retry is optional and only for calls safe to repeat). PROTOCOL.md: Classifying an HTTP response, step 3.",
|
|
402
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
403
|
+
"expectRequest": {
|
|
404
|
+
"method": "POST",
|
|
405
|
+
"path": "/planet/find",
|
|
406
|
+
"headers": {
|
|
407
|
+
"content-type": "application/json",
|
|
408
|
+
"x-ts-pf-protocol": "1"
|
|
409
|
+
},
|
|
410
|
+
"body": { "input": { "id": 1 } }
|
|
411
|
+
},
|
|
412
|
+
"response": {
|
|
413
|
+
"status": 502,
|
|
414
|
+
"headers": { "content-type": "text/html" },
|
|
415
|
+
"body": "<html><body><h1>502 Bad Gateway</h1></body></html>"
|
|
416
|
+
},
|
|
417
|
+
"expect": { "kind": "transport-failure" }
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
"id": "http-headerless-200-html",
|
|
421
|
+
"description": "A 200 that is not an envelope (an HTML fallback page) is a transport failure, not a success. PROTOCOL.md: Classifying an HTTP response, steps 2-3.",
|
|
422
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
423
|
+
"expectRequest": {
|
|
424
|
+
"method": "POST",
|
|
425
|
+
"path": "/planet/find",
|
|
426
|
+
"headers": {
|
|
427
|
+
"content-type": "application/json",
|
|
428
|
+
"x-ts-pf-protocol": "1"
|
|
429
|
+
},
|
|
430
|
+
"body": { "input": { "id": 1 } }
|
|
431
|
+
},
|
|
432
|
+
"response": {
|
|
433
|
+
"status": 200,
|
|
434
|
+
"headers": { "content-type": "text/html" },
|
|
435
|
+
"body": "<!doctype html><title>App</title><div id=\"root\"></div>"
|
|
436
|
+
},
|
|
437
|
+
"expect": { "kind": "transport-failure" }
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
"id": "http-headerless-200-json-not-envelope",
|
|
441
|
+
"description": "JSON that is not an envelope (no boolean ok) is a transport failure. PROTOCOL.md: Classifying an HTTP response, steps 2-3.",
|
|
442
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
443
|
+
"expectRequest": {
|
|
444
|
+
"method": "POST",
|
|
445
|
+
"path": "/planet/find",
|
|
446
|
+
"headers": {
|
|
447
|
+
"content-type": "application/json",
|
|
448
|
+
"x-ts-pf-protocol": "1"
|
|
449
|
+
},
|
|
450
|
+
"body": { "input": { "id": 1 } }
|
|
451
|
+
},
|
|
452
|
+
"response": {
|
|
453
|
+
"status": 200,
|
|
454
|
+
"headers": { "content-type": "application/json" },
|
|
455
|
+
"body": "{\"id\":1,\"name\":\"Earth\"}"
|
|
456
|
+
},
|
|
457
|
+
"expect": { "kind": "transport-failure" }
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
"id": "http-malformed-json-headerless",
|
|
461
|
+
"description": "A body that does not parse as JSON is a transport failure. PROTOCOL.md: Classifying an HTTP response, steps 2-3.",
|
|
462
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
463
|
+
"expectRequest": {
|
|
464
|
+
"method": "POST",
|
|
465
|
+
"path": "/planet/find",
|
|
466
|
+
"headers": {
|
|
467
|
+
"content-type": "application/json",
|
|
468
|
+
"x-ts-pf-protocol": "1"
|
|
469
|
+
},
|
|
470
|
+
"body": { "input": { "id": 1 } }
|
|
471
|
+
},
|
|
472
|
+
"response": {
|
|
473
|
+
"status": 200,
|
|
474
|
+
"headers": { "content-type": "application/json" },
|
|
475
|
+
"body": "{\"ok\":true,\"output\":"
|
|
476
|
+
},
|
|
477
|
+
"expect": { "kind": "transport-failure" }
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
"id": "http-malformed-json-with-header",
|
|
481
|
+
"description": "A body that does not decode is a transport failure even with x-ts-pf-protocol: 1. PROTOCOL.md: Classifying an HTTP response, step 3.",
|
|
482
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
483
|
+
"expectRequest": {
|
|
484
|
+
"method": "POST",
|
|
485
|
+
"path": "/planet/find",
|
|
486
|
+
"headers": {
|
|
487
|
+
"content-type": "application/json",
|
|
488
|
+
"x-ts-pf-protocol": "1"
|
|
489
|
+
},
|
|
490
|
+
"body": { "input": { "id": 1 } }
|
|
491
|
+
},
|
|
492
|
+
"response": {
|
|
493
|
+
"status": 500,
|
|
494
|
+
"headers": {
|
|
495
|
+
"content-type": "application/json",
|
|
496
|
+
"x-ts-pf-protocol": "1"
|
|
497
|
+
},
|
|
498
|
+
"body": "{\"ok\":false,"
|
|
499
|
+
},
|
|
500
|
+
"expect": { "kind": "transport-failure" }
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
"id": "http-ok-false-without-error",
|
|
504
|
+
"description": "ok: false requires error; without it the body is not an envelope. PROTOCOL.md: Classifying an HTTP response, step 2.",
|
|
505
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
506
|
+
"expectRequest": {
|
|
507
|
+
"method": "POST",
|
|
508
|
+
"path": "/planet/find",
|
|
509
|
+
"headers": {
|
|
510
|
+
"content-type": "application/json",
|
|
511
|
+
"x-ts-pf-protocol": "1"
|
|
512
|
+
},
|
|
513
|
+
"body": { "input": { "id": 1 } }
|
|
514
|
+
},
|
|
515
|
+
"response": {
|
|
516
|
+
"status": 400,
|
|
517
|
+
"headers": {
|
|
518
|
+
"content-type": "application/json",
|
|
519
|
+
"x-ts-pf-protocol": "1"
|
|
520
|
+
},
|
|
521
|
+
"body": "{\"ok\":false}"
|
|
522
|
+
},
|
|
523
|
+
"expect": { "kind": "transport-failure" }
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
"id": "http-ok-false-error-null",
|
|
527
|
+
"description": "error: null is not an error. PROTOCOL.md: Classifying an HTTP response, step 2.",
|
|
528
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
529
|
+
"expectRequest": {
|
|
530
|
+
"method": "POST",
|
|
531
|
+
"path": "/planet/find",
|
|
532
|
+
"headers": {
|
|
533
|
+
"content-type": "application/json",
|
|
534
|
+
"x-ts-pf-protocol": "1"
|
|
535
|
+
},
|
|
536
|
+
"body": { "input": { "id": 1 } }
|
|
537
|
+
},
|
|
538
|
+
"response": {
|
|
539
|
+
"status": 400,
|
|
540
|
+
"headers": {
|
|
541
|
+
"content-type": "application/json",
|
|
542
|
+
"x-ts-pf-protocol": "1"
|
|
543
|
+
},
|
|
544
|
+
"body": "{\"ok\":false,\"error\":null}"
|
|
545
|
+
},
|
|
546
|
+
"expect": { "kind": "transport-failure" }
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
"id": "http-ok-false-error-primitive",
|
|
550
|
+
"description": "An error that is a JSON primitive is not an error. PROTOCOL.md: Classifying an HTTP response, step 2.",
|
|
551
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
552
|
+
"expectRequest": {
|
|
553
|
+
"method": "POST",
|
|
554
|
+
"path": "/planet/find",
|
|
555
|
+
"headers": {
|
|
556
|
+
"content-type": "application/json",
|
|
557
|
+
"x-ts-pf-protocol": "1"
|
|
558
|
+
},
|
|
559
|
+
"body": { "input": { "id": 1 } }
|
|
560
|
+
},
|
|
561
|
+
"response": {
|
|
562
|
+
"status": 400,
|
|
563
|
+
"headers": {
|
|
564
|
+
"content-type": "application/json",
|
|
565
|
+
"x-ts-pf-protocol": "1"
|
|
566
|
+
},
|
|
567
|
+
"body": "{\"ok\":false,\"error\":\"boom\"}"
|
|
568
|
+
},
|
|
569
|
+
"expect": { "kind": "transport-failure" }
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
"id": "http-ok-not-boolean",
|
|
573
|
+
"description": "ok must be the JSON boolean true or false; the string \"true\" is not an envelope. PROTOCOL.md: Classifying an HTTP response, step 2.",
|
|
574
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
575
|
+
"expectRequest": {
|
|
576
|
+
"method": "POST",
|
|
577
|
+
"path": "/planet/find",
|
|
578
|
+
"headers": {
|
|
579
|
+
"content-type": "application/json",
|
|
580
|
+
"x-ts-pf-protocol": "1"
|
|
581
|
+
},
|
|
582
|
+
"body": { "input": { "id": 1 } }
|
|
583
|
+
},
|
|
584
|
+
"response": {
|
|
585
|
+
"status": 200,
|
|
586
|
+
"headers": {
|
|
587
|
+
"content-type": "application/json",
|
|
588
|
+
"x-ts-pf-protocol": "1"
|
|
589
|
+
},
|
|
590
|
+
"body": "{\"ok\":\"true\",\"output\":1}"
|
|
591
|
+
},
|
|
592
|
+
"expect": { "kind": "transport-failure" }
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
"id": "http-body-array",
|
|
596
|
+
"description": "The body must parse to an object, not an array. PROTOCOL.md: Classifying an HTTP response, step 2.",
|
|
597
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
598
|
+
"expectRequest": {
|
|
599
|
+
"method": "POST",
|
|
600
|
+
"path": "/planet/find",
|
|
601
|
+
"headers": {
|
|
602
|
+
"content-type": "application/json",
|
|
603
|
+
"x-ts-pf-protocol": "1"
|
|
604
|
+
},
|
|
605
|
+
"body": { "input": { "id": 1 } }
|
|
606
|
+
},
|
|
607
|
+
"response": {
|
|
608
|
+
"status": 200,
|
|
609
|
+
"headers": {
|
|
610
|
+
"content-type": "application/json",
|
|
611
|
+
"x-ts-pf-protocol": "1"
|
|
612
|
+
},
|
|
613
|
+
"body": "[{\"ok\":true}]"
|
|
614
|
+
},
|
|
615
|
+
"expect": { "kind": "transport-failure" }
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
"id": "http-body-null",
|
|
619
|
+
"description": "The body must parse to an object, not null. PROTOCOL.md: Classifying an HTTP response, step 2.",
|
|
620
|
+
"request": { "procedure": ["planet", "find"], "input": { "id": 1 } },
|
|
621
|
+
"expectRequest": {
|
|
622
|
+
"method": "POST",
|
|
623
|
+
"path": "/planet/find",
|
|
624
|
+
"headers": {
|
|
625
|
+
"content-type": "application/json",
|
|
626
|
+
"x-ts-pf-protocol": "1"
|
|
627
|
+
},
|
|
628
|
+
"body": { "input": { "id": 1 } }
|
|
629
|
+
},
|
|
630
|
+
"response": {
|
|
631
|
+
"status": 200,
|
|
632
|
+
"headers": {
|
|
633
|
+
"content-type": "application/json",
|
|
634
|
+
"x-ts-pf-protocol": "1"
|
|
635
|
+
},
|
|
636
|
+
"body": "null"
|
|
637
|
+
},
|
|
638
|
+
"expect": { "kind": "transport-failure" }
|
|
639
|
+
}
|
|
640
|
+
]
|
|
641
|
+
}
|