Skip to content

Commit c0b3ff2

Browse files
authored
Merge pull request #230 from AdobeXD/shotts/xd35docs
Changes for XD 35
2 parents 3bf65cc + 2c4c96b commit c0b3ff2

File tree

5 files changed

+301
-0
lines changed

5 files changed

+301
-0
lines changed

SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
* [WebSocket](./reference/uxp/class/WebSocket.md)
5555
* [Storage APIs](./reference/uxp/storage-index.md)
5656
* [Storage module](./reference/uxp/module/storage.md)
57+
* [Local Storage](./reference/uxp/module/localStorage.md)
58+
* [Session Storage](./reference/uxp/module/sessionStorage.md)
59+
* [Secure Storage](./reference/uxp/module/secureStorage.md)
5760
* [Shell](./reference/uxp/class/Shell.md)
5861
* [OS](./reference/uxp/class/OS.md)
5962
* [UI APIs](./reference/uxp/ui-index.md)

reference/uxp/module/localStorage.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<a name="localstorage" id="localstorage"></a>
2+
3+
# window.localStorage
4+
Provides a local key-value store useful for setting preferences and other kinds of data.
5+
This data is technically persistent, but can be cleared in a variety of ways, so you should not
6+
store data using `localStorage` that you cannot otherwise reconstruct.
7+
8+
<InlineAlert variant="warning" slots="text"/>
9+
10+
Do not store passwords or other secure forms of data using `localStorage`. Instead, use [secureStorage](./secureStorage.md).
11+
12+
13+
14+
<a name="localstorage-length" id="localstorage-length"></a>
15+
16+
## length ⇒ `int`
17+
**Read only**
18+
Returns number of items stored in the local storage.
19+
20+
**Returns**: `int` - returns the number of items
21+
22+
23+
<a name="localstorage-key" id="localstorage-key"></a>
24+
25+
## key()
26+
Returns key which is stored at the given index
27+
28+
**Returns**: `int` - Returns key which is stored at the given index.
29+
30+
| Param | Type |
31+
| --- | --- |
32+
| index. | `number` |
33+
34+
35+
36+
<a name="localstorage-getitem" id="localstorage-getitem"></a>
37+
38+
## getItem(key)
39+
Get value from the local storage for the key.
40+
41+
**Returns**: `string` - returns value corresponding to the key as string. If key doesn't exist, this function returns null.
42+
43+
| Param | Type | Description |
44+
| --- | --- | --- |
45+
| key | `string` | A key to get value. |
46+
47+
48+
49+
<a name="localstorage-setitem" id="localstorage-setitem"></a>
50+
51+
## setItem(key, value)
52+
Set key and value to the local storage.
53+
If the key is newly set or value is different from old value, an update event will be fired later.
54+
55+
56+
| Param | Type | Description |
57+
| --- | --- | --- |
58+
| key | `string` | A key to set value |
59+
| value | `string` | A value for the key |
60+
61+
62+
63+
<a name="localstorage-removeitem" id="localstorage-removeitem"></a>
64+
65+
## removeItem(key)
66+
Remove a key/value pair from the local storage.
67+
If the key exists in the local storage, an update event will be fired later.
68+
69+
70+
| Param | Type | Description |
71+
| --- | --- | --- |
72+
| key | `string` | A key to set value |
73+
74+
75+
76+
<a name="localstorage-clear" id="localstorage-clear"></a>
77+
78+
## clear()
79+
Remove all key/value pairs from the local storage.
80+
An update event will be fired later.
81+
82+

