saasufy-components 3.21.1 → 3.23.0
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/README.md +23 -0
- package/oauth-handler.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ You can apply custom CSS/styling to elements that are rendered inside a viewport
|
|
|
56
56
|
|
|
57
57
|
To use a component, you just need to include the relevant `<script>` tag into the `<head>` tag of your `.html` file.
|
|
58
58
|
You can simply copy-paste the script tag provided under the `Import` section of the relevant component's documentation.
|
|
59
|
+
Make sure that you read the documentation carefully; especially the list of available attributes and acceptable values for each component.
|
|
59
60
|
|
|
60
61
|
You should only add the script tags for the components which your page uses to avoid wasting bandwidth and unnecessarily delaying page load for your users.
|
|
61
62
|
You should always include the `socket.js` script and create a top-level `socket-provider` component if you intend to use components which depend on data from Saasufy.
|
|
@@ -86,6 +87,27 @@ The following utility functions can be used anywhere inside template `{{expressi
|
|
|
86
87
|
- Format UNIX timestamp as a human-readable date: `{{date(Product.updatedAt)}}`
|
|
87
88
|
- Given an array of objects, extract the values from the specified field and join them together into a single comma-separated string: `{{joinFields(Product, 'name')}}`
|
|
88
89
|
|
|
90
|
+
### Special fields
|
|
91
|
+
|
|
92
|
+
Saasufy supports a number of special metadata fields which are automatically created and updated on each model record.
|
|
93
|
+
Those fields are hidden by default but may be exposed via the Saasufy control panel and used within your application.
|
|
94
|
+
The fields are:
|
|
95
|
+
|
|
96
|
+
- `id`: String, UUID v4 format; the ID of the resource.
|
|
97
|
+
- `createdBy`: String, UUID v4 format; if the socket was authenticated, this will hold the ID of the account which created the resource.
|
|
98
|
+
- `updatedBy`: String, UUID v4 format; if the socket was authenticated, this will hold the ID of the account which last modified the resource.
|
|
99
|
+
- `createdByIp`: String, IP address format; the IP address of the client which last modified the resource.
|
|
100
|
+
- `createdAt`: Number, UNIX timestamp format; the timestamp for when the resource was created.
|
|
101
|
+
- `updatedAt`: Number, UNIX timestamp format; the timestamp for when the resource was last modified.
|
|
102
|
+
|
|
103
|
+
All of the above fields except for the `id` field are hidden by default and must be exposed via the Saasufy control panel in order to be accessible within your front end application.
|
|
104
|
+
To expose a special field on a specific model, you just need to create a field with the same name under the `fields` section of the relevant model.
|
|
105
|
+
You will need to make sure that the type you specify (`String` or `Number`) matches the type of the special field described above.
|
|
106
|
+
You will need to deploy your Saasufy service from the dashboard for the changes to take effect.
|
|
107
|
+
|
|
108
|
+
The `id` field in Saasufy is extra special; you can optionally specify it when you create a new resource, however, if it is not specified, Saasufy will create one for you.
|
|
109
|
+
Saasufy offers utility functions for creating IDs (random and deterministic). See the previous `Utility functions` section.
|
|
110
|
+
|
|
89
111
|
### File hosting
|
|
90
112
|
|
|
91
113
|
Saasufy provides basic HTTP/HTTPS file hosting functionality with support for client-side caching (with `ETag`).
|
|
@@ -789,6 +811,7 @@ When using an OAuth provider, the callback URL which you register with the provi
|
|
|
789
811
|
- `provider` (required): The name of the provider. It must match the provider name specified on the `Authentication` page of your Saasufy control panel and also the value provided to the `oauth-link` component at the start of the OAuth flow.
|
|
790
812
|
- `success-location-hash`: If authentication is successful, the browser's `location.hash` will be set to this value. It can be used to redirect the user to their dashboard, for example.
|
|
791
813
|
- `success-url`: If authentication is successful, the browser's `location.href` will be set to this value. It can be used to redirect the user to their dashboard, for example.
|
|
814
|
+
- `extra-data`: This attribute can be used to pass additional data to the OAuth `getAccessTokenURL` endpoint. For Google OAuth, for example, an additional `redirect_uri` field is required, so it should be set using `extra-data="redirect_uri=http://localhost.com:8000/"` (substitute the URI with your own).
|
|
792
815
|
- `navigate-event-path`: If authentication is successful and a path is set via this attribute, the component will emit a `navigate` event which will bubble up the component hierarchy and can be used by a parent component to perform the success redirection. This approach can be used as an alternative to `success-location-hash` or `success-url` for doing the final redirect.
|
|
793
816
|
- `state-session-storage-key`: The state string is stored in the browser's `sessionStorage` under this key. Defaults to `oauth.state`. It must match the value provided to the `oauth-link` component at the start of the OAuth flow.
|
|
794
817
|
- `code-param-name`: The name of the query parameter which holds the `code` as provided by the OAuth provider within the OAuth callback URL. Defaults to `code`.
|
package/oauth-handler.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SocketConsumer } from './socket.js';
|
|
2
|
-
import { generateRandomHexString } from './utils.js';
|
|
2
|
+
import { generateRandomHexString, convertStringToFieldParams } from './utils.js';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_AUTH_TIMEOUT = 10000;
|
|
5
5
|
|
|
@@ -49,9 +49,10 @@ class OAuthHandler extends SocketConsumer {
|
|
|
49
49
|
|
|
50
50
|
let codeParamName = this.getAttribute('code-param-name') || 'code';
|
|
51
51
|
let stateParamName = this.getAttribute('state-param-name') || 'state';
|
|
52
|
+
let extraDataString = this.getAttribute('extra-data') || '';
|
|
53
|
+
let { fieldValues: extraData } = convertStringToFieldParams(extraDataString);
|
|
52
54
|
|
|
53
55
|
let authTimeout = Number(this.getAttribute('auth-timeout') || DEFAULT_AUTH_TIMEOUT);
|
|
54
|
-
|
|
55
56
|
let urlSearchParams = new URLSearchParams(location.search);
|
|
56
57
|
let code = urlSearchParams.get(codeParamName);
|
|
57
58
|
|
|
@@ -63,7 +64,7 @@ class OAuthHandler extends SocketConsumer {
|
|
|
63
64
|
|
|
64
65
|
if (state === expectedOAuthState) {
|
|
65
66
|
try {
|
|
66
|
-
await socket.invoke('log-in-oauth', { provider, data: { code } });
|
|
67
|
+
await socket.invoke('log-in-oauth', { provider, data: { code, ...extraData } });
|
|
67
68
|
} catch (error) {
|
|
68
69
|
this.innerHTML = `
|
|
69
70
|
<div class="error">OAuth authentication failed. ${error.message}</div>
|