You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Belongs to the <a>WoT Producer</a> conformance class. Expects a |td:ThingDescription| argument and returns a {{Promise}} that resolves with an {{ExposedThing}} object that extends {{ConsumedThing}} with a server interface, i.e. the ability to define request handlers. The method MUST run the following steps:
491
+
Belongs to the <a>WoT Producer</a> conformance class. Expects a |init:ExposedThingInit| argument and returns a {{Promise}}
492
+
that resolves with an {{ExposedThing}} object that extends {{ConsumedThing}} with a server interface,
493
+
i.e. the ability to define request handlers. The |init:ExposedThingInit| object is an instance of the <a>ExposedThingInit</a> type.
494
+
Specifically, an <a>ExposedThingInit</a> value is a dictionary used for the initialization of an <a>ExposedThing</a> and
495
+
it represents a <a>Partial TD</a> as described in the [[!WOT-ARCHITECTURE]]. As such, it has the same
496
+
structure of a <a>Thing Description</a> but it may omit some information.
497
+
The method MUST run the following steps:
432
498
<ol>
433
499
<li>
434
500
Return a {{Promise}} |promise:Promise| and execute the next steps <a>in parallel</a>.
If invoking this method is not allowed for the current scripting context for security reasons, reject |promise| with a {{SecurityError}} and abort these steps.
438
504
</li>
439
505
<li>
440
-
Let |thing:ExposedThing| be a new {{ExposedThing}} object constructed with |td|.
506
+
Let |thing:ExposedThing| be a new {{ExposedThing}} object constructed with |init|.
441
507
</li>
442
508
<li>
443
509
Resolve |promise| with |thing|.
444
510
</li>
445
511
</ol>
446
512
</div>
513
+
<section>
514
+
<h3>Expand an ExposedThingInit</h3>
515
+
To <dfn>expand an ExposedThingInit</dfn> given |init:ExposedThingInit| and obtain a valid |td:ThingDescription| as
516
+
a result,
517
+
run the following steps:
518
+
<olclass="algorithm">
519
+
<li>Run <a>validate an ExposedThingInit</a> on |init|. If that fails,
520
+
[= exception/throw =] {{SyntaxError}} and abort these steps.</li>
521
+
<li>Initialize and empty object called |td|</li>
522
+
<li>
523
+
For each property |key| in |init| copy |key| and value of |key| to |td| recursively.
524
+
</li>
525
+
<li>For each |scheme:SecurityScheme| defined in <code>securityDefinitions</code> check if it is supported by at least one <a>Protocol Binding</a>.
526
+
If not remove scheme </li>
527
+
<li>if the value of <code>security</code> is defined but it is not contained in <code>securityDefinitions</code> remove
528
+
<code>security</code></li>
529
+
<li>For each |affordance| run the following sub-steps:
530
+
<ol>
531
+
<li>For each |form:Form| defined in |affordance| execute:
532
+
<ol>
533
+
<li>if |form|'s |contentType:string| is not recognized by the runtime as valid remove |contentType:string| from |form|
534
+
</li>
535
+
<li>if |form|'s |href:URL| has an unknown schema remove |href| from |form|.</li>
536
+
<li>if |form|'s |href:URL| is absolute and its <code>authority</code> it is not recognized by the runtime as a valid
537
+
remove |href| from |form|. </li>
538
+
<li>if |form|'s |href:URL| is already in use by other <a>ExposedThings</a> remove |href| from |form|.</li>
539
+
</ol>
540
+
</li>
541
+
</ol>
542
+
</li>
543
+
<li>Search for missing required properties in |td| accordingly to
<pclass="ednote">The editors find this step vague. It will be improved or removed in the next iteration. </p>
547
+
</li>
548
+
<li>For each |missing| property run these sub-steps:
549
+
<ol>
550
+
<li>If |missing| is <code>title</code> generate a runtime unique name and assign to <code>title</code>.</li>
551
+
<li>If |missing| is <code>@context</code> assign the latest supported Thing Description context URI.</li>
552
+
<li>If |missing| is <code>instance</code> assign the string <code>1.0.0</code>.</li>
553
+
<li>If |missing| is <code>forms</code> generate a list of <a>Forms</a> using the available <a>Protocol Bindings</a> and content types
554
+
encoders. Then assign the obtained list to <code>forms</code>.</li>
555
+
<li>If |missing| is <code>security</code> assign the label of the first supported <a>SecurityScheme</a> in <code>securityDefinitions</code> field.
556
+
If no <a>SecurityScheme</a> is found generate a <a>NoSecurityScheme</a> called <code>nosec</code> and assing the string <code>nosec</code>
557
+
to <code>security</code>.
558
+
<pclass="issue">The discussion about how to properly generate a value for <code>security</code> is still open.
559
+
See issue <ahref="https://github.com/w3c/wot-scripting-api/issues/299">#299</a></p>
560
+
</li>
561
+
<li>If |missing| is <code>href</code> define |formStub| as the partial <a>Form</a> that does not have <code>href</code>. Generate a valid |url:URL| using the first <a>Protocol Binding</a>
562
+
that satisfy the requirements of |formStub|. Assign |url| to <code>href</code>. If not <a>Protocol Binding</a> can be found remove |formStub| from |td|. </li>
563
+
<li>Add |missing| to |td| with |value| as value</li>
564
+
</ol>
565
+
</li>
566
+
<li>Run <a>validate a TD</a> on |td|. If that fails re-[= exception/throw =] the error and abort these steps</li>
567
+
<li>Return |td|</li>
568
+
</ol>
569
+
</section>
570
+
<section>
571
+
<h3>Validating an ExposedThingInit</h3>
572
+
To <dfn>validate an ExposedThingInit</dfn> given |init:ExposedThingInit|, run the following steps:
and load it in object called |exposedThingInitSchema:object|
578
+
</li>
579
+
<li>let |optional:Array| be a list containing the following strings: <code>title</code>, <code>@context</code>,
580
+
<code>instance</code>, <code>forms</code>, <code>security</code>, and <code>href</code>. </li>
581
+
<li>
582
+
For each property and sub-property |key| in |exposedThingInitSchema| equals to <code>required</code> execute the following steps:
583
+
<ol>
584
+
<li>if |key| |value| is an <code>Array</code> then remove all its elements equal to the elements in |optional|</li>
585
+
<li>if |key| |value| is a <code>string</code> then if |value| is equal to one of the elements in |optional| remove |key| from |exposedThingInitSchema|</li>
586
+
</ol>
587
+
</li>
588
+
<li>Return the result of <a>validating an object with JSON Schema</a> given |init| and |exposedThingInitSchema|.
589
+
<pclass="ednote">The<dfn>validating an object with JSON Schema</dfn> steps are still under discussion.
590
+
Currently this specification reference to the validation process of JSONSchema. Please
591
+
follow this <ahref="https://json-schema.org/draft/2019-09/json-schema-validation.html">document</a>
592
+
when validating |init| with |exposedThingInitSchema|. Notice that the working group is evaluating an alternative formal approach.
Before invoking <ahref="#dom-exposedthing-expose">expose()</a>, the {{ExposedThing}} object does not serve any requests. This allows first constructing {{ExposedThing}} and then initialize its <a>Properties</a> and service handlers before starting serving requests.
2113
2263
</p>
2114
2264
<div>
2115
-
To construct an {{ExposedThing}} with the {{ThingDescription}}
2116
-
|td:ThingDescription|, run the following steps:
2265
+
To construct an {{ExposedThing}} with the {{ExposedThingInit}}
2266
+
|init:ExposedThingInit|, run the following steps:
2117
2267
<ol>
2118
2268
<li>
2119
2269
If invoking this method is not allowed for the current scripting context for security reasons, [= exception/throw =] a {{SecurityError}} and abort these steps.
2120
2270
</li>
2271
+
<li>Run the <a>expand an ExposedThingInit</a> steps on |init|. if that fails re-[= exception/throw =] the error and abort these steps. Otherwise store the obtained |td:ThingDescription| </li>
2121
2272
<li>
2122
2273
Run the <a>expand a TD</a> steps on |td|. If that fails, re-[= exception/throw =] the error and abort these steps.
TODO: add more examples where the <a>ExposedThingInit</a> contains suggested values that are replaced by the algorithm.
3471
+
</p>
3269
3472
</section><!-- ExposedThing Examples -->
3270
3473
</section><!-- ExposedThing -->
3271
3474
@@ -3702,9 +3905,10 @@ <h3>Denial Of Service Security Risk</h3>
3702
3905
3703
3906
<section><h2>Terminology and conventions</h2>
3704
3907
<p>
3705
-
The generic WoT terminology is defined in [[!WOT-ARCHITECTURE]]: <dfndata-lt="Things">Thing</dfn>, <dfndata-lt="Thing Descriptions">Thing Description</dfn> (in short <dfn>TD</dfn>), <dfn>Web of Things</dfn> (in short <b><i>WoT</i></b>), <dfn>WoT Interface</dfn>, <dfn>Protocol Bindings</dfn>, <dfn>WoT Runtime</dfn>, <dfndata-lt="consume|consume a TD|consuming a TD">Consuming a Thing Description</dfn>, <dfn>Thing Directory</dfn>, <dfndata-lt="Properties">Property</dfn>, <dfndata-lt="Actions">Action</dfn>, <dfndata-lt="Events|WoT-Event">Event</dfn>,
3908
+
The generic WoT terminology is defined in [[!WOT-ARCHITECTURE]]: <dfndata-lt="Things">Thing</dfn>, <dfndata-lt="Thing Descriptions">Thing Description</dfn> (in short <dfn>TD</dfn>), <dfn>Partial TD</dfn>, <dfn>Web of Things</dfn> (in short <b><i>WoT</i></b>), <dfn>WoT Interface</dfn>, <dfn>Protocol Bindings</dfn>, <dfn>WoT Runtime</dfn>, <dfndata-lt="consume|consume a TD|consuming a TD">Consuming a Thing Description</dfn>, <dfn>Thing Directory</dfn>, <dfndata-lt="Properties">Property</dfn>, <dfndata-lt="Actions">Action</dfn>, <dfndata-lt="Events|WoT-Event">Event</dfn>,
<ahref="https://w3c.github.io/wot-thing-description/#securityscheme"><dfn>SecurityScheme</dfn></a>, <ahref="https://w3c.github.io/wot-thing-description/#nosecurityscheme"><dfn>NoSecurityScheme</dfn></a> etc.
3708
3912
</p>
3709
3913
<p>
3710
3914
<dfndata-plurals="WoT Interactions">WoT Interaction</dfn> is a synonym for <ahref="https://www.w3.org/TR/2020/WD-wot-architcture11-20201124/#dfn-interaction-affordance"><dfn>Interaction Affordance</dfn></a>.
0 commit comments