reference/uxp/module/secureStorage.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<a name="securestorage" id="securestorage"></a>
2+
3+
# require('uxp').storage.secureStorage
4+
SecureStorage provides a protected storage which can be used to store sensitive data
5+
per plugin. SecureStorage takes a key-value pair and encrypts the value before being
6+
stored. After encryption, it stores the key and the encrypted value pair. When the value
7+
is requested with an associated key, it's retrieved after being decrypted. Please note
8+
that the key is not encrypted thus it's not protected by the cryptographic operation.
9+
10+
Caveats for SecureStorage are as follows:
11+
1. SecureStorage is not an appropriate storage for sensitive data which wants to keep
12+
secret from the current user. SecureStorage is protected under the current user's
13+
account credential. It means the encrypted data can be at risk of being decrypted
14+
with the current user's privilege.
15+
2. Data in SecureStorage can be lost for various reasons. For an example, the user
16+
could uninstall the host application and delete the secure storage. Or, the cryptographic
17+
information used by the secure storage could be damaged by the user accidentally, and
18+
it will result in loss of data without the secure storage being removed. SecureStorage
19+
should be regarded as a cache rather than a persistent storage. Data in SecureStorage
20+
should be able to be regenerated from plugins after the time of loss.
21+
22+
23+
24+
<a name="securestorage-length" id="securestorage-length"></a>
25+
26+
## length ⇒ `int`
27+
**Read only**
28+
Returns number of items stored in the secure storage.
29+
30+
**Returns**: `int` - returns the number of items
31+
32+
33+
<a name="securestorage-setitem" id="securestorage-setitem"></a>
34+
35+
## setItem(key, value)
36+
Store a key and value pair after the value is encrypted in a secure storage
37+
38+
**Returns**: `Promise` - : resolved when the value is stored. rejected when the value is empty or not stored.
39+
**Throws**:
40+
41+
- `TypeError` : thrown when either key or value doesn't have one of acceptable types.
42+
43+
44+
| Param | Type | Description |
45+
| --- | --- | --- |
46+
| key | `string` | : a key to set value |
47+
| value | `string` \| `ArrayBuffer` \| `TypedArray` | : a value for a key. |
48+
49+
50+
51+
<a name="securestorage-getitem" id="securestorage-getitem"></a>
52+
53+
## getItem(key)
54+
Retrieve a value associated with a provided key after the value is being decrypted from a secure storage.
55+
56+
**Returns**: `Promise.<Uint8Array>` - : a value as buffer
57+
**Throws**:
58+
59+
- `TypeError` : thrown when a key doesn't have an acceptable type.
60+
61+
62+
| Param | Type | Description |
63+
| --- | --- | --- |
64+
| key | `string` | : a key to get value |
65+
66+
67+
68+
<a name="securestorage-removeitem" id="securestorage-removeitem"></a>
69+
70+
## removeItem(key)
71+
Remove a value associated with a provided key
72+
73+
**Returns**: `Promise` - : resolved when the value associated with the key is removed. rejected when the value is neither removed nor found.
74+
**Throws**:
75+
76+
- `TypeError` : thrown when a key doesn't have an acceptable type.
77+
78+
79+
| Param | Type | Description |
80+
| --- | --- | --- |
81+
| key | `string` | : a key to remove value |
82+
83+
84+
85+
<a name="securestorage-key" id="securestorage-key"></a>
86+
87+
## key()
88+
Returns a key which is stored at the given index
89+
90+
**Returns**: `int` - Returns the key which is stored at the given index.
91+
92+
| Param | Type |
93+
| --- | --- |
94+
| index. | `number` |
95+
96+
97+
98+
<a name="securestorage-clear" id="securestorage-clear"></a>
99+
100+
## clear()
101+
Clear all values in a secure storage.
102+
103+
**Returns**: `Promise` - : resolved when all the items are cleared. rejected when there is no item to clear or clear failed.
104+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# window.sessionStorage
2+
3+
Provides a local key/value store useful for storing data that persists only for the plugin's current session.
4+
5+
For more information about the API itself, see the [localStorage](./localStorage.md) API.

