@smapiot/piral-cloud-node 0.12.2-pre.20220801.2

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.
Files changed (3) hide show
  1. package/lib/index.d.ts +675 -0
  2. package/lib/index.js +6008 -0
  3. package/package.json +48 -0
package/lib/index.d.ts ADDED
@@ -0,0 +1,675 @@
1
+ declare module "@smapiot/piral-cloud-node" {
2
+ /**
3
+ * The options for creating a new service client.
4
+ */
5
+ export interface CreateServiceClientOptions {
6
+ /**
7
+ * Defines the host to talk to. Set this if you want to communicate
8
+ * with your own feed service instance.
9
+ * @default https://feed.piral.cloud
10
+ */
11
+ host?: string;
12
+ /**
13
+ * Defines the API key to use for making the HTTP calls. Needs
14
+ * to be provided.
15
+ */
16
+ apiKey: string;
17
+ }
18
+
19
+ /**
20
+ * Creates a new service client for use in Node.js-based applications.
21
+ * @param options The options for creating the client.
22
+ * @returns The created service client.
23
+ */
24
+ export function createServiceClient(options: CreateServiceClientOptions): FeedServiceApiClient;
25
+
26
+ export class FeedServiceApiClient {
27
+ constructor(private http: FetchClient, host?: string);
28
+ getUrl(path: string): string;
29
+ getEvents(): string;
30
+ getPilets(): Promise<Array<PiletMetadataDTO>>;
31
+ doAny<T>(path: string, init?: RequestInit): Promise<T>;
32
+ doGet<T>(path: string, init?: RequestInit): Promise<T>;
33
+ doPost<T>(path: string, content: any, init?: RequestInit): Promise<T>;
34
+ doPut<T>(path: string, content: any, init?: RequestInit): Promise<T>;
35
+ doDelete<T>(path: string, init?: RequestInit): Promise<T>;
36
+ doQueryFeeds(): Promise<FeedsDTO>;
37
+ doQueryFeed(feed: string): Promise<FeedDTO>;
38
+ doQueryPages(feed: string): Promise<PagesDTO>;
39
+ doPublishPage(feed: string, content: PagePublishDetails): Promise<unknown>;
40
+ doQueryAllPilets(feed: string, tag?: string, view?: "all" | "selected"): Promise<SelectedPiletsDTO>;
41
+ doQueryUploadedPilets(feed: string, name: string, offset?: string, count?: string): Promise<UploadedPiletsDTO>;
42
+ doPublishPilet(feed: string, tag: string, file: File): Promise<unknown>;
43
+ doQueryCurrentPilets(feed: string): Promise<Array<PiletMetadataDTO>>;
44
+ doQueryFeedExists(feed: string): Promise<FeedCheckDTO>;
45
+ doQueryApiKeyScopes(): Promise<ApiKeyScopesDTO>;
46
+ doQueryApiKeys(feed: string): Promise<ApiKeysDTO>;
47
+ doQueryFeedApiKeys(feed: string): Promise<ApiKeysDTO>;
48
+ doQueryGeneralApiKeys(): Promise<ApiKeysDTO>;
49
+ doQueryRules(feed: string): Promise<RulesDTO>;
50
+ doCreateFeed(content: FeedCreateDetails): Promise<unknown>;
51
+ doAddRule(feed: string, content: RuleCreateDetails): Promise<unknown>;
52
+ doGenerateApiKey(feed: string, content: ApiKeyCreateDetails): Promise<GeneratedApiKeyDTO>;
53
+ doGenerateFeedApiKey(feed: string, content: ApiKeyCreateDetails): Promise<GeneratedApiKeyDTO>;
54
+ doGenerateGeneralApiKey(content: ApiKeyCreateDetails): Promise<GeneratedApiKeyDTO>;
55
+ doDeleteFeed(feed: string): Promise<unknown>;
56
+ doRevokeGeneralApiKey(id: string): Promise<unknown>;
57
+ doRevokeApiKey(feed: string, id: string): Promise<unknown>;
58
+ doRevokeFeedApiKey(feed: string, id: string): Promise<unknown>;
59
+ doDeletePilet(feed: string, id: string): Promise<unknown>;
60
+ doDeleteRule(feed: string, id: string): Promise<unknown>;
61
+ doUpdateRule(feed: string, id: string, content: RuleUpdateDetails): Promise<unknown>;
62
+ doUpdatePilet(feed: string, id: string, content: PiletUpdateDetails): Promise<unknown>;
63
+ doUpdateFeed(feed: string, content: FeedUpdateDetails): Promise<unknown>;
64
+ doUpdateApiKey(feed: string, id: string, content: ApiKeyUpdateDetails): Promise<unknown>;
65
+ doUpdateFeedApiKey(feed: string, id: string, content: ApiKeyUpdateDetails): Promise<unknown>;
66
+ doUpdateGeneralApiKey(id: string, content: ApiKeyUpdateDetails): Promise<unknown>;
67
+ doQueryAudits(offset?: string, count?: string, areaName?: string, areaId?: string, objectId?: string, userId?: string): Promise<AuditsDTO>;
68
+ doQueryAudit(id: string): Promise<AuditDTO>;
69
+ doQueryAllUsers(q: string): Promise<AllUsersDTO>;
70
+ doQueryFeedContributors(feed: string): Promise<FeedContributorsDTO>;
71
+ doPutFeedContributors(feed: string, content: ContributorUpdateDetails): Promise<unknown>;
72
+ doQueryConfigs(feed: string, pilet: string): Promise<ConfigsDTO>;
73
+ doQueryConfig(feed: string, pilet: string, config: string): Promise<ConfigDTO>;
74
+ doAddConfig(feed: string, pilet: string, content: ConfigCreateDetails): Promise<unknown>;
75
+ doDeleteConfig(feed: string, pilet: string, config: string): Promise<unknown>;
76
+ doUpdateConfig(feed: string, pilet: string, config: string, content: ConfigUpdateDetails): Promise<unknown>;
77
+ doQueryEntities(feed: string): Promise<EntitiesDTO>;
78
+ doQueryEntity(feed: string, id: string): Promise<EntityDTO>;
79
+ doAddEntity(feed: string, content: EntityCreateDetails): Promise<unknown>;
80
+ doDeleteEntity(feed: string, id: string): Promise<EntityDTO>;
81
+ doUpdateEntity(feed: string, id: string, content: EntityUpdateDetails): Promise<unknown>;
82
+ doQueryUsers(): Promise<UsersDTO>;
83
+ doQueryUser(id: string): Promise<UserDTO>;
84
+ doAddUser(content: UserCreateDetails): Promise<ChangedUserDTO>;
85
+ doDeleteUser(id: string): Promise<UserDTO>;
86
+ doUpdateUser(id: string, content: UserUpdateDetails): Promise<ChangedUserDTO>;
87
+ doQueryCustomRules(): Promise<CustomRuleModulesDTO>;
88
+ doAddCustomRules(file: string, content: string): Promise<ChangedCustomRuleModuleDTO>;
89
+ doDeleteCustomRule(file: string): Promise<ChangedCustomRuleModuleDTO>;
90
+ doQueryCustomRuleDetails(file: string): Promise<CustomRuleDetailsDTO>;
91
+ doTestRule(feed: string, rule: string, content: TestRuleDetails): Promise<TestRuleResultDTO>;
92
+ doQueryCurrentUser(): Promise<CurrentUserDTO>;
93
+ doUpdateCurrentUser(content: CurrentUserUpdateDetails): Promise<ChangedUserDTO>;
94
+ doQueryStatus(ac?: AbortController): Promise<StatusDTO>;
95
+ doQueryStatistics(ac?: AbortController): Promise<StatisticsDTO>;
96
+ doQueryRulesSchema(ac?: AbortController): Promise<any>;
97
+ doQueryFeedAnalysis(feed: string, ac?: AbortController): Promise<FeedAnalysisDTO>;
98
+ doRecheckDomains(feed: string, domains: Array<string>, ac?: AbortController): Promise<unknown>;
99
+ doQueryFeedStatistics(feed: string, from: string, to: string, ac?: AbortController): Promise<FeedStatisticsDTO>;
100
+ doQueryAdminFeedStatistics(offset?: string, count?: string, ac?: AbortController): Promise<AdminStatisticsDTO>;
101
+ doQueryAdminFeedStatisticsDetails(feed: string, from: string, to: string, ac?: AbortController): Promise<AdminStatisticsDetailsDTO>;
102
+ doQueryNpmRegistry(feed: string, ac?: AbortController): Promise<NpmRegistryDTO>;
103
+ doQueryNpmPackage(feed: string, name: string, ac?: AbortController): Promise<NpmPackageDTO>;
104
+ doUploadNpmPackage(feed: string, name: string, body: any, ac?: AbortController): Promise<void>;
105
+ doDownloadFile(fileUrl: string, ac?: AbortController): Promise<Blob>;
106
+ }
107
+
108
+ export interface FetchClient {
109
+ getAuthorizationHeader(): Promise<string>;
110
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
111
+ Headers: {
112
+ new (init?: HeadersInit): Headers;
113
+ prototype: Headers;
114
+ };
115
+ FormData: {
116
+ new (form?: HTMLFormElement): FormData;
117
+ prototype: FormData;
118
+ };
119
+ }
120
+
121
+ export interface PiletMetadataDTO {
122
+ /**
123
+ * The name of the pilet, i.e., the package id.
124
+ */
125
+ name: string;
126
+ /**
127
+ * The version of the pilet. Should be semantically versioned.
128
+ */
129
+ version: string;
130
+ /**
131
+ * Provides the version of the specification for this pilet.
132
+ */
133
+ spec: string;
134
+ /**
135
+ * The reference name for the global require.
136
+ */
137
+ requireRef: string;
138
+ /**
139
+ * The computed integrity of the pilet.
140
+ */
141
+ integrity?: string;
142
+ /**
143
+ * The content of a v0 pilet. If the content is not available
144
+ * the link will be used (unless caching has been activated).
145
+ */
146
+ content?: string;
147
+ /**
148
+ * If available indicates that the pilet should not be cached.
149
+ * In case of a string this is interpreted as the expiration time
150
+ * of the cache. In case of an accurate hash this should not be
151
+ * required or set.
152
+ */
153
+ noCache?: boolean | string;
154
+ /**
155
+ * The computed hash value of the pilet's content. Should be
156
+ * accurate to allow caching.
157
+ */
158
+ hash?: string;
159
+ /**
160
+ * The link for retrieving the content of the pilet.
161
+ */
162
+ link: string;
163
+ /**
164
+ * Optionally provides some custom metadata for the pilet.
165
+ */
166
+ custom?: any;
167
+ /**
168
+ * Optionally provides some configuration to be used in the pilet.
169
+ */
170
+ config?: Record<string, any>;
171
+ /**
172
+ * Additional shared dependency script files.
173
+ */
174
+ dependencies?: Record<string, string>;
175
+ }
176
+
177
+ export interface FeedsDTO extends ApiData<FeedDTO> {
178
+ used: number;
179
+ maximum: number;
180
+ }
181
+
182
+ export type FeedDTO = ShortFeedDTO | FullFeedDTO;
183
+
184
+ export interface PagesDTO extends ApiData<PageDTO> {
185
+ feed: string;
186
+ }
187
+
188
+ export interface PagePublishDetails {
189
+ version: string;
190
+ type: "custom" | "none" | "docs" | "siteless";
191
+ embed: "yes" | "no";
192
+ options?: any;
193
+ files?: Array<[string, Blob]>;
194
+ }
195
+
196
+ export interface SelectedPiletsDTO extends ApiData<PiletDTO> {
197
+ enabled: Array<string>;
198
+ bundled: Array<string>;
199
+ feed: string;
200
+ tags: Array<string>;
201
+ }
202
+
203
+ export interface UploadedPiletsDTO extends ApiPaginatedData<PiletDTO> {}
204
+
205
+ export interface FeedCheckDTO {
206
+ exists: boolean;
207
+ self: boolean;
208
+ feed: string;
209
+ }
210
+
211
+ export interface ApiKeyScopesDTO extends ApiData<string> {
212
+ feedScopes: Array<string>;
213
+ generalScopes: Array<string>;
214
+ }
215
+
216
+ export interface ApiKeysDTO extends ApiData<ApiKeyDTO> {
217
+ feed: string;
218
+ }
219
+
220
+ export interface RulesDTO extends ApiData<RuleDTO> {
221
+ feed: string;
222
+ }
223
+
224
+ export interface FeedCreateDetails {
225
+ id: string;
226
+ description: string;
227
+ hosts?: Array<string>;
228
+ integrity?: boolean;
229
+ }
230
+
231
+ export interface RuleCreateDetails {
232
+ pilet: string;
233
+ description: string;
234
+ definition: any;
235
+ mode: "allow" | "block";
236
+ meta?: string;
237
+ }
238
+
239
+ export interface ApiKeyCreateDetails {
240
+ name: string;
241
+ description: string;
242
+ expires?: string;
243
+ constraints?: Array<string>;
244
+ scopes?: Array<string>;
245
+ }
246
+
247
+ export interface GeneratedApiKeyDTO {
248
+ feed: string;
249
+ id: string;
250
+ name: string;
251
+ description: string;
252
+ expires: string;
253
+ apiKey: string;
254
+ }
255
+
256
+ export interface RuleUpdateDetails {
257
+ description?: string;
258
+ order?: number;
259
+ definition?: any;
260
+ mode?: string;
261
+ meta?: string;
262
+ }
263
+
264
+ export interface PiletUpdateDetails {
265
+ selected?: boolean;
266
+ enabled?: boolean;
267
+ bundled?: boolean;
268
+ }
269
+
270
+ export interface FeedUpdateDetails {
271
+ description?: string;
272
+ hosts?: Array<string>;
273
+ active?: boolean;
274
+ hook?: string;
275
+ integrity?: boolean;
276
+ contributors?: Array<string>;
277
+ domains?: Array<string>;
278
+ sources?: Array<{
279
+ type: string;
280
+ source: string;
281
+ }>;
282
+ }
283
+
284
+ export interface ApiKeyUpdateDetails {
285
+ description?: string;
286
+ name?: string;
287
+ expires?: string;
288
+ }
289
+
290
+ export interface AuditsDTO extends ApiPaginatedData<AuditDTO> {}
291
+
292
+ export interface AuditDTO {
293
+ id: string;
294
+ userId: string;
295
+ time: string;
296
+ actionName: string;
297
+ areaName: string;
298
+ areaId: string;
299
+ objectId: string;
300
+ details: string;
301
+ }
302
+
303
+ export interface AllUsersDTO extends ApiData<ServiceUserDTO> {}
304
+
305
+ export interface FeedContributorsDTO extends ApiData<FeedContributorDTO> {
306
+ canEdit: boolean;
307
+ }
308
+
309
+ export interface ContributorUpdateDetails {
310
+ items: Array<{
311
+ id: string;
312
+ constraints: Array<string>;
313
+ }>;
314
+ }
315
+
316
+ export interface ConfigsDTO extends ApiData<ConfigDTO> {
317
+ feed: string;
318
+ pilet: string;
319
+ }
320
+
321
+ export interface ConfigDTO {
322
+ name: string;
323
+ value: any;
324
+ feed: string;
325
+ pilet: string;
326
+ created: string;
327
+ changed: string;
328
+ }
329
+
330
+ export interface ConfigCreateDetails {
331
+ name: string;
332
+ value: any;
333
+ }
334
+
335
+ export interface ConfigUpdateDetails {
336
+ value: any;
337
+ }
338
+
339
+ export interface EntitiesDTO extends ApiData<EntityDTO> {
340
+ feed: string;
341
+ }
342
+
343
+ export interface EntityDTO {
344
+ id: string;
345
+ feed: string;
346
+ type: string;
347
+ name: string;
348
+ pilet: string;
349
+ description: string;
350
+ order: number;
351
+ changed: string;
352
+ }
353
+
354
+ export interface EntityCreateDetails {
355
+ pilet: string;
356
+ name: string;
357
+ description: string;
358
+ type: string;
359
+ }
360
+
361
+ export interface EntityUpdateDetails {
362
+ description?: string;
363
+ order?: number;
364
+ }
365
+
366
+ export interface UsersDTO extends ApiData<UserDTO> {}
367
+
368
+ export interface UserDTO {
369
+ id: string;
370
+ name: string;
371
+ provider: string;
372
+ plan: string;
373
+ role: string;
374
+ created: string;
375
+ changed: string;
376
+ self: boolean;
377
+ }
378
+
379
+ export interface UserCreateDetails {
380
+ id: string;
381
+ provider: string;
382
+ name?: string;
383
+ plan?: string;
384
+ role?: string;
385
+ }
386
+
387
+ export interface ChangedUserDTO {
388
+ id: string;
389
+ passphrase: string;
390
+ success: boolean;
391
+ }
392
+
393
+ export interface UserUpdateDetails {
394
+ name?: string;
395
+ provider?: string;
396
+ plan?: string;
397
+ role?: string;
398
+ resetpass?: boolean;
399
+ }
400
+
401
+ export interface CustomRuleModulesDTO {
402
+ items: Array<CustomRuleModuleDTO>;
403
+ }
404
+
405
+ export interface ChangedCustomRuleModuleDTO {
406
+ success: boolean;
407
+ file: string;
408
+ rules: Array<string>;
409
+ }
410
+
411
+ export interface CustomRuleDetailsDTO {
412
+ file: string;
413
+ content: string;
414
+ rules?: Array<string>;
415
+ error?: string;
416
+ }
417
+
418
+ export interface TestRuleDetails {
419
+ headers: Record<string, string>;
420
+ query: Record<string, string>;
421
+ }
422
+
423
+ export interface TestRuleResultDTO {
424
+ result: boolean;
425
+ }
426
+
427
+ export interface CurrentUserDTO {
428
+ id: string;
429
+ name: string;
430
+ provider: string;
431
+ plan: string;
432
+ role: string;
433
+ created: string;
434
+ changed: string;
435
+ settings: Record<string, any>;
436
+ }
437
+
438
+ export interface CurrentUserUpdateDetails {
439
+ name?: string;
440
+ resetpass?: boolean;
441
+ oldPassword?: string;
442
+ newPassword?: string;
443
+ settings?: Record<string, any>;
444
+ }
445
+
446
+ export interface StatusDTO {
447
+ instanceId: string;
448
+ started: string;
449
+ status: "healthy" | "unhealthy";
450
+ modules: Array<string>;
451
+ healthy: boolean;
452
+ version: string;
453
+ requests: {
454
+ count: number;
455
+ avg: number;
456
+ };
457
+ ping: string;
458
+ }
459
+
460
+ export interface StatisticsDTO {
461
+ accounts: number;
462
+ apiKeys: number;
463
+ feeds: number;
464
+ piletAlls: number;
465
+ piletCurrents: number;
466
+ rules: number;
467
+ }
468
+
469
+ export interface FeedAnalysisDTO {
470
+ items: Array<{
471
+ name: string;
472
+ version: string;
473
+ spec: string;
474
+ report: {
475
+ dependencies: {
476
+ referenced: Array<{
477
+ name: string;
478
+ version: string;
479
+ distributed: boolean;
480
+ }>;
481
+ included: Array<{
482
+ name: string;
483
+ version: string;
484
+ href: string;
485
+ }>;
486
+ };
487
+ };
488
+ }>;
489
+ }
490
+
491
+ export interface FeedStatisticsDTO {
492
+ feedRequests: Array<FeedRequestsDTO>;
493
+ feedUserCountries: Array<FeedUserCountriesDTO>;
494
+ }
495
+
496
+ export interface AdminStatisticsDTO extends ApiPaginatedData<AdminStatisticsItemDTO> {}
497
+
498
+ export interface AdminStatisticsDetailsDTO {
499
+ feedRequests: Array<FeedRequestsDTO>;
500
+ feedUserCountries: Array<FeedUserCountriesDTO>;
501
+ feedContributors: number;
502
+ feedSources: number;
503
+ feedPilets: AdminStatisticsFeedPiletsDTO;
504
+ }
505
+
506
+ export interface NpmRegistryDTO extends ApiData<NpmItemDTO> {
507
+ feed: string;
508
+ }
509
+
510
+ export interface NpmPackageDTO {
511
+ _id: string;
512
+ name: string;
513
+ description: string;
514
+ "dist-tags": Record<string, string>;
515
+ versions: Record<string, {
516
+ name: string;
517
+ description: string;
518
+ version: string;
519
+ keywords: Array<string>;
520
+ readme: string;
521
+ _from: string;
522
+ _resolved: string;
523
+ _integrity: string;
524
+ _id: string;
525
+ _nodeVersion: string;
526
+ _npmVersion: string;
527
+ dist: {
528
+ integrity: string;
529
+ shasum: string;
530
+ tarball: string;
531
+ };
532
+ }>;
533
+ }
534
+
535
+ export interface ApiData<T> {
536
+ items: Array<T>;
537
+ }
538
+
539
+ export interface ShortFeedDTO extends BaseFeedDTO {
540
+ contributors: undefined;
541
+ targetFeeds: undefined;
542
+ sources: undefined;
543
+ }
544
+
545
+ export interface FullFeedDTO extends BaseFeedDTO {
546
+ _details: "all";
547
+ contributors: Array<string>;
548
+ targetFeeds: Array<string>;
549
+ sources: Array<{
550
+ type: string;
551
+ source: string;
552
+ }>;
553
+ domains: Array<string>;
554
+ invalidDomains: Array<string>;
555
+ newDomains: Array<string>;
556
+ }
557
+
558
+ export interface PageDTO {
559
+ feed: string;
560
+ type: "custom" | "siteless" | "none";
561
+ version: string;
562
+ active: boolean;
563
+ }
564
+
565
+ export interface PiletDTO {
566
+ id: string;
567
+ name: string;
568
+ version: string;
569
+ hash: string;
570
+ tag: string;
571
+ selected: boolean;
572
+ schema: PiletType;
573
+ canSetTag: boolean;
574
+ canBundle: boolean;
575
+ canDelete: boolean;
576
+ }
577
+
578
+ export interface ApiPaginatedData<T> {
579
+ items: Array<T>;
580
+ continuation: string;
581
+ }
582
+
583
+ export interface ApiKeyDTO {
584
+ id: string;
585
+ name: string;
586
+ description: string;
587
+ revoked: boolean;
588
+ expires: string;
589
+ scopes: Array<string>;
590
+ constraints: Array<string>;
591
+ }
592
+
593
+ export interface RuleDTO {
594
+ id: string;
595
+ order: number;
596
+ feed: string;
597
+ pilet: string;
598
+ description: string;
599
+ meta?: string;
600
+ mode: "allow" | "block";
601
+ definition: any;
602
+ }
603
+
604
+ export interface ServiceUserDTO {
605
+ id: string;
606
+ name: string;
607
+ }
608
+
609
+ export interface FeedContributorDTO {
610
+ id: string;
611
+ name: string;
612
+ verified: boolean;
613
+ constraints: Array<string>;
614
+ }
615
+
616
+ export interface CustomRuleModuleDTO {
617
+ file: string;
618
+ success: boolean;
619
+ source: "vs" | "fs";
620
+ rules?: Array<string>;
621
+ error?: string;
622
+ }
623
+
624
+ export interface FeedRequestsDTO {
625
+ count: number;
626
+ from: string;
627
+ to: string;
628
+ }
629
+
630
+ export interface FeedUserCountriesDTO {
631
+ name: string;
632
+ count: number;
633
+ }
634
+
635
+ export interface AdminStatisticsItemDTO {
636
+ id: string;
637
+ name: string;
638
+ owner: string;
639
+ enabled: boolean;
640
+ requestsToday: number;
641
+ requestsLastMonth: number;
642
+ }
643
+
644
+ export interface AdminStatisticsFeedPiletsDTO {
645
+ current: number;
646
+ all: number;
647
+ }
648
+
649
+ export interface NpmItemDTO {
650
+ feed: string;
651
+ id: string;
652
+ name: string;
653
+ version: string;
654
+ created: string;
655
+ }
656
+
657
+ export interface BaseFeedDTO {
658
+ id: string;
659
+ name: string;
660
+ account: string;
661
+ description: string;
662
+ active: boolean;
663
+ deleted: boolean;
664
+ integrity: boolean;
665
+ hook: string;
666
+ hosts: Array<string>;
667
+ owner: boolean;
668
+ canEdit: boolean;
669
+ canAddUser: boolean;
670
+ canDelete: boolean;
671
+ plan: string;
672
+ }
673
+
674
+ export type PiletType = "v0" | "v1" | "v2" | "oc" | "sspa" | "wmf";
675
+ }