Skip to content

Commit 3c18b5a

Browse files
lussolucacloudify
authored andcommitted
[#157768307] Replaces autorest with fetch and autogenerated models (#292)
1 parent b81e1a7 commit 3c18b5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1084
-1890
lines changed

.circleci/config.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ jobs:
3232
# Generate the proxy API models
3333
- run: yarn generate:proxy-models
3434

35-
# Generate API client
36-
- run: yarn generate:api-client
37-
38-
# Generate PagoPA client
39-
- run: yarn generate:pagopa-client
40-
4135
# Generate certificates
4236
- run: yarn generate:test-certs
4337

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ ALLOW_PAGOPA_IP_SOURCE_RANGE="::ffff:ac13:1/112"
1919
AUTHENTICATION_BASE_PATH=""
2020
API_BASE_PATH="/api/v1"
2121
PAGOPA_BASE_PATH="/pagopa/api/v1"
22+
PAGOPA_API_URL= ""
2223
SPID_AUTOLOGIN=lussoluca
2324
SPID_TESTENV_URL=https://spid-testenv2:8088

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ npm-debug.log
2121
*.js.map
2222

2323
# Excluded auto-generated API client.
24-
/src/clients/
24+
/src/clients/pagopa
2525

2626
# Excluded auto-generated API types.
2727
/src/types/api/*.ts

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ COPY /api_public.yaml /usr/src/app/api_public.yaml
1717
RUN sudo chmod -R 777 /usr/src/app \
1818
&& yarn install \
1919
&& yarn generate:proxy-models \
20-
&& yarn generate:api-client \
21-
&& yarn generate:pagopa-client \
2220
&& yarn build
2321

2422
FROM node:8.9.4-alpine

README.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The code that manage this flow are in the `src/strategies/bearerSessionTokenStra
8484

8585
* [Docker](https://www.docker.com/) and [Docker Compose](https://github.com/docker/compose)
8686

87-
To fully simulate the SPID authentication process we use the images provided by the
87+
To fully simulate the SPID authentication process we use the images provided by the
8888
[spid-testenv2](https://github.com/italia/spid-testenv2) project.
8989

9090
A Linux/macOS environment is required at the moment.
@@ -96,12 +96,10 @@ A Linux/macOS environment is required at the moment.
9696
3. run `scripts/build-tools.sh` to build the `tools` Docker image
9797
4. run `scripts/yarn.sh` to install backend dependencies
9898
5. run `scripts/generate-proxy-api-models.sh` to generate the models defined in api_proxy.yaml and api_notifications.yaml
99-
6. run `scripts/generate-api-client.sh` to generate the Autorest API Client
100-
7. run `scripts/generate-pagopa-client.sh` to generate the Autorest PagoPA Client
101-
8. run `scripts/build.sh` to compile the Typescript files
102-
9. run `scripts/generate-test-certs-task.sh` to create SAML (SPID) certificates
103-
10. run `docker-compose up -d` to start the containers
104-
11. edit your `/etc/hosts` file by adding:
99+
6. run `scripts/build.sh` to compile the Typescript files
100+
7. run `scripts/generate-test-certs-task.sh` to create SAML (SPID) certificates
101+
8. run `docker-compose up -d` to start the containers
102+
9. edit your `/etc/hosts` file by adding:
105103

106104
```
107105
localhost spid-testenv2
@@ -148,7 +146,7 @@ Those are all Environment variables needed by the application:
148146
| ALLOW_PAGOPA_IP_SOURCE_RANGE | The range in CIDR form of allowed IPs for the PagoPA API | string |
149147
| AUTHENTICATION_BASE_PATH | The root path for the authentication endpoints | string |
150148
| API_BASE_PATH | The root path for the api endpoints | string |
151-
| PAGOPA_BASE_PATH | The root path for the PagoPA endpoints | string |
149+
| PAGOPA_BASE_PATH | The root path for the PagoPA endpoints | string |
152150
| SPID_AUTOLOGIN | The user used in the autologin feature, omit this to disable autologin | string |
153151
154152
### Logs
@@ -180,13 +178,6 @@ A Linux/macOS environment is required at the moment.
180178
181179
In general follow the [Node Best Practices](https://devcenter.heroku.com/articles/node-best-practices).
182180
183-
### Generate the API client
184-
185-
The API client is generated with the [AutoRest](https://github.com/Azure/autorest) tool, in case of API change you need
186-
to regenerate the client code:
187-
188-
* run the command `yarn generate:api-client`
189-
190181
### Generate SAML (SPID) certs (development)
191182
192183
The backend implements a SAML Service Provider - for authenticating the clients

api_proxy.yaml

Lines changed: 82 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ paths:
2929
"$ref": "#/definitions/ServicePublic"
3030
examples:
3131
application/json:
32-
department_name: dept
33-
organization_name: org
34-
service_id: 2b3e728c1a5d1efa035c
35-
service_name: service
32+
department_name: "IO"
33+
organization_fiscal_code: "00000000000"
34+
organization_name: "IO"
35+
service_id: "5a563817fcc896087002ea46c49a"
36+
service_name: "App IO"
3637
version: 1
3738
"401":
3839
description: Bearer token null or expired.
@@ -56,9 +57,9 @@ paths:
5657
$ref: "#/definitions/ServiceList"
5758
examples:
5859
application/json:
59-
page_size: 1
6060
items:
6161
- service_id: 2b3e728c1a5d1efa035c
62+
page_size: 1
6263
"401":
6364
description: Bearer token null or expired.
6465
"500":
@@ -79,6 +80,14 @@ paths:
7980
description: Found.
8081
schema:
8182
$ref: "#/definitions/ServiceList"
83+
examples:
84+
application/json:
85+
items:
86+
- service_id: "AzureDeployc49a"
87+
version: 1
88+
- service_id: "5a25abf4fcc89605c082f042c49a"
89+
version: 0
90+
page_size: 1
8291
"401":
8392
description: Bearer token null or expired.
8493
"500":
@@ -106,10 +115,16 @@ paths:
106115
examples:
107116
application/json:
108117
items:
109-
- id: 01BX9NSMKVXXS5PSP2FATZMYYY
110-
sender_service_id: "5a25abf4fcc89605c082f042c49a"
111-
- id: 01BX9NSMKVXXS5PSP2FATZM123
112-
sender_service_id: "5a25abf4fcc89605c082f042c49a"
118+
- created_at: "2018-05-21T07:36:41.209Z"
119+
fiscal_code: "LSSLCU79B24L219P"
120+
id: "01CE0T1Z18T3NT9ECK5NJ09YR3"
121+
sender_service_id: "5a563817fcc896087002ea46c49a"
122+
time_to_live: 3600
123+
- created_at: "2018-05-21T07:41:01.361Z"
124+
fiscal_code: "LSSLCU79B24L219P"
125+
id: "01CE0T9X1HT595GEF8FH9NRSW7"
126+
sender_service_id: "5a563817fcc896087002ea46c49a"
127+
time_to_live: 3600
113128
page_size: 2
114129
next: https://example.com/next
115130
"401":
@@ -139,18 +154,24 @@ paths:
139154
"200":
140155
description: Found.
141156
schema:
142-
$ref: "#/definitions/MessageWithContent"
157+
$ref: "#/definitions/CreatedMessageWithContent"
143158
examples:
144159
application/json:
145-
id: 01BX9NSMKAAAS5PSP2FATZM6BQ
146-
subject: message subject, aliquip sint nulla in estinut
147-
markdown: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas et mollis felis.
148-
Vivamus orci nisl, commodo ut sodales ut, eleifend a libero. Donec dapibus, turpis in mattis tempor,
149-
risus nunc malesuada ex, non aliquet metus nunc a lacus. Aenean in arcu vitae nisl porta
150-
fermentum nec non nibh. Phasellus tortor tellus, semper in metus eget, eleifend
151-
laoreet nibh. Aenean feugiat lectus ut nisl eleifend gravida.
152-
sender_service_id: "5a25abf4fcc89605c082f042c49a"
153-
created_at: "2018-05-21T12:45:41.105Z"
160+
message: {
161+
content: {
162+
markdown: "hey hey !! <a style=\"color: red\" href=\"http://example.com\"> some content here ..... this is a link with a style applied, some other content</a>",
163+
subject: "my subject ............"
164+
},
165+
created_at: "2018-06-06T12:22:24.523Z",
166+
fiscal_code: "LSSLCU79B24L219P",
167+
id: "01CFAGRMGB9XCA8B2CQ4QA7K76",
168+
sender_service_id: "5a25abf4fcc89605c082f042c49a",
169+
time_to_live: 3600
170+
}
171+
notification: {
172+
email: "SENT"
173+
}
174+
status: "PROCESSED"
154175
"401":
155176
description: Bearer token null or expired.
156177
"404":
@@ -176,16 +197,17 @@ paths:
176197
- $ref: "#/definitions/AuthenticatedProfile"
177198
examples:
178199
application/json:
200+
email: "email@example.com"
179201
family_name: "Rossi"
180202
fiscal_code: "TMMEXQ60A10Y526X"
181203
has_profile: true
182-
is_email_set: false
204+
is_email_set: true
183205
is_inbox_enabled: true
184-
is_webhook_enabled: false
206+
is_webhook_enabled: true
185207
name: "Mario"
186-
preferred_email: "preferred@example.com"
208+
spid_email: "preferred@example.com"
209+
spid_mobile_phone: "1234567890"
187210
version: 1
188-
email: "email@example.com"
189211
"401":
190212
description: Bearer token null or expired.
191213
"500":
@@ -215,10 +237,16 @@ paths:
215237
$ref: "#/definitions/InitializedProfile"
216238
examples:
217239
application/json:
218-
email: foobar@example.com
219-
preferred_languages: [ it_IT ]
240+
email: "email@example.com"
241+
family_name: "Rossi"
242+
fiscal_code: "TMMEXQ60A10Y526X"
243+
has_profile: true
244+
is_email_set: true
220245
is_inbox_enabled: true
221-
is_webhook_enabled: false
246+
is_webhook_enabled: true
247+
name: "Mario"
248+
spid_email: "preferred@example.com"
249+
spid_mobile_phone: "1234567890"
222250
version: 1
223251
'400':
224252
description: Invalid payload.
@@ -442,10 +470,12 @@ definitions:
442470
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/PaymentData"
443471
TimeToLiveSeconds:
444472
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/TimeToLiveSeconds"
445-
MessageWithContent:
473+
CreatedMessageWithContent:
446474
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/CreatedMessageWithContent"
447-
MessageWithoutContent:
475+
CreatedMessageWithoutContent:
448476
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/CreatedMessageWithoutContent"
477+
MessageResponseWithContent:
478+
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/MessageResponseWithContent"
449479
ServiceList:
450480
type: object
451481
title: List of services.
@@ -468,7 +498,7 @@ definitions:
468498
items:
469499
type: array
470500
items:
471-
$ref: "#/definitions/MessageWithoutContent"
501+
$ref: "#/definitions/CreatedMessageWithoutContent"
472502
next:
473503
type: string
474504
page_size:
@@ -495,29 +525,27 @@ definitions:
495525
properties:
496526
email:
497527
$ref: '#/definitions/EmailAddress'
528+
blocked_inbox_or_channels:
529+
$ref: "#/definitions/BlockedInboxOrChannels"
530+
preferred_languages:
531+
$ref: "#/definitions/PreferredLanguages"
532+
is_inbox_enabled:
533+
$ref: "#/definitions/IsInboxEnabled"
534+
is_webhook_enabled:
535+
$ref: "#/definitions/IsWebhookEnabled"
498536
family_name:
499537
type: string
500538
fiscal_code:
501539
$ref: '#/definitions/FiscalCode'
502540
has_profile:
503541
$ref: "#/definitions/HasProfile"
504-
is_inbox_enabled:
505-
$ref: "#/definitions/IsInboxEnabled"
506-
is_webhook_enabled:
507-
$ref: "#/definitions/IsWebhookEnabled"
508542
name:
509543
type: string
510544
spid_email:
511545
$ref: '#/definitions/EmailAddress'
512546
spid_mobile_phone:
513547
type: string
514548
minLength: 1
515-
preferred_languages:
516-
type: array
517-
items:
518-
$ref: '#/definitions/PreferredLanguage'
519-
blocked_inbox_or_channels:
520-
$ref: "#/definitions/BlockedInboxOrChannels"
521549
version:
522550
$ref: '#/definitions/Version'
523551
required:
@@ -601,6 +629,21 @@ definitions:
601629
description: |-
602630
The Push Notification Service handle for this Installation.
603631
See https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-registration-management
632+
Services:
633+
type: object
634+
title: A list of services
635+
properties:
636+
items:
637+
type: array
638+
items:
639+
$ref: "#/definitions/ServiceTuple"
640+
next:
641+
type: string
642+
page_size:
643+
$ref: '#/definitions/PageSize'
644+
required:
645+
- items
646+
- page_size
604647
SpidLevel:
605648
type: string
606649
description: A SPID level.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"prettify": "prettier --write \"./**/*.ts\"",
1717
"test": "jest -i",
1818
"start": "node src/server.js",
19-
"generate:api-client": "swagger-cli bundle https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.49.0/api/public_api_v1.yaml | autorest --typescript --input-file=/dev/stdin --output-folder=src/clients/api --add-credentials --use=@microsoft.azure/autorest.typescript@2.0.157",
20-
"generate:pagopa-client": "swagger-cli bundle https://raw.githubusercontent.com/teamdigitale/italia-pagopa-proxy/v0.5.12/api_pagopa.yaml | autorest --typescript --input-file=/dev/stdin --output-folder=src/clients/pagopa --use=@microsoft.azure/autorest.typescript@2.0.157",
2119
"generate:proxy-models": "npm-run-all generate:proxy:*",
2220
"generate:proxy:api-models": "gen-api-models --api-spec api_proxy.yaml --no-strict --out-dir src/types/api",
2321
"generate:proxy:notification-models": "gen-api-models --api-spec api_notifications.yaml --no-strict --out-dir src/types/api",
@@ -50,7 +48,7 @@
5048
"italia-ts-commons": "^2.12.3",
5149
"json-set-map": "^1.0.2",
5250
"morgan": "^1.9.1",
53-
"ms-rest-js": "^0.3.1",
51+
"node-fetch": "^2.2.0",
5452
"passport": "^0.4.0",
5553
"passport-auth-token": "^1.0.1",
5654
"passport-http-bearer": "^1.0.1",
@@ -77,6 +75,7 @@
7775
"@types/jest": "^23.3.2",
7876
"@types/lolex": "2.1.3",
7977
"@types/morgan": "^1.7.35",
78+
"@types/node-fetch": "^2.1.2",
8079
"@types/passport": "^0.4.6",
8180
"@types/passport-http-bearer": "^1.0.33",
8281
"@types/passport-strategy": "^0.2.35",
@@ -88,7 +87,6 @@
8887
"@types/validator": "^9.4.2",
8988
"@types/xml2js": "^0.4.3",
9089
"@types/xmldom": "^0.1.29",
91-
"autorest": "^2.0.4280",
9290
"danger": "^4.0.1",
9391
"danger-plugin-digitalcitizenship": "^0.3.1",
9492
"fp-ts": "^1.8.1",

public/message.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h1>Message</h1>
7575
response.json().then(function(data) {
7676
console.log(data);
7777

78-
fetch('./api/v1/services/' + data.sender_service_id, {
78+
fetch('./api/v1/services/' + data.message.sender_service_id, {
7979
headers: {
8080
'Authorization': 'Bearer ' + token
8181
},
@@ -97,10 +97,10 @@ <h1>Message</h1>
9797
console.log('Fetch Error :-S', err);
9898
});
9999

100-
$('#subject').append(data.subject);
101-
$('#markdown').append(data.markdown);
102-
$('#created_at').append(data.created_at);
103-
$('#sender_service_id').append(data.sender_service_id);
100+
$('#subject').append(data.message.content.subject);
101+
$('#markdown').append(data.message.content.markdown);
102+
$('#created_at').append(data.message.created_at);
103+
$('#sender_service_id').append(data.message.sender_service_id);
104104

105105
if(data.payment_data) {
106106
$('#amount').append(data.payment_data.amount);

scripts/generate-api-client.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/generate-pagopa-client.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)