reference/uxp/module/storage.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
* [.getPluginFolder()](#module-storage-filesystemprovider-getpluginfolder)`Promise.<Folder>`
4040
* [.getFsUrl(entry)](#module-storage-filesystemprovider-getfsurl)`URL`
4141
* [.getNativePath(entry)](#module-storage-filesystemprovider-getnativepath)`string`
42+
* [.createSessionToken(entry)](#module-storage-filesystemprovider-createsessiontoken)`string`
43+
* [.getEntryForSessionToken(token)](#module-storage-filesystemprovider-getentryforsessiontoken)`Entry`
44+
* [.createPersistentToken(entry)](#module-storage-filesystemprovider-createpersistenttoken)`Promise<string>`
45+
* [.getEntryForPersistentToken(token)](#module-storage-filesystemprovider-getentryforpersistenttoken)`Promise<Entry>`
4246
* [.Folder](#module-storage-folder)`Entry`
4347
* [.getEntries()](#module-storage-folder-getentries)`Promise.<Array.<Entry>>`
4448
* [.createFile(name, options)](#module-storage-folder-createfile)`Promise.<File>`
@@ -638,6 +642,109 @@ Returns the platform native file system path of given entry.
638642
| --- | --- |
639643
| entry | `Entry` |
640644
645+
<a name="module-storage-filesystemprovider-createsessiontoken" id="module-storage-filesystemprovider-createsessiontoken"></a>
646+
647+
### createSessionToken(entry)
648+
Returns a token suitable for use with certain host-specific APIs. This
649+
token is valid only for the current plugin session. As such, it is of no use if you
650+
serialize the token to persistent storage, as the token will be invalid in the future.
651+
652+
**Returns**: `string` - the session token for the given entry
653+
654+
| Param | Type |
655+
| --- | --- |
656+
| entry | `Entry` |
657+
658+
**Example**
659+
```js
660+
const fs = require('uxp').storage.localFileSystem;
661+
let entry = await fs.getFileForOpening();
662+
let token = fs.createSessionToken(entry);
663+
```
664+
665+
666+
<a name="module-storage-filesystemprovider-getentryforsessiontoken" id="module-storage-filesystemprovider-getentryforsessiontoken"></a>
667+
668+
### getEntryForSessionToken(token)
669+
Returns the file system Entry that corresponds to the session token obtained from
670+
`createSessionToken`. If an entry cannot be found that matches the token, then a
671+
`Reference Error: token is not defined` error is thrown.
672+
673+
**Returns**: `Entry` - the corresponding entry for the session token
674+
675+
| Param | Type |
676+
| --- | --- |
677+
| token | `string` |
678+
679+
680+
681+
<a name="module-storage-filesystemprovider-createpersistenttoken" id="module-storage-filesystemprovider-createpersistenttoken"></a>
682+
683+
### createPersistentToken(entry)
684+
Returns a token suitable for use with host-specific APIs (such as Xd), or
685+
for storing a persistent reference to an entry (useful if you want to only ask for
686+
permission to access a file or folder once). A persistent token is not guaranteed
687+
to last forever -- certain scenarios can cause the token to longer work (including
688+
moving files, changing permissions, or OS-specific limitations). If a persistent
689+
token cannot be reused, you'll get an error at the time of use.
690+
691+
**Returns**: `string` - the persistent token for the given entry
692+
693+
| Param | Type |
694+
| --- | --- |
695+
| entry | `Entry` |
696+
697+
**Example**
698+
```js
699+
const fs = require('uxp').storage.localFileSystem;
700+
let entry = await fs.getFileForOpening();
701+
let token = fs.createPersistentToken(entry);
702+
localStorage.setItem("persistent-file", token);
703+
```
704+
705+
706+
<a name="module-storage-filesystemprovider-getentryforpersistenttoken" id="module-storage-filesystemprovider-getentryforpersistenttoken"></a>
707+
708+
### getEntryForPersistentToken(token)
709+
Returns the file system Entry that corresponds to the persistent token obtained from
710+
`createPersistentToken`. If an entry cannot be found that matches the token, then a
711+
`Reference Error: token is not defined` error is thrown.
712+
713+
> Retrieving an entry for a persistent token does _not_ guarantee that the
714+
entry is valid for use. You'll need to properly handle the case where the entry no
715+
longer exists on the disk, or the permissions have changed by catching the appropriate
716+
errors. If that occurs, the suggested practice is to prompt the user for the entry
717+
again and store the new token.
718+
719+
**Returns**: `Entry` - the corresponding entry for the persistent token
720+
721+
| Param | Type |
722+
| --- | --- |
723+
| token | `string` |
724+
725+
**Example**
726+
```js
727+
const fs = require('uxp').storage.localFileSystem;
728+
let entry, contents, tries = 3, success = false;
729+
while (tries > 0) {
730+
try {
731+
entry = await fs.getEntryForPersistentToken(localStorage.getItem("persistent-file"));
732+
contents = await entry.read();
733+
tries = 0;
734+
success = true;
735+
} catch (err) {
736+
entry = await fs.getFileForOpening();
737+
localStorage.setItem("persistent-token", await fs.createPersistentToken(entry));
738+
tries--;
739+
}
740+
}
741+
if (!success) {
742+
// fail gracefully somehow
743+
}
744+
```
745+
746+
747+
641748
642749
<a name="module-storage-folder" id="module-storage-folder"></a>
643750

0 commit comments

Comments
 (0)