@amazon-devices/asset-resolver-lib 1.0.1767254403

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
2
+
3
+ These materials are licensed as "Program Materials" under the Program Materials License Agreement (the "Agreement"). The Agreement is available at https://developer.amazon.com/support/legal/pml. See the Agreement for the specific terms and conditions of the Agreement. Capitalized terms not defined in this file have the meanings given to them in the Agreement.
4
+
5
+ If you do not agree to the above terms and conditions, you may not use any file in this package.
6
+
7
+ YOUR USE OF THE PROGRAM MATERIALS IN OR ASSOCIATED WITH THIS PACKAGE IS AT YOUR SOLE RISK. IN NO EVENT WILL AMAZON BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL, INCIDENTAL, OR PUNITIVE DAMAGES (INCLUDING FOR ANY LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS OR DATA, OR COMPUTER FAILURE OR MALFUNCTION) ARISING FROM OR RELATING TO SUCH PROGRAM MATERIALS, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, EVEN IF AMAZON HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS AND DISCLAIMERS APPLY EXCEPT TO THE EXTENT PROHIBITED BY APPLICABLE LAW.
@@ -0,0 +1,76 @@
1
+ @amazon-devices/keplerscript-turbomodule-api
2
+ 1.0.0 <>
3
+ MIT License
4
+
5
+ Copyright (c) Meta Platforms, Inc. and its affiliates.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+
25
+ ******************************
26
+
27
+ @react-native/js-polyfills
28
+ 0.72.1 <https://github.com/facebook/react-native/tree/v0.72.1/packages/polyfills>
29
+ MIT License
30
+
31
+ Copyright (c) Meta Platforms, Inc. and affiliates.
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy
34
+ of this software and associated documentation files (the "Software"), to deal
35
+ in the Software without restriction, including without limitation the rights
36
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
+ copies of the Software, and to permit persons to whom the Software is
38
+ furnished to do so, subject to the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be included in all
41
+ copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49
+ SOFTWARE.
50
+
51
+ ******************************
52
+
53
+ @babel/runtime
54
+ 7.27.6 <https://github.com/babel/babel/tree/v7.27.6/packages/babel-runtime>
55
+ MIT License
56
+
57
+ Copyright (c) 2014-present Sebastian McKenzie and other contributors
58
+
59
+ Permission is hereby granted, free of charge, to any person obtaining
60
+ a copy of this software and associated documentation files (the
61
+ "Software"), to deal in the Software without restriction, including
62
+ without limitation the rights to use, copy, modify, merge, publish,
63
+ distribute, sublicense, and/or sell copies of the Software, and to
64
+ permit persons to whom the Software is furnished to do so, subject to
65
+ the following conditions:
66
+
67
+ The above copyright notice and this permission notice shall be
68
+ included in all copies or substantial portions of the Software.
69
+
70
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
71
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
73
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
74
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
75
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
76
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # AssetResolver
2
+
3
+ This document will serve as a user guide and will explain library installation (in a KSDK app) and
4
+ API usage.
5
+
6
+ ### Library Setup
7
+
8
+ 1. Update the package's `package.json` file to add the library as a dependency:
9
+
10
+ ```json
11
+ "dependencies": {
12
+ "@amazon-devices/asset-resolver-lib": "*"
13
+ }
14
+ ```
15
+
16
+ 1. With these changes, the AssetResolver turbo module can be consumed. To include the class and its
17
+ types, the following include line should be used:
18
+
19
+ ```js
20
+ import { AssetResolver, AssetType } from '@amazon-devices/asset-resolver-lib'
21
+ ```
22
+
23
+ ### Asset Resolution
24
+
25
+ As previously mentioned, AssetResolver turbo module is a wrapper for the AssetResolver Application
26
+ Framework library. The AssetResolver library provides applications a means of seamless asset
27
+ resolution whereby assets are ranked according to device system qualifiers.
28
+
29
+ Applications can contain assets which are files that can be used for things such as images and text.
30
+ Assets must be located in the application's `assets` directory, and the following directory
31
+ structure must be used for AssetResolver API use:
32
+
33
+ ```text
34
+ └── assets
35
+ ├── image
36
+ ├── raw
37
+ └── text
38
+ ```
39
+
40
+ These directories will hold asset files for images, raw files, and text-defining files,
41
+ respectively. These are the supported asset types in the AssetResolver.
42
+
43
+ For text localization, Asset Resolver expects text asset files to use the `puff.json` format for
44
+ defining string and numeric values.
45
+ [PUFF-J files](https://developer.amazon.com/docs/kepler-tv-api/internationalization-developer-guide.html)
46
+ define text resources used in an application and are used by Asset Resolver in its getString() and
47
+ getNumber() APIs.
48
+
49
+ ### Configuration Qualifiers
50
+
51
+ The AssetResolver's APIs resolve assets based on the system's current configuration qualifiers.
52
+ These are values which define certain device properties such as locale, UI mode, and so on.
53
+
54
+ For example, the qualifier locale can take values `en-US`, `es-AR`, or `es-SP`. This qualifier will
55
+ directly influence which assets are resolved.
56
+
57
+ ```text
58
+ └── assets
59
+ ├── image
60
+ ├── raw
61
+ └── text
62
+ ├── en
63
+ │   └── strings.puff.json
64
+ ├── en-US
65
+ │   └── strings.puff.json
66
+ ├── es
67
+ │   └── strings.puff.json
68
+ ├── es-AR
69
+ │   └── strings.puff.json
70
+ └── strings.puff.json
71
+ ```
72
+
73
+ In the above asset directory structure, the file `strings.puff.json` is defined in multiple
74
+ directories: one for each locale and one in `text` to act as a default. Depending on the current
75
+ system configuration qualifiers, the AssetResolver will resolve text based on the most appropriate
76
+ match; if there is none, the default file will be used.
77
+
78
+ **_NOTE_:** when an application supports a locale (such as `en-GB`), it **must** also define support
79
+ for that locale's default qualifier (in this case `en`).
80
+
81
+ **_NOTE_:** defining a default asset file is recommended as it ensures there is always an asset
82
+ matched in case asset resolution fails.
83
+
84
+ If the system configuration qualifier for locale is `es-AR`, then the file
85
+ `assets/text/es-AR/strings.puff.json` will be chosen when using the AssetResolver APIs. If multiple
86
+ locales contain the same text assets, symbolic links to a single asset file may be used to save
87
+ device storage space.
88
+
89
+ **_NOTE_:** only locale is supported as a configuration qualifier to resolve assets around.
90
+
91
+ ### Access Control
92
+
93
+ The AssetResolver APIs are not access-controlled. AssetResolver APIs only execute within an
94
+ application's subset of the device's filesystem. Moreover, other applications cannot explicitly
95
+ resolve assets from another application, ensuring app-to-app isolation.
96
+
97
+ ### Usage
98
+
99
+ The AssetResolver is an application library that allows retrieval of assets from packages. These
100
+ assets are resolved based on various system qualifiers such as locale, day/night mode, UI mode, etc.
101
+ Assets can be text-based, images, or raw files.
102
+
103
+ The AssetResolver turbo module provides various APIs which packages may use to retrieve asset values
104
+ as well as paths which will be demonstrated below.
105
+
106
+ #### AssetConfiguration type
107
+
108
+ Certain APIs take in an AssetConfiguration object. This object is used to specify which qualifiers
109
+ should be used when resolving assets. Currently locale is supported.
110
+
111
+ #### getString()
112
+
113
+ In order to retrieve an internationalized string value, the getString() API should be used. This
114
+ API takes in the identifier of the string being queried and an optional configuration object which
115
+ specifies which qualifiers should be used in asset resolution.
116
+
117
+ On failure, this API will throw an Error whose message indicates the error condition.
118
+
119
+ ```js
120
+ const stringResult = AssetResolver.getString("welcome-string");
121
+
122
+ console.log("string value: {}", stringResult.value);
123
+ console.log("string direction: {}", stringResult.dir);
124
+
125
+ const config = { locale: "fr-CA" };
126
+ const stringConfigResult = AssetResolver.getString("welcome-string", config);
127
+
128
+ console.log("string value: {}", stringConfigResult.value);
129
+ console.log("string direction: {}", stringConfigResult.dir);
130
+ ```
131
+
132
+ #### getNumber()
133
+
134
+ In order to retrieve an internationalized number value, the getNumber() API should be used. Similar
135
+ to getString(), this takes in a string which is the identifier for the number value being queried.
136
+ Furthermore, the API also takes in an optional configuration object which specifies which
137
+ qualifiers should be used in asset resolution.
138
+
139
+ This API similarly throws an Error if there is an issue in execution.
140
+
141
+ ```js
142
+ const numberResult = AssetResolver.getNumber("numeral");
143
+
144
+ console.log("number value: {}", numberResult);
145
+
146
+ const config = { locale: "en-US" };
147
+ const numberConfigResult = AssetResolver.getNumber("numeral", config);
148
+
149
+ console.log("number value: {}", numberConfigResult);
150
+ ```