@scaleway/sdk-iot 1.0.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.
@@ -0,0 +1,532 @@
1
+ import randomName from "@scaleway/random-name";
2
+ import { resolveOneOf, isJSONObject, unmarshalDate, unmarshalArrayOfObject, unmarshalTimeSeries } from "@scaleway/sdk-client";
3
+ const unmarshalDeviceMessageFiltersRule = (data) => {
4
+ if (!isJSONObject(data)) {
5
+ throw new TypeError(
6
+ `Unmarshalling the type 'DeviceMessageFiltersRule' failed as data isn't a dictionary.`
7
+ );
8
+ }
9
+ return {
10
+ policy: data.policy,
11
+ topics: data.topics
12
+ };
13
+ };
14
+ const unmarshalDeviceMessageFilters = (data) => {
15
+ if (!isJSONObject(data)) {
16
+ throw new TypeError(
17
+ `Unmarshalling the type 'DeviceMessageFilters' failed as data isn't a dictionary.`
18
+ );
19
+ }
20
+ return {
21
+ publish: data.publish ? unmarshalDeviceMessageFiltersRule(data.publish) : void 0,
22
+ subscribe: data.subscribe ? unmarshalDeviceMessageFiltersRule(data.subscribe) : void 0
23
+ };
24
+ };
25
+ const unmarshalDevice = (data) => {
26
+ if (!isJSONObject(data)) {
27
+ throw new TypeError(
28
+ `Unmarshalling the type 'Device' failed as data isn't a dictionary.`
29
+ );
30
+ }
31
+ return {
32
+ allowInsecure: data.allow_insecure,
33
+ allowMultipleConnections: data.allow_multiple_connections,
34
+ createdAt: unmarshalDate(data.created_at),
35
+ description: data.description,
36
+ hasCustomCertificate: data.has_custom_certificate,
37
+ hubId: data.hub_id,
38
+ id: data.id,
39
+ isConnected: data.is_connected,
40
+ lastActivityAt: unmarshalDate(data.last_activity_at),
41
+ messageFilters: data.message_filters ? unmarshalDeviceMessageFilters(data.message_filters) : void 0,
42
+ name: data.name,
43
+ status: data.status,
44
+ updatedAt: unmarshalDate(data.updated_at)
45
+ };
46
+ };
47
+ const unmarshalNetwork = (data) => {
48
+ if (!isJSONObject(data)) {
49
+ throw new TypeError(
50
+ `Unmarshalling the type 'Network' failed as data isn't a dictionary.`
51
+ );
52
+ }
53
+ return {
54
+ createdAt: unmarshalDate(data.created_at),
55
+ endpoint: data.endpoint,
56
+ hubId: data.hub_id,
57
+ id: data.id,
58
+ name: data.name,
59
+ topicPrefix: data.topic_prefix,
60
+ type: data.type
61
+ };
62
+ };
63
+ const unmarshalHubTwinsGraphiteConfig = (data) => {
64
+ if (!isJSONObject(data)) {
65
+ throw new TypeError(
66
+ `Unmarshalling the type 'HubTwinsGraphiteConfig' failed as data isn't a dictionary.`
67
+ );
68
+ }
69
+ return {
70
+ pushUri: data.push_uri
71
+ };
72
+ };
73
+ const unmarshalHub = (data) => {
74
+ if (!isJSONObject(data)) {
75
+ throw new TypeError(
76
+ `Unmarshalling the type 'Hub' failed as data isn't a dictionary.`
77
+ );
78
+ }
79
+ return {
80
+ connectedDeviceCount: data.connected_device_count,
81
+ createdAt: unmarshalDate(data.created_at),
82
+ deviceCount: data.device_count,
83
+ disableEvents: data.disable_events,
84
+ enableDeviceAutoProvisioning: data.enable_device_auto_provisioning,
85
+ enabled: data.enabled,
86
+ endpoint: data.endpoint,
87
+ eventsTopicPrefix: data.events_topic_prefix,
88
+ hasCustomCa: data.has_custom_ca,
89
+ id: data.id,
90
+ name: data.name,
91
+ organizationId: data.organization_id,
92
+ productPlan: data.product_plan,
93
+ projectId: data.project_id,
94
+ region: data.region,
95
+ status: data.status,
96
+ twinsGraphiteConfig: data.twins_graphite_config ? unmarshalHubTwinsGraphiteConfig(data.twins_graphite_config) : void 0,
97
+ updatedAt: unmarshalDate(data.updated_at)
98
+ };
99
+ };
100
+ const unmarshalCertificate = (data) => {
101
+ if (!isJSONObject(data)) {
102
+ throw new TypeError(
103
+ `Unmarshalling the type 'Certificate' failed as data isn't a dictionary.`
104
+ );
105
+ }
106
+ return {
107
+ crt: data.crt,
108
+ key: data.key
109
+ };
110
+ };
111
+ const unmarshalCreateDeviceResponse = (data) => {
112
+ if (!isJSONObject(data)) {
113
+ throw new TypeError(
114
+ `Unmarshalling the type 'CreateDeviceResponse' failed as data isn't a dictionary.`
115
+ );
116
+ }
117
+ return {
118
+ certificate: data.certificate ? unmarshalCertificate(data.certificate) : void 0,
119
+ device: data.device ? unmarshalDevice(data.device) : void 0
120
+ };
121
+ };
122
+ const unmarshalCreateNetworkResponse = (data) => {
123
+ if (!isJSONObject(data)) {
124
+ throw new TypeError(
125
+ `Unmarshalling the type 'CreateNetworkResponse' failed as data isn't a dictionary.`
126
+ );
127
+ }
128
+ return {
129
+ network: data.network ? unmarshalNetwork(data.network) : void 0,
130
+ secret: data.secret
131
+ };
132
+ };
133
+ const unmarshalGetDeviceCertificateResponse = (data) => {
134
+ if (!isJSONObject(data)) {
135
+ throw new TypeError(
136
+ `Unmarshalling the type 'GetDeviceCertificateResponse' failed as data isn't a dictionary.`
137
+ );
138
+ }
139
+ return {
140
+ certificatePem: data.certificate_pem,
141
+ device: data.device ? unmarshalDevice(data.device) : void 0
142
+ };
143
+ };
144
+ const unmarshalGetDeviceMetricsResponse = (data) => {
145
+ if (!isJSONObject(data)) {
146
+ throw new TypeError(
147
+ `Unmarshalling the type 'GetDeviceMetricsResponse' failed as data isn't a dictionary.`
148
+ );
149
+ }
150
+ return {
151
+ metrics: unmarshalArrayOfObject(data.metrics, unmarshalTimeSeries)
152
+ };
153
+ };
154
+ const unmarshalGetHubCAResponse = (data) => {
155
+ if (!isJSONObject(data)) {
156
+ throw new TypeError(
157
+ `Unmarshalling the type 'GetHubCAResponse' failed as data isn't a dictionary.`
158
+ );
159
+ }
160
+ return {
161
+ caCertPem: data.ca_cert_pem
162
+ };
163
+ };
164
+ const unmarshalGetHubMetricsResponse = (data) => {
165
+ if (!isJSONObject(data)) {
166
+ throw new TypeError(
167
+ `Unmarshalling the type 'GetHubMetricsResponse' failed as data isn't a dictionary.`
168
+ );
169
+ }
170
+ return {
171
+ metrics: unmarshalArrayOfObject(data.metrics, unmarshalTimeSeries)
172
+ };
173
+ };
174
+ const unmarshalListDevicesResponse = (data) => {
175
+ if (!isJSONObject(data)) {
176
+ throw new TypeError(
177
+ `Unmarshalling the type 'ListDevicesResponse' failed as data isn't a dictionary.`
178
+ );
179
+ }
180
+ return {
181
+ devices: unmarshalArrayOfObject(data.devices, unmarshalDevice),
182
+ totalCount: data.total_count
183
+ };
184
+ };
185
+ const unmarshalListHubsResponse = (data) => {
186
+ if (!isJSONObject(data)) {
187
+ throw new TypeError(
188
+ `Unmarshalling the type 'ListHubsResponse' failed as data isn't a dictionary.`
189
+ );
190
+ }
191
+ return {
192
+ hubs: unmarshalArrayOfObject(data.hubs, unmarshalHub),
193
+ totalCount: data.total_count
194
+ };
195
+ };
196
+ const unmarshalListNetworksResponse = (data) => {
197
+ if (!isJSONObject(data)) {
198
+ throw new TypeError(
199
+ `Unmarshalling the type 'ListNetworksResponse' failed as data isn't a dictionary.`
200
+ );
201
+ }
202
+ return {
203
+ networks: unmarshalArrayOfObject(data.networks, unmarshalNetwork),
204
+ totalCount: data.total_count
205
+ };
206
+ };
207
+ const unmarshalRouteSummary = (data) => {
208
+ if (!isJSONObject(data)) {
209
+ throw new TypeError(
210
+ `Unmarshalling the type 'RouteSummary' failed as data isn't a dictionary.`
211
+ );
212
+ }
213
+ return {
214
+ createdAt: unmarshalDate(data.created_at),
215
+ hubId: data.hub_id,
216
+ id: data.id,
217
+ name: data.name,
218
+ topic: data.topic,
219
+ type: data.type,
220
+ updatedAt: unmarshalDate(data.updated_at)
221
+ };
222
+ };
223
+ const unmarshalListRoutesResponse = (data) => {
224
+ if (!isJSONObject(data)) {
225
+ throw new TypeError(
226
+ `Unmarshalling the type 'ListRoutesResponse' failed as data isn't a dictionary.`
227
+ );
228
+ }
229
+ return {
230
+ routes: unmarshalArrayOfObject(data.routes, unmarshalRouteSummary),
231
+ totalCount: data.total_count
232
+ };
233
+ };
234
+ const unmarshalListTwinDocumentsResponseDocumentSummary = (data) => {
235
+ if (!isJSONObject(data)) {
236
+ throw new TypeError(
237
+ `Unmarshalling the type 'ListTwinDocumentsResponseDocumentSummary' failed as data isn't a dictionary.`
238
+ );
239
+ }
240
+ return {
241
+ documentName: data.document_name
242
+ };
243
+ };
244
+ const unmarshalListTwinDocumentsResponse = (data) => {
245
+ if (!isJSONObject(data)) {
246
+ throw new TypeError(
247
+ `Unmarshalling the type 'ListTwinDocumentsResponse' failed as data isn't a dictionary.`
248
+ );
249
+ }
250
+ return {
251
+ documents: unmarshalArrayOfObject(
252
+ data.documents,
253
+ unmarshalListTwinDocumentsResponseDocumentSummary
254
+ )
255
+ };
256
+ };
257
+ const unmarshalRenewDeviceCertificateResponse = (data) => {
258
+ if (!isJSONObject(data)) {
259
+ throw new TypeError(
260
+ `Unmarshalling the type 'RenewDeviceCertificateResponse' failed as data isn't a dictionary.`
261
+ );
262
+ }
263
+ return {
264
+ certificate: data.certificate ? unmarshalCertificate(data.certificate) : void 0,
265
+ device: data.device ? unmarshalDevice(data.device) : void 0
266
+ };
267
+ };
268
+ const unmarshalRouteDatabaseConfig = (data) => {
269
+ if (!isJSONObject(data)) {
270
+ throw new TypeError(
271
+ `Unmarshalling the type 'RouteDatabaseConfig' failed as data isn't a dictionary.`
272
+ );
273
+ }
274
+ return {
275
+ dbname: data.dbname,
276
+ engine: data.engine,
277
+ host: data.host,
278
+ password: data.password,
279
+ port: data.port,
280
+ query: data.query,
281
+ username: data.username
282
+ };
283
+ };
284
+ const unmarshalRouteRestConfig = (data) => {
285
+ if (!isJSONObject(data)) {
286
+ throw new TypeError(
287
+ `Unmarshalling the type 'RouteRestConfig' failed as data isn't a dictionary.`
288
+ );
289
+ }
290
+ return {
291
+ headers: data.headers,
292
+ uri: data.uri,
293
+ verb: data.verb
294
+ };
295
+ };
296
+ const unmarshalRouteS3Config = (data) => {
297
+ if (!isJSONObject(data)) {
298
+ throw new TypeError(
299
+ `Unmarshalling the type 'RouteS3Config' failed as data isn't a dictionary.`
300
+ );
301
+ }
302
+ return {
303
+ bucketName: data.bucket_name,
304
+ bucketRegion: data.bucket_region,
305
+ objectPrefix: data.object_prefix,
306
+ strategy: data.strategy
307
+ };
308
+ };
309
+ const unmarshalRoute = (data) => {
310
+ if (!isJSONObject(data)) {
311
+ throw new TypeError(
312
+ `Unmarshalling the type 'Route' failed as data isn't a dictionary.`
313
+ );
314
+ }
315
+ return {
316
+ createdAt: unmarshalDate(data.created_at),
317
+ dbConfig: data.db_config ? unmarshalRouteDatabaseConfig(data.db_config) : void 0,
318
+ hubId: data.hub_id,
319
+ id: data.id,
320
+ name: data.name,
321
+ restConfig: data.rest_config ? unmarshalRouteRestConfig(data.rest_config) : void 0,
322
+ s3Config: data.s3_config ? unmarshalRouteS3Config(data.s3_config) : void 0,
323
+ topic: data.topic,
324
+ type: data.type,
325
+ updatedAt: unmarshalDate(data.updated_at)
326
+ };
327
+ };
328
+ const unmarshalSetDeviceCertificateResponse = (data) => {
329
+ if (!isJSONObject(data)) {
330
+ throw new TypeError(
331
+ `Unmarshalling the type 'SetDeviceCertificateResponse' failed as data isn't a dictionary.`
332
+ );
333
+ }
334
+ return {
335
+ certificatePem: data.certificate_pem,
336
+ device: data.device ? unmarshalDevice(data.device) : void 0
337
+ };
338
+ };
339
+ const unmarshalTwinDocument = (data) => {
340
+ if (!isJSONObject(data)) {
341
+ throw new TypeError(
342
+ `Unmarshalling the type 'TwinDocument' failed as data isn't a dictionary.`
343
+ );
344
+ }
345
+ return {
346
+ data: data.data,
347
+ documentName: data.document_name,
348
+ twinId: data.twin_id,
349
+ version: data.version
350
+ };
351
+ };
352
+ const marshalDeviceMessageFiltersRule = (request, defaults) => ({
353
+ policy: request.policy,
354
+ topics: request.topics
355
+ });
356
+ const marshalDeviceMessageFilters = (request, defaults) => ({
357
+ publish: request.publish !== void 0 ? marshalDeviceMessageFiltersRule(request.publish) : void 0,
358
+ subscribe: request.subscribe !== void 0 ? marshalDeviceMessageFiltersRule(request.subscribe) : void 0
359
+ });
360
+ const marshalCreateDeviceRequest = (request, defaults) => ({
361
+ allow_insecure: request.allowInsecure,
362
+ allow_multiple_connections: request.allowMultipleConnections,
363
+ description: request.description,
364
+ hub_id: request.hubId,
365
+ message_filters: request.messageFilters !== void 0 ? marshalDeviceMessageFilters(request.messageFilters) : void 0,
366
+ name: request.name || randomName("device")
367
+ });
368
+ const marshalHubTwinsGraphiteConfig = (request, defaults) => ({
369
+ push_uri: request.pushUri
370
+ });
371
+ const marshalCreateHubRequest = (request, defaults) => ({
372
+ disable_events: request.disableEvents,
373
+ events_topic_prefix: request.eventsTopicPrefix,
374
+ name: request.name || randomName("hub"),
375
+ product_plan: request.productPlan,
376
+ project_id: request.projectId ?? defaults.defaultProjectId,
377
+ ...resolveOneOf([
378
+ {
379
+ param: "twins_graphite_config",
380
+ value: request.twinsGraphiteConfig !== void 0 ? marshalHubTwinsGraphiteConfig(request.twinsGraphiteConfig) : void 0
381
+ }
382
+ ])
383
+ });
384
+ const marshalCreateNetworkRequest = (request, defaults) => ({
385
+ hub_id: request.hubId,
386
+ name: request.name || randomName("network"),
387
+ topic_prefix: request.topicPrefix,
388
+ type: request.type
389
+ });
390
+ const marshalCreateRouteRequestDatabaseConfig = (request, defaults) => ({
391
+ dbname: request.dbname,
392
+ engine: request.engine,
393
+ host: request.host,
394
+ password: request.password,
395
+ port: request.port,
396
+ query: request.query,
397
+ username: request.username
398
+ });
399
+ const marshalCreateRouteRequestRestConfig = (request, defaults) => ({
400
+ headers: request.headers,
401
+ uri: request.uri,
402
+ verb: request.verb
403
+ });
404
+ const marshalCreateRouteRequestS3Config = (request, defaults) => ({
405
+ bucket_name: request.bucketName,
406
+ bucket_region: request.bucketRegion,
407
+ object_prefix: request.objectPrefix,
408
+ strategy: request.strategy
409
+ });
410
+ const marshalCreateRouteRequest = (request, defaults) => ({
411
+ hub_id: request.hubId,
412
+ name: request.name || randomName("route"),
413
+ topic: request.topic,
414
+ ...resolveOneOf([
415
+ {
416
+ param: "s3_config",
417
+ value: request.s3Config !== void 0 ? marshalCreateRouteRequestS3Config(request.s3Config) : void 0
418
+ },
419
+ {
420
+ param: "db_config",
421
+ value: request.dbConfig !== void 0 ? marshalCreateRouteRequestDatabaseConfig(request.dbConfig) : void 0
422
+ },
423
+ {
424
+ param: "rest_config",
425
+ value: request.restConfig !== void 0 ? marshalCreateRouteRequestRestConfig(request.restConfig) : void 0
426
+ }
427
+ ])
428
+ });
429
+ const marshalPatchTwinDocumentRequest = (request, defaults) => ({
430
+ data: request.data,
431
+ version: request.version
432
+ });
433
+ const marshalPutTwinDocumentRequest = (request, defaults) => ({
434
+ data: request.data,
435
+ version: request.version
436
+ });
437
+ const marshalSetDeviceCertificateRequest = (request, defaults) => ({
438
+ certificate_pem: request.certificatePem
439
+ });
440
+ const marshalSetHubCARequest = (request, defaults) => ({
441
+ ca_cert_pem: request.caCertPem,
442
+ challenge_cert_pem: request.challengeCertPem
443
+ });
444
+ const marshalUpdateDeviceRequest = (request, defaults) => ({
445
+ allow_insecure: request.allowInsecure,
446
+ allow_multiple_connections: request.allowMultipleConnections,
447
+ description: request.description,
448
+ hub_id: request.hubId,
449
+ message_filters: request.messageFilters !== void 0 ? marshalDeviceMessageFilters(request.messageFilters) : void 0
450
+ });
451
+ const marshalUpdateHubRequest = (request, defaults) => ({
452
+ disable_events: request.disableEvents,
453
+ enable_device_auto_provisioning: request.enableDeviceAutoProvisioning,
454
+ events_topic_prefix: request.eventsTopicPrefix,
455
+ name: request.name,
456
+ product_plan: request.productPlan,
457
+ ...resolveOneOf([
458
+ {
459
+ param: "twins_graphite_config",
460
+ value: request.twinsGraphiteConfig !== void 0 ? marshalHubTwinsGraphiteConfig(request.twinsGraphiteConfig) : void 0
461
+ }
462
+ ])
463
+ });
464
+ const marshalUpdateRouteRequestDatabaseConfig = (request, defaults) => ({
465
+ dbname: request.dbname,
466
+ engine: request.engine,
467
+ host: request.host,
468
+ password: request.password,
469
+ port: request.port,
470
+ query: request.query,
471
+ username: request.username
472
+ });
473
+ const marshalUpdateRouteRequestRestConfig = (request, defaults) => ({
474
+ headers: request.headers,
475
+ uri: request.uri,
476
+ verb: request.verb
477
+ });
478
+ const marshalUpdateRouteRequestS3Config = (request, defaults) => ({
479
+ bucket_name: request.bucketName,
480
+ bucket_region: request.bucketRegion,
481
+ object_prefix: request.objectPrefix,
482
+ strategy: request.strategy
483
+ });
484
+ const marshalUpdateRouteRequest = (request, defaults) => ({
485
+ name: request.name,
486
+ topic: request.topic,
487
+ ...resolveOneOf([
488
+ {
489
+ param: "s3_config",
490
+ value: request.s3Config !== void 0 ? marshalUpdateRouteRequestS3Config(request.s3Config) : void 0
491
+ },
492
+ {
493
+ param: "db_config",
494
+ value: request.dbConfig !== void 0 ? marshalUpdateRouteRequestDatabaseConfig(request.dbConfig) : void 0
495
+ },
496
+ {
497
+ param: "rest_config",
498
+ value: request.restConfig !== void 0 ? marshalUpdateRouteRequestRestConfig(request.restConfig) : void 0
499
+ }
500
+ ])
501
+ });
502
+ export {
503
+ marshalCreateDeviceRequest,
504
+ marshalCreateHubRequest,
505
+ marshalCreateNetworkRequest,
506
+ marshalCreateRouteRequest,
507
+ marshalPatchTwinDocumentRequest,
508
+ marshalPutTwinDocumentRequest,
509
+ marshalSetDeviceCertificateRequest,
510
+ marshalSetHubCARequest,
511
+ marshalUpdateDeviceRequest,
512
+ marshalUpdateHubRequest,
513
+ marshalUpdateRouteRequest,
514
+ unmarshalCreateDeviceResponse,
515
+ unmarshalCreateNetworkResponse,
516
+ unmarshalDevice,
517
+ unmarshalGetDeviceCertificateResponse,
518
+ unmarshalGetDeviceMetricsResponse,
519
+ unmarshalGetHubCAResponse,
520
+ unmarshalGetHubMetricsResponse,
521
+ unmarshalHub,
522
+ unmarshalListDevicesResponse,
523
+ unmarshalListHubsResponse,
524
+ unmarshalListNetworksResponse,
525
+ unmarshalListRoutesResponse,
526
+ unmarshalListTwinDocumentsResponse,
527
+ unmarshalNetwork,
528
+ unmarshalRenewDeviceCertificateResponse,
529
+ unmarshalRoute,
530
+ unmarshalSetDeviceCertificateResponse,
531
+ unmarshalTwinDocument
532
+ };