platformatic 0.18.0 → 0.19.0

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/cli.js CHANGED
@@ -5,11 +5,13 @@ import minimist from 'minimist'
5
5
  import { runDB } from '@platformatic/db/db.mjs'
6
6
  import { runService } from '@platformatic/service/service.mjs'
7
7
  import { login } from '@platformatic/authenticate/authenticate.js'
8
+ import { command as client } from '@platformatic/client-cli'
8
9
  import { readFile } from 'fs/promises'
9
10
  import { join } from 'desm'
10
11
  import { isColorSupported } from 'colorette'
11
12
  import helpMe from 'help-me'
12
13
  import { upgrade } from './lib/upgrade.js'
14
+ import { gh } from './lib/gh.js'
13
15
 
14
16
  import { logo } from './lib/ascii.js'
15
17
 
@@ -36,10 +38,12 @@ const ensureCommand = async ({ output, help }) => {
36
38
  program.register('db', async (args) => ensureCommand(await runDB(args)))
37
39
  program.register('service', async (args) => ensureCommand(await runService(args)))
38
40
  program.register('upgrade', upgrade)
41
+ program.register('client', client)
39
42
  program.register('help', help.toStdout)
40
43
  program.register('help db', async (args) => runDB(['help', ...args]))
41
44
  program.register('help service', async (args) => runService(['help', ...args]))
42
45
  program.register({ command: 'login', strict: true }, login)
46
+ program.register('gh', gh)
43
47
 
44
48
  const args = minimist(process.argv.slice(2), {
45
49
  boolean: ['help', 'version'],
@@ -0,0 +1,1054 @@
1
+ {
2
+ "swagger": "2.0",
3
+ "info": {
4
+ "description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",
5
+ "version": "1.0.6",
6
+ "title": "Swagger Petstore",
7
+ "termsOfService": "http://swagger.io/terms/",
8
+ "contact": {
9
+ "email": "apiteam@swagger.io"
10
+ },
11
+ "license": {
12
+ "name": "Apache 2.0",
13
+ "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
14
+ }
15
+ },
16
+ "host": "petstore.swagger.io",
17
+ "basePath": "/v2",
18
+ "tags": [
19
+ {
20
+ "name": "pet",
21
+ "description": "Everything about your Pets",
22
+ "externalDocs": {
23
+ "description": "Find out more",
24
+ "url": "http://swagger.io"
25
+ }
26
+ },
27
+ {
28
+ "name": "store",
29
+ "description": "Access to Petstore orders"
30
+ },
31
+ {
32
+ "name": "user",
33
+ "description": "Operations about user",
34
+ "externalDocs": {
35
+ "description": "Find out more about our store",
36
+ "url": "http://swagger.io"
37
+ }
38
+ }
39
+ ],
40
+ "schemes": [
41
+ "https",
42
+ "http"
43
+ ],
44
+ "paths": {
45
+ "/pet/{petId}/uploadImage": {
46
+ "post": {
47
+ "tags": [
48
+ "pet"
49
+ ],
50
+ "summary": "uploads an image",
51
+ "description": "",
52
+ "operationId": "uploadFile",
53
+ "consumes": [
54
+ "multipart/form-data"
55
+ ],
56
+ "produces": [
57
+ "application/json"
58
+ ],
59
+ "parameters": [
60
+ {
61
+ "name": "petId",
62
+ "in": "path",
63
+ "description": "ID of pet to update",
64
+ "required": true,
65
+ "type": "integer",
66
+ "format": "int64"
67
+ },
68
+ {
69
+ "name": "additionalMetadata",
70
+ "in": "formData",
71
+ "description": "Additional data to pass to server",
72
+ "required": false,
73
+ "type": "string"
74
+ },
75
+ {
76
+ "name": "file",
77
+ "in": "formData",
78
+ "description": "file to upload",
79
+ "required": false,
80
+ "type": "file"
81
+ }
82
+ ],
83
+ "responses": {
84
+ "200": {
85
+ "description": "successful operation",
86
+ "schema": {
87
+ "$ref": "#/definitions/ApiResponse"
88
+ }
89
+ }
90
+ },
91
+ "security": [
92
+ {
93
+ "petstore_auth": [
94
+ "write:pets",
95
+ "read:pets"
96
+ ]
97
+ }
98
+ ]
99
+ }
100
+ },
101
+ "/pet": {
102
+ "post": {
103
+ "tags": [
104
+ "pet"
105
+ ],
106
+ "summary": "Add a new pet to the store",
107
+ "description": "",
108
+ "operationId": "addPet",
109
+ "consumes": [
110
+ "application/json",
111
+ "application/xml"
112
+ ],
113
+ "produces": [
114
+ "application/json",
115
+ "application/xml"
116
+ ],
117
+ "parameters": [
118
+ {
119
+ "in": "body",
120
+ "name": "body",
121
+ "description": "Pet object that needs to be added to the store",
122
+ "required": true,
123
+ "schema": {
124
+ "$ref": "#/definitions/Pet"
125
+ }
126
+ }
127
+ ],
128
+ "responses": {
129
+ "405": {
130
+ "description": "Invalid input"
131
+ }
132
+ },
133
+ "security": [
134
+ {
135
+ "petstore_auth": [
136
+ "write:pets",
137
+ "read:pets"
138
+ ]
139
+ }
140
+ ]
141
+ },
142
+ "put": {
143
+ "tags": [
144
+ "pet"
145
+ ],
146
+ "summary": "Update an existing pet",
147
+ "description": "",
148
+ "operationId": "updatePet",
149
+ "consumes": [
150
+ "application/json",
151
+ "application/xml"
152
+ ],
153
+ "produces": [
154
+ "application/json",
155
+ "application/xml"
156
+ ],
157
+ "parameters": [
158
+ {
159
+ "in": "body",
160
+ "name": "body",
161
+ "description": "Pet object that needs to be added to the store",
162
+ "required": true,
163
+ "schema": {
164
+ "$ref": "#/definitions/Pet"
165
+ }
166
+ }
167
+ ],
168
+ "responses": {
169
+ "400": {
170
+ "description": "Invalid ID supplied"
171
+ },
172
+ "404": {
173
+ "description": "Pet not found"
174
+ },
175
+ "405": {
176
+ "description": "Validation exception"
177
+ }
178
+ },
179
+ "security": [
180
+ {
181
+ "petstore_auth": [
182
+ "write:pets",
183
+ "read:pets"
184
+ ]
185
+ }
186
+ ]
187
+ }
188
+ },
189
+ "/pet/findByStatus": {
190
+ "get": {
191
+ "tags": [
192
+ "pet"
193
+ ],
194
+ "summary": "Finds Pets by status",
195
+ "description": "Multiple status values can be provided with comma separated strings",
196
+ "operationId": "findPetsByStatus",
197
+ "produces": [
198
+ "application/json",
199
+ "application/xml"
200
+ ],
201
+ "parameters": [
202
+ {
203
+ "name": "status",
204
+ "in": "query",
205
+ "description": "Status values that need to be considered for filter",
206
+ "required": true,
207
+ "type": "array",
208
+ "items": {
209
+ "type": "string",
210
+ "enum": [
211
+ "available",
212
+ "pending",
213
+ "sold"
214
+ ],
215
+ "default": "available"
216
+ },
217
+ "collectionFormat": "multi"
218
+ }
219
+ ],
220
+ "responses": {
221
+ "200": {
222
+ "description": "successful operation",
223
+ "schema": {
224
+ "type": "array",
225
+ "items": {
226
+ "$ref": "#/definitions/Pet"
227
+ }
228
+ }
229
+ },
230
+ "400": {
231
+ "description": "Invalid status value"
232
+ }
233
+ },
234
+ "security": [
235
+ {
236
+ "petstore_auth": [
237
+ "write:pets",
238
+ "read:pets"
239
+ ]
240
+ }
241
+ ]
242
+ }
243
+ },
244
+ "/pet/findByTags": {
245
+ "get": {
246
+ "tags": [
247
+ "pet"
248
+ ],
249
+ "summary": "Finds Pets by tags",
250
+ "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
251
+ "operationId": "findPetsByTags",
252
+ "produces": [
253
+ "application/json",
254
+ "application/xml"
255
+ ],
256
+ "parameters": [
257
+ {
258
+ "name": "tags",
259
+ "in": "query",
260
+ "description": "Tags to filter by",
261
+ "required": true,
262
+ "type": "array",
263
+ "items": {
264
+ "type": "string"
265
+ },
266
+ "collectionFormat": "multi"
267
+ }
268
+ ],
269
+ "responses": {
270
+ "200": {
271
+ "description": "successful operation",
272
+ "schema": {
273
+ "type": "array",
274
+ "items": {
275
+ "$ref": "#/definitions/Pet"
276
+ }
277
+ }
278
+ },
279
+ "400": {
280
+ "description": "Invalid tag value"
281
+ }
282
+ },
283
+ "security": [
284
+ {
285
+ "petstore_auth": [
286
+ "write:pets",
287
+ "read:pets"
288
+ ]
289
+ }
290
+ ],
291
+ "deprecated": true
292
+ }
293
+ },
294
+ "/pet/{petId}": {
295
+ "get": {
296
+ "tags": [
297
+ "pet"
298
+ ],
299
+ "summary": "Find pet by ID",
300
+ "description": "Returns a single pet",
301
+ "operationId": "getPetById",
302
+ "produces": [
303
+ "application/json",
304
+ "application/xml"
305
+ ],
306
+ "parameters": [
307
+ {
308
+ "name": "petId",
309
+ "in": "path",
310
+ "description": "ID of pet to return",
311
+ "required": true,
312
+ "type": "integer",
313
+ "format": "int64"
314
+ }
315
+ ],
316
+ "responses": {
317
+ "200": {
318
+ "description": "successful operation",
319
+ "schema": {
320
+ "$ref": "#/definitions/Pet"
321
+ }
322
+ },
323
+ "400": {
324
+ "description": "Invalid ID supplied"
325
+ },
326
+ "404": {
327
+ "description": "Pet not found"
328
+ }
329
+ },
330
+ "security": [
331
+ {
332
+ "api_key": []
333
+ }
334
+ ]
335
+ },
336
+ "post": {
337
+ "tags": [
338
+ "pet"
339
+ ],
340
+ "summary": "Updates a pet in the store with form data",
341
+ "description": "",
342
+ "operationId": "updatePetWithForm",
343
+ "consumes": [
344
+ "application/x-www-form-urlencoded"
345
+ ],
346
+ "produces": [
347
+ "application/json",
348
+ "application/xml"
349
+ ],
350
+ "parameters": [
351
+ {
352
+ "name": "petId",
353
+ "in": "path",
354
+ "description": "ID of pet that needs to be updated",
355
+ "required": true,
356
+ "type": "integer",
357
+ "format": "int64"
358
+ },
359
+ {
360
+ "name": "name",
361
+ "in": "formData",
362
+ "description": "Updated name of the pet",
363
+ "required": false,
364
+ "type": "string"
365
+ },
366
+ {
367
+ "name": "status",
368
+ "in": "formData",
369
+ "description": "Updated status of the pet",
370
+ "required": false,
371
+ "type": "string"
372
+ }
373
+ ],
374
+ "responses": {
375
+ "405": {
376
+ "description": "Invalid input"
377
+ }
378
+ },
379
+ "security": [
380
+ {
381
+ "petstore_auth": [
382
+ "write:pets",
383
+ "read:pets"
384
+ ]
385
+ }
386
+ ]
387
+ },
388
+ "delete": {
389
+ "tags": [
390
+ "pet"
391
+ ],
392
+ "summary": "Deletes a pet",
393
+ "description": "",
394
+ "operationId": "deletePet",
395
+ "produces": [
396
+ "application/json",
397
+ "application/xml"
398
+ ],
399
+ "parameters": [
400
+ {
401
+ "name": "api_key",
402
+ "in": "header",
403
+ "required": false,
404
+ "type": "string"
405
+ },
406
+ {
407
+ "name": "petId",
408
+ "in": "path",
409
+ "description": "Pet id to delete",
410
+ "required": true,
411
+ "type": "integer",
412
+ "format": "int64"
413
+ }
414
+ ],
415
+ "responses": {
416
+ "400": {
417
+ "description": "Invalid ID supplied"
418
+ },
419
+ "404": {
420
+ "description": "Pet not found"
421
+ }
422
+ },
423
+ "security": [
424
+ {
425
+ "petstore_auth": [
426
+ "write:pets",
427
+ "read:pets"
428
+ ]
429
+ }
430
+ ]
431
+ }
432
+ },
433
+ "/store/order": {
434
+ "post": {
435
+ "tags": [
436
+ "store"
437
+ ],
438
+ "summary": "Place an order for a pet",
439
+ "description": "",
440
+ "operationId": "placeOrder",
441
+ "consumes": [
442
+ "application/json"
443
+ ],
444
+ "produces": [
445
+ "application/json",
446
+ "application/xml"
447
+ ],
448
+ "parameters": [
449
+ {
450
+ "in": "body",
451
+ "name": "body",
452
+ "description": "order placed for purchasing the pet",
453
+ "required": true,
454
+ "schema": {
455
+ "$ref": "#/definitions/Order"
456
+ }
457
+ }
458
+ ],
459
+ "responses": {
460
+ "200": {
461
+ "description": "successful operation",
462
+ "schema": {
463
+ "$ref": "#/definitions/Order"
464
+ }
465
+ },
466
+ "400": {
467
+ "description": "Invalid Order"
468
+ }
469
+ }
470
+ }
471
+ },
472
+ "/store/order/{orderId}": {
473
+ "get": {
474
+ "tags": [
475
+ "store"
476
+ ],
477
+ "summary": "Find purchase order by ID",
478
+ "description": "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions",
479
+ "operationId": "getOrderById",
480
+ "produces": [
481
+ "application/json",
482
+ "application/xml"
483
+ ],
484
+ "parameters": [
485
+ {
486
+ "name": "orderId",
487
+ "in": "path",
488
+ "description": "ID of pet that needs to be fetched",
489
+ "required": true,
490
+ "type": "integer",
491
+ "maximum": 10,
492
+ "minimum": 1,
493
+ "format": "int64"
494
+ }
495
+ ],
496
+ "responses": {
497
+ "200": {
498
+ "description": "successful operation",
499
+ "schema": {
500
+ "$ref": "#/definitions/Order"
501
+ }
502
+ },
503
+ "400": {
504
+ "description": "Invalid ID supplied"
505
+ },
506
+ "404": {
507
+ "description": "Order not found"
508
+ }
509
+ }
510
+ },
511
+ "delete": {
512
+ "tags": [
513
+ "store"
514
+ ],
515
+ "summary": "Delete purchase order by ID",
516
+ "description": "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors",
517
+ "operationId": "deleteOrder",
518
+ "produces": [
519
+ "application/json",
520
+ "application/xml"
521
+ ],
522
+ "parameters": [
523
+ {
524
+ "name": "orderId",
525
+ "in": "path",
526
+ "description": "ID of the order that needs to be deleted",
527
+ "required": true,
528
+ "type": "integer",
529
+ "minimum": 1,
530
+ "format": "int64"
531
+ }
532
+ ],
533
+ "responses": {
534
+ "400": {
535
+ "description": "Invalid ID supplied"
536
+ },
537
+ "404": {
538
+ "description": "Order not found"
539
+ }
540
+ }
541
+ }
542
+ },
543
+ "/store/inventory": {
544
+ "get": {
545
+ "tags": [
546
+ "store"
547
+ ],
548
+ "summary": "Returns pet inventories by status",
549
+ "description": "Returns a map of status codes to quantities",
550
+ "operationId": "getInventory",
551
+ "produces": [
552
+ "application/json"
553
+ ],
554
+ "parameters": [],
555
+ "responses": {
556
+ "200": {
557
+ "description": "successful operation",
558
+ "schema": {
559
+ "type": "object",
560
+ "additionalProperties": {
561
+ "type": "integer",
562
+ "format": "int32"
563
+ }
564
+ }
565
+ }
566
+ },
567
+ "security": [
568
+ {
569
+ "api_key": []
570
+ }
571
+ ]
572
+ }
573
+ },
574
+ "/user/createWithArray": {
575
+ "post": {
576
+ "tags": [
577
+ "user"
578
+ ],
579
+ "summary": "Creates list of users with given input array",
580
+ "description": "",
581
+ "operationId": "createUsersWithArrayInput",
582
+ "consumes": [
583
+ "application/json"
584
+ ],
585
+ "produces": [
586
+ "application/json",
587
+ "application/xml"
588
+ ],
589
+ "parameters": [
590
+ {
591
+ "in": "body",
592
+ "name": "body",
593
+ "description": "List of user object",
594
+ "required": true,
595
+ "schema": {
596
+ "type": "array",
597
+ "items": {
598
+ "$ref": "#/definitions/User"
599
+ }
600
+ }
601
+ }
602
+ ],
603
+ "responses": {
604
+ "default": {
605
+ "description": "successful operation"
606
+ }
607
+ }
608
+ }
609
+ },
610
+ "/user/createWithList": {
611
+ "post": {
612
+ "tags": [
613
+ "user"
614
+ ],
615
+ "summary": "Creates list of users with given input array",
616
+ "description": "",
617
+ "operationId": "createUsersWithListInput",
618
+ "consumes": [
619
+ "application/json"
620
+ ],
621
+ "produces": [
622
+ "application/json",
623
+ "application/xml"
624
+ ],
625
+ "parameters": [
626
+ {
627
+ "in": "body",
628
+ "name": "body",
629
+ "description": "List of user object",
630
+ "required": true,
631
+ "schema": {
632
+ "type": "array",
633
+ "items": {
634
+ "$ref": "#/definitions/User"
635
+ }
636
+ }
637
+ }
638
+ ],
639
+ "responses": {
640
+ "default": {
641
+ "description": "successful operation"
642
+ }
643
+ }
644
+ }
645
+ },
646
+ "/user/{username}": {
647
+ "get": {
648
+ "tags": [
649
+ "user"
650
+ ],
651
+ "summary": "Get user by user name",
652
+ "description": "",
653
+ "operationId": "getUserByName",
654
+ "produces": [
655
+ "application/json",
656
+ "application/xml"
657
+ ],
658
+ "parameters": [
659
+ {
660
+ "name": "username",
661
+ "in": "path",
662
+ "description": "The name that needs to be fetched. Use user1 for testing. ",
663
+ "required": true,
664
+ "type": "string"
665
+ }
666
+ ],
667
+ "responses": {
668
+ "200": {
669
+ "description": "successful operation",
670
+ "schema": {
671
+ "$ref": "#/definitions/User"
672
+ }
673
+ },
674
+ "400": {
675
+ "description": "Invalid username supplied"
676
+ },
677
+ "404": {
678
+ "description": "User not found"
679
+ }
680
+ }
681
+ },
682
+ "put": {
683
+ "tags": [
684
+ "user"
685
+ ],
686
+ "summary": "Updated user",
687
+ "description": "This can only be done by the logged in user.",
688
+ "operationId": "updateUser",
689
+ "consumes": [
690
+ "application/json"
691
+ ],
692
+ "produces": [
693
+ "application/json",
694
+ "application/xml"
695
+ ],
696
+ "parameters": [
697
+ {
698
+ "name": "username",
699
+ "in": "path",
700
+ "description": "name that need to be updated",
701
+ "required": true,
702
+ "type": "string"
703
+ },
704
+ {
705
+ "in": "body",
706
+ "name": "body",
707
+ "description": "Updated user object",
708
+ "required": true,
709
+ "schema": {
710
+ "$ref": "#/definitions/User"
711
+ }
712
+ }
713
+ ],
714
+ "responses": {
715
+ "400": {
716
+ "description": "Invalid user supplied"
717
+ },
718
+ "404": {
719
+ "description": "User not found"
720
+ }
721
+ }
722
+ },
723
+ "delete": {
724
+ "tags": [
725
+ "user"
726
+ ],
727
+ "summary": "Delete user",
728
+ "description": "This can only be done by the logged in user.",
729
+ "operationId": "deleteUser",
730
+ "produces": [
731
+ "application/json",
732
+ "application/xml"
733
+ ],
734
+ "parameters": [
735
+ {
736
+ "name": "username",
737
+ "in": "path",
738
+ "description": "The name that needs to be deleted",
739
+ "required": true,
740
+ "type": "string"
741
+ }
742
+ ],
743
+ "responses": {
744
+ "400": {
745
+ "description": "Invalid username supplied"
746
+ },
747
+ "404": {
748
+ "description": "User not found"
749
+ }
750
+ }
751
+ }
752
+ },
753
+ "/user/login": {
754
+ "get": {
755
+ "tags": [
756
+ "user"
757
+ ],
758
+ "summary": "Logs user into the system",
759
+ "description": "",
760
+ "operationId": "loginUser",
761
+ "produces": [
762
+ "application/json",
763
+ "application/xml"
764
+ ],
765
+ "parameters": [
766
+ {
767
+ "name": "username",
768
+ "in": "query",
769
+ "description": "The user name for login",
770
+ "required": true,
771
+ "type": "string"
772
+ },
773
+ {
774
+ "name": "password",
775
+ "in": "query",
776
+ "description": "The password for login in clear text",
777
+ "required": true,
778
+ "type": "string"
779
+ }
780
+ ],
781
+ "responses": {
782
+ "200": {
783
+ "description": "successful operation",
784
+ "headers": {
785
+ "X-Expires-After": {
786
+ "type": "string",
787
+ "format": "date-time",
788
+ "description": "date in UTC when token expires"
789
+ },
790
+ "X-Rate-Limit": {
791
+ "type": "integer",
792
+ "format": "int32",
793
+ "description": "calls per hour allowed by the user"
794
+ }
795
+ },
796
+ "schema": {
797
+ "type": "string"
798
+ }
799
+ },
800
+ "400": {
801
+ "description": "Invalid username/password supplied"
802
+ }
803
+ }
804
+ }
805
+ },
806
+ "/user/logout": {
807
+ "get": {
808
+ "tags": [
809
+ "user"
810
+ ],
811
+ "summary": "Logs out current logged in user session",
812
+ "description": "",
813
+ "operationId": "logoutUser",
814
+ "produces": [
815
+ "application/json",
816
+ "application/xml"
817
+ ],
818
+ "parameters": [],
819
+ "responses": {
820
+ "default": {
821
+ "description": "successful operation"
822
+ }
823
+ }
824
+ }
825
+ },
826
+ "/user": {
827
+ "post": {
828
+ "tags": [
829
+ "user"
830
+ ],
831
+ "summary": "Create user",
832
+ "description": "This can only be done by the logged in user.",
833
+ "operationId": "createUser",
834
+ "consumes": [
835
+ "application/json"
836
+ ],
837
+ "produces": [
838
+ "application/json",
839
+ "application/xml"
840
+ ],
841
+ "parameters": [
842
+ {
843
+ "in": "body",
844
+ "name": "body",
845
+ "description": "Created user object",
846
+ "required": true,
847
+ "schema": {
848
+ "$ref": "#/definitions/User"
849
+ }
850
+ }
851
+ ],
852
+ "responses": {
853
+ "default": {
854
+ "description": "successful operation"
855
+ }
856
+ }
857
+ }
858
+ }
859
+ },
860
+ "securityDefinitions": {
861
+ "api_key": {
862
+ "type": "apiKey",
863
+ "name": "api_key",
864
+ "in": "header"
865
+ },
866
+ "petstore_auth": {
867
+ "type": "oauth2",
868
+ "authorizationUrl": "https://petstore.swagger.io/oauth/authorize",
869
+ "flow": "implicit",
870
+ "scopes": {
871
+ "read:pets": "read your pets",
872
+ "write:pets": "modify pets in your account"
873
+ }
874
+ }
875
+ },
876
+ "definitions": {
877
+ "ApiResponse": {
878
+ "type": "object",
879
+ "properties": {
880
+ "code": {
881
+ "type": "integer",
882
+ "format": "int32"
883
+ },
884
+ "type": {
885
+ "type": "string"
886
+ },
887
+ "message": {
888
+ "type": "string"
889
+ }
890
+ }
891
+ },
892
+ "Category": {
893
+ "type": "object",
894
+ "properties": {
895
+ "id": {
896
+ "type": "integer",
897
+ "format": "int64"
898
+ },
899
+ "name": {
900
+ "type": "string"
901
+ }
902
+ },
903
+ "xml": {
904
+ "name": "Category"
905
+ }
906
+ },
907
+ "Pet": {
908
+ "type": "object",
909
+ "required": [
910
+ "name",
911
+ "photoUrls"
912
+ ],
913
+ "properties": {
914
+ "id": {
915
+ "type": "integer",
916
+ "format": "int64"
917
+ },
918
+ "category": {
919
+ "$ref": "#/definitions/Category"
920
+ },
921
+ "name": {
922
+ "type": "string",
923
+ "example": "doggie"
924
+ },
925
+ "photoUrls": {
926
+ "type": "array",
927
+ "xml": {
928
+ "wrapped": true
929
+ },
930
+ "items": {
931
+ "type": "string",
932
+ "xml": {
933
+ "name": "photoUrl"
934
+ }
935
+ }
936
+ },
937
+ "tags": {
938
+ "type": "array",
939
+ "xml": {
940
+ "wrapped": true
941
+ },
942
+ "items": {
943
+ "xml": {
944
+ "name": "tag"
945
+ },
946
+ "$ref": "#/definitions/Tag"
947
+ }
948
+ },
949
+ "status": {
950
+ "type": "string",
951
+ "description": "pet status in the store",
952
+ "enum": [
953
+ "available",
954
+ "pending",
955
+ "sold"
956
+ ]
957
+ }
958
+ },
959
+ "xml": {
960
+ "name": "Pet"
961
+ }
962
+ },
963
+ "Tag": {
964
+ "type": "object",
965
+ "properties": {
966
+ "id": {
967
+ "type": "integer",
968
+ "format": "int64"
969
+ },
970
+ "name": {
971
+ "type": "string"
972
+ }
973
+ },
974
+ "xml": {
975
+ "name": "Tag"
976
+ }
977
+ },
978
+ "Order": {
979
+ "type": "object",
980
+ "properties": {
981
+ "id": {
982
+ "type": "integer",
983
+ "format": "int64"
984
+ },
985
+ "petId": {
986
+ "type": "integer",
987
+ "format": "int64"
988
+ },
989
+ "quantity": {
990
+ "type": "integer",
991
+ "format": "int32"
992
+ },
993
+ "shipDate": {
994
+ "type": "string",
995
+ "format": "date-time"
996
+ },
997
+ "status": {
998
+ "type": "string",
999
+ "description": "Order Status",
1000
+ "enum": [
1001
+ "placed",
1002
+ "approved",
1003
+ "delivered"
1004
+ ]
1005
+ },
1006
+ "complete": {
1007
+ "type": "boolean"
1008
+ }
1009
+ },
1010
+ "xml": {
1011
+ "name": "Order"
1012
+ }
1013
+ },
1014
+ "User": {
1015
+ "type": "object",
1016
+ "properties": {
1017
+ "id": {
1018
+ "type": "integer",
1019
+ "format": "int64"
1020
+ },
1021
+ "username": {
1022
+ "type": "string"
1023
+ },
1024
+ "firstName": {
1025
+ "type": "string"
1026
+ },
1027
+ "lastName": {
1028
+ "type": "string"
1029
+ },
1030
+ "email": {
1031
+ "type": "string"
1032
+ },
1033
+ "password": {
1034
+ "type": "string"
1035
+ },
1036
+ "phone": {
1037
+ "type": "string"
1038
+ },
1039
+ "userStatus": {
1040
+ "type": "integer",
1041
+ "format": "int32",
1042
+ "description": "User Status"
1043
+ }
1044
+ },
1045
+ "xml": {
1046
+ "name": "User"
1047
+ }
1048
+ }
1049
+ },
1050
+ "externalDocs": {
1051
+ "description": "Find out more about Swagger",
1052
+ "url": "http://swagger.io"
1053
+ }
1054
+ }
Binary file
package/help/gh.txt ADDED
@@ -0,0 +1,17 @@
1
+ Creates a gh action to deploy platformatic services on workspaces
2
+
3
+ ``` bash
4
+ $ platformatic gh -t dynamic
5
+ ```
6
+
7
+ Options:
8
+
9
+ -w --workspace ID The workspace ID where the service will be deployed
10
+ -t, --type static/dynamic The type of the workspace. Defaults to static.
11
+ -c, --config FILE Specify a configuration file to use
12
+ -b, --build Build the service before deploying (`npm run build`)
13
+
14
+ If not specified, the configuration will be loaded from `platformatic.db.json`,
15
+ `platformatic.db.yml`, or `platformatic.db.tml`, `platformatic.service.json`,
16
+ `platformatic.service.yml`, or `platformatic.service.tml` in the current directory.
17
+
package/help/help.txt CHANGED
@@ -5,3 +5,4 @@ Welcome to Platformatic. Available commands are:
5
5
  * db - start Platformatic DB; type `platformatic db help` to know more.
6
6
  * service - start Platformatic Service; type `platformatic service help` to know more.
7
7
  * upgrade - upgrade the Platformatic configuration to the latest version.
8
+ * gh - creates a new gh action for Platformatic deployments
package/lib/gh.js ADDED
@@ -0,0 +1,99 @@
1
+ import {
2
+ createStaticWorkspaceGHAction,
3
+ createDynamicWorkspaceGHAction
4
+ } from 'create-platformatic'
5
+
6
+ import parseArgs from 'minimist'
7
+ import { access } from 'fs/promises'
8
+ import pino from 'pino'
9
+ import pretty from 'pino-pretty'
10
+
11
+ export const createGHAction = async (logger, workspaceId, env, config, buildTS, type, projectDir = process.cwd()) => {
12
+ if (type === 'static') {
13
+ await createStaticWorkspaceGHAction(logger, workspaceId, env, config, projectDir, buildTS)
14
+ return
15
+ }
16
+ await createDynamicWorkspaceGHAction(logger, workspaceId, env, config, projectDir, buildTS)
17
+ }
18
+
19
+ const logger = pino(pretty({
20
+ translateTime: 'SYS:HH:MM:ss',
21
+ ignore: 'hostname,pid'
22
+ }))
23
+
24
+ const configFileNames = [
25
+ './platformatic.db.json',
26
+ './platformatic.db.json5',
27
+ './platformatic.db.yaml',
28
+ './platformatic.db.yml',
29
+ './platformatic.db.toml',
30
+ './platformatic.db.tml',
31
+ './platformatic.service.json',
32
+ './platformatic.service.json5',
33
+ './platformatic.service.yaml',
34
+ './platformatic.service.yml',
35
+ './platformatic.service.toml',
36
+ './platformatic.service.tml'
37
+ ]
38
+
39
+ async function isFileAccessible (filename) {
40
+ try {
41
+ await access(filename)
42
+ return true
43
+ } catch (err) {
44
+ return false
45
+ }
46
+ }
47
+
48
+ export const gh = async (argv) => {
49
+ const args = parseArgs(argv, {
50
+ default: {
51
+ type: 'static',
52
+ build: false
53
+ },
54
+ alias: {
55
+ config: 'c',
56
+ type: 't',
57
+ help: 'h',
58
+ build: 'b',
59
+ workspace: 'w'
60
+ },
61
+ boolean: ['build']
62
+ })
63
+
64
+ // Validations:
65
+ if (!args.workspace) {
66
+ logger.error('Workspace ID is required')
67
+ process.exit(1)
68
+ }
69
+
70
+ if (!['static', 'dynamic'].includes(args.type)) {
71
+ logger.error(`Invalid type: [${args.type}]. Type must be either static or dynamic`)
72
+ process.exit(1)
73
+ }
74
+
75
+ let configFilename = args.config
76
+ if (!configFilename) {
77
+ const configFilesAccessibility = await Promise.all(configFileNames.map((fileName) => isFileAccessible(fileName)))
78
+ configFilename = configFileNames.find((value, index) => configFilesAccessibility[index])
79
+ }
80
+
81
+ if (!configFilename) {
82
+ logger.error('No config file found')
83
+ process.exit(1)
84
+ }
85
+
86
+ if (await isFileAccessible('.env')) {
87
+ // We cannot add this automatically, because there might be credentials .env file
88
+ logger.info('Found .env file. If you need these variables in your GitHub Action, please add them to env: in "Deploy Project" step')
89
+ }
90
+
91
+ const env = {
92
+ plt_custom_variable: 'change-me',
93
+ custom_variable1: 'change-me'
94
+ }
95
+ await createGHAction(logger, args.workspace, env, configFilename, args.build, args.type)
96
+
97
+ const secretName = args.type === 'static' ? 'PLATFORMATIC_STATIC_WORKSPACE_API_KEY' : 'PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY'
98
+ logger.info(`Github action successfully created for workspace ${args.workspace}, please add ${secretName} as repository secret.`)
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "platformatic",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Platformatic CLI",
5
5
  "main": "cli.js",
6
6
  "type": "module",
@@ -30,6 +30,7 @@
30
30
  "c8": "^7.13.0",
31
31
  "execa": "^7.0.0",
32
32
  "license-checker": "^25.0.1",
33
+ "mkdirp": "^2.1.3",
33
34
  "snazzy": "^9.0.0",
34
35
  "split2": "^4.1.0",
35
36
  "standard": "^17.0.0",
@@ -42,10 +43,14 @@
42
43
  "desm": "^1.3.0",
43
44
  "help-me": "^4.2.0",
44
45
  "minimist": "^1.2.8",
45
- "@platformatic/db": "0.18.0",
46
- "@platformatic/authenticate": "0.18.0",
47
- "@platformatic/service": "0.18.0",
48
- "@platformatic/metaconfig": "0.18.0"
46
+ "pino": "^8.11.0",
47
+ "pino-pretty": "^10.0.0",
48
+ "@platformatic/authenticate": "0.19.0",
49
+ "@platformatic/db": "0.19.0",
50
+ "@platformatic/client-cli": "0.19.0",
51
+ "@platformatic/service": "0.19.0",
52
+ "@platformatic/metaconfig": "0.19.0",
53
+ "create-platformatic": "0.19.0"
49
54
  },
50
55
  "scripts": {
51
56
  "test": "standard | snazzy && c8 --100 tap --no-coverage test/*.test.js",
@@ -0,0 +1,110 @@
1
+ import { test } from 'tap'
2
+ import { tmpdir } from 'os'
3
+ import { execa } from 'execa'
4
+ import { cp, readFile, writeFile } from 'fs/promises'
5
+ import { cliPath } from './helper.js'
6
+ import { fileURLToPath } from 'url'
7
+ import { dirname, join } from 'path'
8
+ import mkdirp from 'mkdirp'
9
+
10
+ let count = 0
11
+ const workspaceId = 'WORKSPACE-ID-TEST'
12
+
13
+ test('creates a deploy config for static workspace', async (t) => {
14
+ const dest = join(tmpdir(), `test-cli-gh-${process.pid}-${count++}`)
15
+
16
+ await mkdirp(dest)
17
+ await cp(
18
+ join(dirname(fileURLToPath(import.meta.url)), 'fixtures', 'v0.16.0.db.json'),
19
+ join(dest, 'platformatic.db.json'))
20
+
21
+ await execa('node', [cliPath, 'gh', '-w', workspaceId], {
22
+ cwd: dest
23
+ })
24
+
25
+ const deployWorkflow = await readFile(join(dest, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml'), 'utf8')
26
+ t.ok(deployWorkflow.indexOf('PLATFORMATIC_STATIC_WORKSPACE_API_KEY') !== -1)
27
+ t.ok(deployWorkflow.indexOf('WORKSPACE-ID-TEST') !== -1)
28
+ })
29
+
30
+ test('creates a deploy config for dynamic workspace', async (t) => {
31
+ const dest = join(tmpdir(), `test-cli-gh-${process.pid}-${count++}`)
32
+
33
+ await mkdirp(dest)
34
+ await cp(
35
+ join(dirname(fileURLToPath(import.meta.url)), 'fixtures', 'v0.16.0.db.json'),
36
+ join(dest, 'platformatic.db.json'))
37
+
38
+ await execa('node', [cliPath, 'gh', '-w', workspaceId, '-t', 'dynamic'], {
39
+ cwd: dest
40
+ })
41
+
42
+ const deployWorkflow = await readFile(join(dest, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml'), 'utf8')
43
+ t.ok(deployWorkflow.indexOf('PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY') !== -1)
44
+ t.ok(deployWorkflow.indexOf('WORKSPACE-ID-TEST') !== -1)
45
+ })
46
+
47
+ test('creation fails if workspace is missing', async (t) => {
48
+ const dest = join(tmpdir(), `test-cli-gh-${process.pid}-${count++}`)
49
+
50
+ await mkdirp(dest)
51
+ await cp(
52
+ join(dirname(fileURLToPath(import.meta.url)), 'fixtures', 'v0.16.0.db.json'),
53
+ join(dest, 'platformatic.db.json'))
54
+
55
+ try {
56
+ await execa('node', [cliPath, 'gh'], {
57
+ cwd: dest
58
+ })
59
+ t.fail('should have failed')
60
+ } catch ({ stdout }) {
61
+ t.ok(stdout.indexOf('Workspace ID is required') !== -1)
62
+ }
63
+ })
64
+
65
+ test('creation fails if workspace type is not static or dynamic', async (t) => {
66
+ const dest = join(tmpdir(), `test-cli-gh-${process.pid}-${count++}`)
67
+
68
+ await mkdirp(dest)
69
+ await cp(
70
+ join(dirname(fileURLToPath(import.meta.url)), 'fixtures', 'v0.16.0.db.json'),
71
+ join(dest, 'platformatic.db.json'))
72
+
73
+ try {
74
+ await execa('node', [cliPath, 'gh', '-w', workspaceId, '-t', 'XXXXX'], {
75
+ cwd: dest
76
+ })
77
+ t.fail('should have failed')
78
+ } catch ({ stdout }) {
79
+ t.ok(stdout.indexOf('Type must be either static or dynamic') !== -1)
80
+ }
81
+ })
82
+
83
+ test('creation fails if no config file is found', async (t) => {
84
+ const dest = join(tmpdir(), `test-cli-gh-${process.pid}-${count++}`)
85
+ await mkdirp(dest)
86
+ try {
87
+ await execa('node', [cliPath, 'gh', '-w', workspaceId], {
88
+ cwd: dest
89
+ })
90
+ t.fail('should have failed')
91
+ } catch ({ stdout }) {
92
+ t.ok(stdout.indexOf('No config file found') !== -1)
93
+ }
94
+ })
95
+
96
+ test('creates a deploy must warn that a .env exists', async (t) => {
97
+ const dest = join(tmpdir(), `test-cli-gh-${process.pid}-${count++}`)
98
+
99
+ await mkdirp(dest)
100
+ await cp(
101
+ join(dirname(fileURLToPath(import.meta.url)), 'fixtures', 'v0.16.0.db.json'),
102
+ join(dest, 'platformatic.db.json'))
103
+
104
+ await writeFile(join(dest, '.env'), 'TEST=1')
105
+
106
+ const { stdout } = await execa('node', [cliPath, 'gh', '-w', workspaceId], {
107
+ cwd: dest
108
+ })
109
+ t.ok(stdout.indexOf('Found .env file') !== -1)
110
+ })