Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocWorks for wix-web-module - 6 changes detected, but 2 issue detected #3051

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 6 additions & 156 deletions wix-web-module/wix-web-module.service.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
{ "summary": "The wix-web-module module contains functionality for defining and managing web modules.",
"description":
[ "The Web Modules API allows you to define functions in your backend code that can be called from your site's frontend code. In order to call the function from the frontened, you need to define the necessary permissions. ",
"",
"With web modules you can also cache the return values of the backend functions in your code. This means you can temporarily store the result of the function for a specified period of time. Caching return values reduces response times, decreases server load, and enhances the overall user experience of site visitors by providing quicker access to previously generated data. ",
"",
"To use the Web Modules API, import the `webMethod` function and the `Permissions` enum from the `wix-web-module` module:",
"```javascript",
Expand All @@ -33,18 +31,14 @@
"doc": "Permissions needed to call the function in frontend code." },
{ "name": "function",
"type": "Function",
"doc": "Function to export." },
{ "name": "options",
"type": "wix-web-module.Options",
"doc": "Caching options.",
"optional": true } ],
"doc": "Function to export." } ],
"ret":
{ "type":
{ "name": "Promise",
"typeParams":
[ "function()" ] } },
"locations":
[ { "lineno": 19,
[ { "lineno": 17,
"filename": "web-methods.js" } ],
"docs":
{ "summary": "Defines a backend function that can be called from the frontend.",
Expand All @@ -59,18 +53,6 @@
" - `Permissions.SiteMember`: Only site members can call the function.",
"",
"",
"The `cache` object, found in the `options` parameter, enables you to cache or temporarily store the return values of your backend functions for a specific duration. Use the `ttl` property to define the duration, in seconds, for which you want your return value to be cached. If the Time To Live (TTL) is not set, the default value is `604000` seconds, which is approximately 1 week. ",
"",
"You can also assign identifiers to cached return values using the `tags` property of the `cache` object. Tags allow you to specify cached return values that may require invalidation due to a significant change in your data. To invalidate a cached return value, use the [`invalidateCache()`](https://dev.wix.com/docs/velo/api-reference/wix-cache-backend/cache/invalidate-cache) function from `wix-cache-backend`. Once invalidated, the return value will be re-cached the next time the function is called. ",
"",
"<blockquote class=\"important\">",
"",
">__Important:__",
">If you plan to invalidate your caches, you must first cache them using the `tags` property to identify them. Without tags, your cache will only be invalidated when the TTL expires or when you republish your site with a code change. ",
"",
"</blockquote>",
"",
"",
"Web methods must be defined in files with a `.web.js` extension." ],
"links": [],
"examples":
Expand All @@ -89,140 +71,6 @@
" console.log(result); // Logs 15",
" });",
"});" ],
"extra":
{ } },
{ "title": "Export and cache the return value",
"body":
[ "import { Permissions, webMethod } from \"wix-web-module\";",
"import { currencies } from \"wix-ecom.v2\";",
"",
"export const getConversionRate = webMethod(",
" Permissions.Anyone, ",
" async () => {",
" try {",
" const conversionRate = await currencies.getConversionRate(\"USD\", \"GBP\");",
" const rate = conversionRate.rate;",
" const timestamp = conversionRate.rateTimestamp;",
"",
" return conversionRate;",
" } catch (error) {",
" console.error(error);",
" // Handle the error",
" }",
"},",
"{",
" cache: {",
" tags: [\"currency\", \"USD\", \"GBP\"],",
" ttl: 86400 // Cache TTL in seconds (1 day)",
" }",
"});",
"",
"/* Promise resolves to:",
" * {",
" * \"rate\": {",
" * value: \"20\",",
" * decimalPlaces: 2",
" * },",
" * \"rateTimestamp\": \"2020-03-15T20:00:00.181Z\"",
" * }",
" */" ],
"extra":
{ } },
{ "title": "Export and cache the return value of `getConversionRate()` for 1 day",
"body":
[ "import { Permissions, webMethod } from \"wix-web-module\";",
"import { currencies } from \"wix-ecom.v2\";",
"",
"export const getConversionRate = webMethod(",
" Permissions.Anyone, ",
" async () => {",
" try {",
" const conversionRate = await currencies.getConversionRate(\"USD\", \"GBP\");",
" const rate = conversionRate.rate;",
" const timestamp = conversionRate.rateTimestamp;",
"",
" return conversionRate;",
" } catch (error) {",
" console.error(error);",
" // Handle the error",
" }",
"},",
"{",
" cache: {",
" tags: [\"currency\", \"USD\", \"GBP\"],",
" ttl: 86400 // Cache TTL in seconds (1 day)",
" }",
"});",
"",
"/* Promise resolves to:",
" * {",
" * \"rate\": {",
" * value: \"20\",",
" * decimalPlaces: 2",
" * },",
" * \"rateTimestamp\": \"2020-03-15T20:00:00.181Z\"",
" * }",
" */" ],
"extra":
{ } },
{ "title": "Export and cache the return value of `listPosts()` for 1 week",
"body":
[ "import { Permissions, webMethod } from \"wix-web-module\";",
"import { posts } from \"wix-blog-backend\";",
"",
"// List blog posts",
"const listBlogPostsFunction = async () => {",
" try {",
" const results = await posts.listPosts();",
" return results.posts;",
" } catch (error) {",
" console.error(\"Error fetching blog posts:\", error);",
" // Handle the error",
" }",
"};",
"",
"// Exported web method that caches blog posts",
"export const getCachedBlogPosts = webMethod(",
" Permissions.Anyone,",
" listBlogPostsFunction,",
" {",
" cache: {",
" tags: [\"blogPosts\", \"blog\"],",
" ttl: 604800, // Cache TTL in seconds (7 days)",
" },",
" }",
");" ],
"extra":
{ } },
{ "title": "Export and cache the return value of `queryContacts()` for 1 month with `elevate()`",
"body":
[ "import { Permissions, webMethod } from \"wix-web-module\";",
"import { contacts } from \"wix-crm.v2\";",
"import { elevate } from \"wix-auth\";",
"",
"/* Sample contact ID value: \"2ca312b3-e850-465a-9991-c59c9c140919\" */",
"",
"const elevatedGetContact = elevate(contacts.getContact);",
"",
"export const myGetContactFunction = webMethod(",
" Permissions.Anyone,",
" async (id) => {",
" try {",
" const contact = await elevatedGetContact(id);",
"",
" return contact;",
" } catch (error) {",
" console.log(error);",
" // Handle the error",
" }",
" },",
" {",
" cache: {",
" tags: [\"contact\", \"crm\"],",
" ttl: 2628000, // Cache TTL in seconds (1 month)",
" },",
" }",
");" ],
"extra":
{ } } ],
"extra":
Expand Down Expand Up @@ -255,7 +103,8 @@
"optional": true } ],
"extra":
{ },
"labels": [] },
"labels":
[ "removed" ] },
{ "name": "Options",
"locations":
[ { "lineno": 71,
Expand All @@ -273,7 +122,8 @@
"optional": true } ],
"extra":
{ },
"labels": [] } ],
"labels":
[ "removed" ] } ],
"extra":
{ "scopes":
[ "backend" ] } }
Loading