webs-sdk 0.19.64 → 0.19.65
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/AGENTS.md +44 -0
- package/CLAUDE.md +80 -0
- package/README.md +513 -490
- package/dist/components/ARFilters/ARFilters.js +54 -54
- package/dist/components/ArtGenerator.js +141 -141
- package/dist/components/AvatarAI.js +14 -14
- package/dist/components/CookieConsent/constants.js +31 -31
- package/dist/components/CreativeFaceSwap.js +23 -23
- package/dist/components/GifsIa.js +76 -76
- package/dist/components/MemeGenerator.js +12 -12
- package/dist/components/PasswordReset/constants.js +33 -33
- package/dist/components/RecoveryPassword/constants.js +27 -27
- package/dist/components/SpinningWheel/SpinningWheel.js +7 -7
- package/dist/components/SpinningWheel/index.d.ts +1 -1
- package/dist/components/SpinningWheel/index.d.ts.map +1 -1
- package/dist/components/SpinningWheel/index.js +2 -1
- package/dist/components/SpinningWheel/index.js.map +1 -1
- package/dist/components/ui/ConfiguredMediaPlayer.d.ts +49 -0
- package/dist/components/ui/ConfiguredMediaPlayer.d.ts.map +1 -0
- package/dist/components/ui/ConfiguredMediaPlayer.js +111 -0
- package/dist/components/ui/ConfiguredMediaPlayer.js.map +1 -0
- package/dist/components/ui/badge.d.ts +1 -0
- package/dist/components/ui/badge.d.ts.map +1 -1
- package/dist/components/ui/badge.js +1 -1
- package/dist/components/ui/badge.js.map +1 -1
- package/dist/components/ui/compose-refs.d.ts +6 -0
- package/dist/components/ui/compose-refs.d.ts.map +1 -0
- package/dist/components/ui/compose-refs.js +57 -0
- package/dist/components/ui/compose-refs.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +3 -1
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/components/ui/dropdown-menu.js +2 -2
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.d.ts.map +1 -1
- package/dist/components/ui/index.js +2 -0
- package/dist/components/ui/index.js.map +1 -1
- package/dist/components/ui/media-player.d.ts +127 -0
- package/dist/components/ui/media-player.d.ts.map +1 -0
- package/dist/components/ui/media-player.js +1633 -0
- package/dist/components/ui/media-player.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +3 -1
- package/dist/components/ui/tooltip.d.ts.map +1 -1
- package/dist/components/ui/tooltip.js +2 -2
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/components/ui/use-lazy-ref.d.ts +4 -0
- package/dist/components/ui/use-lazy-ref.d.ts.map +1 -0
- package/dist/components/ui/use-lazy-ref.js +45 -0
- package/dist/components/ui/use-lazy-ref.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/network.d.ts +12 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +15 -0
- package/dist/network.js.map +1 -0
- package/dist/server.d.ts +54 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +74 -0
- package/dist/server.js.map +1 -0
- package/dist/types/media-chrome-store-types.d.ts +107 -0
- package/dist/types/media-chrome-store-types.d.ts.map +1 -0
- package/dist/types/media-chrome-store-types.js +3 -0
- package/dist/types/media-chrome-store-types.js.map +1 -0
- package/dist/utils/QRCode.d.ts +1 -0
- package/dist/utils/QRCode.d.ts.map +1 -0
- package/dist/utils/QRCode.js +2 -0
- package/dist/utils/QRCode.js.map +1 -0
- package/dist/utils/imageValidation.d.ts +6 -0
- package/dist/utils/imageValidation.d.ts.map +1 -0
- package/dist/utils/imageValidation.js +64 -0
- package/dist/utils/imageValidation.js.map +1 -0
- package/docs/CONFIGURED_MEDIA_PLAYER.md +40 -0
- package/docs/CORP_AUTH_USAGE.md +687 -0
- package/docs/EXAMPLES_WALLPAPERSNAME_IMPLEMENTATION.md +1445 -0
- package/docs/EXAMPLE_ENDPOINTS_COMUNICATION.md +55 -0
- package/docs/EXTERNAL_SDK_GUIDE.md +1340 -0
- package/docs/FOR_YOU_360_FACESWAP_FIX.md +400 -0
- package/docs/FOR_YOU_IMPLEMENTATION_GUIDE.md +1413 -0
- package/docs/FOR_YOU_QUIZ_ARCHITECTURE.md +753 -0
- package/docs/FOR_YOU_SDK_WALLPAPERSNAME_BUG.md +106 -0
- package/docs/FOR_YOU_WALLPAPERSNAME_ENHANCEMENT_PLAN.md +210 -0
- package/docs/LEGAL_USAGE.md +190 -0
- package/docs/STREAK_IMPLEMENTATION_GUIDE.md +430 -0
- package/package.json +106 -84
- package/public/spin2win/assets/border-afristream.svg +26 -26
- package/public/spin2win/assets/border-efc.svg +23 -23
- package/public/spin2win/assets/border-streetreel.svg +23 -23
- package/public/spin2win/assets/border-totalgym.svg +27 -27
- package/public/spin2win/assets/border-womantoday.svg +26 -26
- package/public/spin2win/assets/indicator-afristream.svg +28 -28
- package/public/spin2win/assets/indicator-efc.svg +29 -29
- package/public/spin2win/assets/indicator-streetreel.svg +29 -29
- package/public/spin2win/assets/indicator-totalgym.svg +29 -29
- package/public/spin2win/fonts/switzer/README.md +22 -22
- package/scripts/install-agent-skill.cjs +34 -0
- package/skills/webs-sdk-package/SKILL.md +11 -0
- package/skills/webs-sdk-package/references/components.md +30 -0
- package/skills/webs-sdk-package/references/integration.md +32 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Bug Report: `ForYouPage` — `wallpapersName` feature shows "No wallpapers available"
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
When `wallpapersName` is rendered inside `ForYouPage`, it always shows "No wallpapers available" even though the standalone `WallpapersNamePage` component works correctly with the same data.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Environment
|
|
10
|
+
|
|
11
|
+
- **SDK version:** 0.18.74
|
|
12
|
+
- **Component:** `ForYouPage` → feature `wallpapersName`
|
|
13
|
+
- **Affected URL:** `/en/foryou-fullpage?feature=wallpapersName`
|
|
14
|
+
- **Working URL:** `/en/for-you-templates` (uses `WallpapersNamePage` directly)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Root cause
|
|
19
|
+
|
|
20
|
+
`ForYouPage` internally passes the feature config to `WallpapersName` using the **generic keys** (`tags`, `website_id`), but the `WallpapersName` component expects **specific keys** (`wallpaperTag`, `wid`).
|
|
21
|
+
|
|
22
|
+
### What `WallpapersName` expects
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
config: {
|
|
26
|
+
apiUrl: '/api/get_contents_by_tags',
|
|
27
|
+
wallpaperTag: 'wogcawallpapers', // ← specific key: string
|
|
28
|
+
locale: 'en',
|
|
29
|
+
wid: '42', // ← specific key
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### What `ForYouPage` currently passes to `WallpapersName`
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
config: {
|
|
37
|
+
apiUrl: '/api/get_contents_by_tags',
|
|
38
|
+
tags: ['wogcawallpapers'], // ← generic key: string[] ❌
|
|
39
|
+
locale: 'en',
|
|
40
|
+
website_id: '42', // ← generic key ❌
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Because `wallpaperTag` is `undefined`, the component calls the API without a tag filter and receives no results.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Comparison: standalone vs. ForYouPage
|
|
49
|
+
|
|
50
|
+
| | `WallpapersNamePage` (standalone) | `ForYouPage` → `wallpapersName` |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| Tag key | `wallpaperTag` ✅ | `tags` ❌ |
|
|
53
|
+
| Website ID key | `wid` ✅ | `website_id` ❌ |
|
|
54
|
+
| Result | Works correctly | "No wallpapers available" |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Expected behavior
|
|
59
|
+
|
|
60
|
+
`ForYouPage` should normalize the generic config keys when rendering the `wallpapersName` case, just like it already does for other features:
|
|
61
|
+
|
|
62
|
+
- `ringtone`: normalizes `tags` → `ringtoneTag` (already fixed in 0.18.72)
|
|
63
|
+
- `memeGenerator`: normalizes `tags` → `memeTag` (already fixed in 0.18.72)
|
|
64
|
+
- `wallpapersName`: **missing normalization** — `tags` → `wallpaperTag` and `website_id` → `wid`
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Requested fix
|
|
69
|
+
|
|
70
|
+
In the `ForYouPage` internal handler for the `wallpapersName` case, apply the same normalization pattern used for `ringtone` and `memeGenerator`:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// Inside ForYouPage — case 'wallpapersName'
|
|
74
|
+
const wallpaperTag =
|
|
75
|
+
config.wallpaperTag ||
|
|
76
|
+
(Array.isArray(config.tags) ? config.tags[0] : config.tags) ||
|
|
77
|
+
'wallpaper_name';
|
|
78
|
+
|
|
79
|
+
const wid = config.wid || config.website_id || '';
|
|
80
|
+
|
|
81
|
+
// Pass to WallpapersName component:
|
|
82
|
+
// { apiUrl, wallpaperTag, wid, locale, ... }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Workaround (project-side, until SDK fix)
|
|
88
|
+
|
|
89
|
+
Until the SDK is fixed, `ForYouFullPageView.tsx` passes `wallpaperTag` and `wid` directly for the `WallpapersName` feature:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
if (item.key === 'WallpapersName') {
|
|
93
|
+
baseConfig.wallpaperTag = tags[0] ?? 'wogcawallpapers';
|
|
94
|
+
baseConfig.wid = website_id;
|
|
95
|
+
delete baseConfig.tags;
|
|
96
|
+
delete baseConfig.website_id;
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This workaround is not ideal because `ForYouPage` should abstract away these config differences internally.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Priority
|
|
105
|
+
|
|
106
|
+
**High** — `wallpapersName` is a core feature of the ForYou hub and it is completely broken inside `ForYouPage`.
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Plan: WallpapersName feature enhancement in ForYouPage
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
|
|
5
|
+
`ForYouPage` (SDK) renders the `wallpapersName` feature using the `WallpapersName` component internally.
|
|
6
|
+
The current `WallpapersNameFeatureOverride` type exposes a `config` prop that only partially maps to what
|
|
7
|
+
the underlying component needs. The goal of this plan is to:
|
|
8
|
+
|
|
9
|
+
1. Allow the call to `get_contents_by_tags` to be fully configurable per portal from `product_config`.
|
|
10
|
+
2. Support a `content_default_enabled: true` flag that activates a curated set of default items even when
|
|
11
|
+
the portal-specific API call returns empty results.
|
|
12
|
+
3. Ensure that the breadcrumb rendered inside `WallpapersName` reflects the configured content source.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Current state
|
|
17
|
+
|
|
18
|
+
### SDK type — `WallpapersNameFeatureOverride`
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
export interface WallpapersNameFeatureOverride {
|
|
22
|
+
card?: ForYouCardVisual;
|
|
23
|
+
theme?: Partial<WallpapersNameTheme>;
|
|
24
|
+
texts?: Partial<WallpapersNameTexts>;
|
|
25
|
+
config?: ForYouFeatureConfig & {
|
|
26
|
+
wid?: string;
|
|
27
|
+
};
|
|
28
|
+
items?: WallpapersNameItem[];
|
|
29
|
+
categories?: WallpapersNameCategory[];
|
|
30
|
+
howItWorksSteps?: WallpapersNameHowItWorksStep[];
|
|
31
|
+
showEmptyState?: boolean;
|
|
32
|
+
onCustomise?: (item: WallpapersNameItem) => void;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### SDK type — `ForYouFeatureConfig`
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
export interface ForYouFeatureConfig {
|
|
40
|
+
apiUrl?: string;
|
|
41
|
+
apiBaseUrl?: string;
|
|
42
|
+
tags?: string | string[];
|
|
43
|
+
locale?: string;
|
|
44
|
+
website_id?: string;
|
|
45
|
+
initialCount?: number;
|
|
46
|
+
loadMoreCount?: number;
|
|
47
|
+
contents?: ForYouContentPreset[];
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### What the underlying `WallpapersName` component expects
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
config: {
|
|
55
|
+
apiUrl: string;
|
|
56
|
+
wallpaperTag?: string; // single string — normalized by SDK from tags[0]
|
|
57
|
+
locale?: string;
|
|
58
|
+
initialCount?: number;
|
|
59
|
+
loadMoreCount?: number;
|
|
60
|
+
wid?: string; // normalized by SDK from website_id
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### What `ForYouPage` internally does (SDK v0.18.75)
|
|
65
|
+
|
|
66
|
+
The SDK already normalizes:
|
|
67
|
+
- `tags[0]` → `wallpaperTag`
|
|
68
|
+
- `website_id` → `wid`
|
|
69
|
+
|
|
70
|
+
It does NOT yet support:
|
|
71
|
+
- Passing multiple content sources (tabs by tag) to `WallpapersName`
|
|
72
|
+
- A `content_default_enabled` fallback mechanism
|
|
73
|
+
- Breadcrumb configuration passthrough
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Proposed changes
|
|
78
|
+
|
|
79
|
+
### 1. Extend `WallpapersNameFeatureOverride.config` in the SDK
|
|
80
|
+
|
|
81
|
+
Add the following fields to the config shape accepted by the `wallpapersName` case inside `ForYouPage`:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
config?: ForYouFeatureConfig & {
|
|
85
|
+
wid?: string;
|
|
86
|
+
wallpaperTag?: string; // explicit tag override (skips normalization from tags[])
|
|
87
|
+
content_default_enabled?: boolean; // NEW — activates built-in default items as fallback
|
|
88
|
+
defaultItems?: WallpapersNameItem[]; // NEW — optional explicit list of fallback items
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Behavior of `content_default_enabled`
|
|
93
|
+
|
|
94
|
+
| Scenario | Behavior |
|
|
95
|
+
|---|---|
|
|
96
|
+
| API returns items | Show API items only (normal flow) |
|
|
97
|
+
| API returns 0 items AND `content_default_enabled: true` | Show `defaultItems` (if provided) OR SDK built-in curated set |
|
|
98
|
+
| API returns 0 items AND `content_default_enabled: false` or absent | Show empty state |
|
|
99
|
+
|
|
100
|
+
The SDK built-in curated set is a small static array of ~8 public-domain wallpapers stored inside
|
|
101
|
+
`ForYouPage.js` used only as last-resort fallback. Projects can override this via `defaultItems`.
|
|
102
|
+
|
|
103
|
+
### 2. Breadcrumb configuration passthrough
|
|
104
|
+
|
|
105
|
+
`WallpapersName` does not currently expose a `breadcrumbItems` prop (unlike `Wallpapers`).
|
|
106
|
+
The plan is to add it:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// in WallpapersNameProps (WallpapersName.d.ts)
|
|
110
|
+
breadcrumbItems?: { label: string; href?: string }[];
|
|
111
|
+
|
|
112
|
+
// in WallpapersNameFeatureOverride (ForYouPage.d.ts)
|
|
113
|
+
breadcrumbItems?: { label: string; href?: string }[];
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
When `WallpapersName` is rendered inside `ForYouPage`, the SDK should:
|
|
117
|
+
1. Check if `breadcrumbItems` is provided in the feature override.
|
|
118
|
+
2. If provided, pass it through to `WallpapersName`.
|
|
119
|
+
3. If NOT provided, auto-generate breadcrumbs based on the `locale`:
|
|
120
|
+
```
|
|
121
|
+
ForYou > WallpapersName
|
|
122
|
+
```
|
|
123
|
+
using the SDK's own i18n translations.
|
|
124
|
+
|
|
125
|
+
### 3. Project-side changes in `ForYouFullPageView.tsx`
|
|
126
|
+
|
|
127
|
+
Once the SDK changes are shipped, `ForYouFullPageView.tsx` should be updated to pass the new config:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
if (item.key === 'WallpapersName') {
|
|
131
|
+
// existing
|
|
132
|
+
featureEntry.howItWorksSteps = [ /* ... */ ];
|
|
133
|
+
|
|
134
|
+
// new — read from product_config or use defaults
|
|
135
|
+
const wallpaperTag = tags[0] ?? 'wogcawallpapers';
|
|
136
|
+
featureEntry.config = {
|
|
137
|
+
...featureEntry.config,
|
|
138
|
+
wallpaperTag,
|
|
139
|
+
content_default_enabled: (item.contents?.[0] as any)?.content_default_enabled ?? false,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// optional: pass breadcrumb
|
|
143
|
+
featureEntry.breadcrumbItems = [
|
|
144
|
+
{ label: t('for_you.breadcrumb.for_you'), href: `/${locale}/foryou-fullpage` },
|
|
145
|
+
{ label: t('for_you.wallpapers_name_component.breadcrumb_label') },
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 4. `product_config` schema for `WallpapersName` item
|
|
151
|
+
|
|
152
|
+
Each portal can configure the feature via its `product_config.sections[foryou].items`:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"key": "WallpapersName",
|
|
157
|
+
"contents": [
|
|
158
|
+
{
|
|
159
|
+
"tags": ["wogcawallpapers"],
|
|
160
|
+
"content_default_enabled": true
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
| Field | Type | Required | Description |
|
|
167
|
+
|---|---|---|---|
|
|
168
|
+
| `tags` | `string[]` | Yes | API tag used for `wallpaperTag`. First element is used. |
|
|
169
|
+
| `content_default_enabled` | `boolean` | No (default `false`) | Activates fallback default items when API returns empty. |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Implementation order
|
|
174
|
+
|
|
175
|
+
### Phase 1 — SDK changes (webs-sdk)
|
|
176
|
+
|
|
177
|
+
1. **`WallpapersName.tsx`**: Add `breadcrumbItems` prop. Render breadcrumb when provided.
|
|
178
|
+
2. **`WallpapersName.d.ts`**: Export updated type with `breadcrumbItems`.
|
|
179
|
+
3. **`ForYouPage.tsx`** — case `wallpapersName`:
|
|
180
|
+
- Accept `config.content_default_enabled` and `config.defaultItems`.
|
|
181
|
+
- When API resolves with 0 items and `content_default_enabled === true`, merge in `defaultItems`
|
|
182
|
+
or the SDK built-in curated set.
|
|
183
|
+
- Pass `breadcrumbItems` from the feature override to `WallpapersName`.
|
|
184
|
+
4. **`ForYouPage.d.ts`**: Update `WallpapersNameFeatureOverride` with the new fields.
|
|
185
|
+
5. **Publish** new SDK version (suggested: `0.18.76`).
|
|
186
|
+
|
|
187
|
+
### Phase 2 — Project changes (winsports)
|
|
188
|
+
|
|
189
|
+
1. **`ForYouFullPageView.tsx`**: Read `content_default_enabled` from `itemConfig.contents[0]` and
|
|
190
|
+
pass it through the `featureEntry.config`. Add `breadcrumbItems`.
|
|
191
|
+
2. **`product_config`** (portal backend): Add `content_default_enabled: true` to the `WallpapersName`
|
|
192
|
+
item for portals that should show default content on empty results.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Expected result per URL
|
|
197
|
+
|
|
198
|
+
| URL | Before | After |
|
|
199
|
+
|---|---|---|
|
|
200
|
+
| `/foryou-fullpage?feature=wallpapersName` | No "How does it work?", button blocked when API empty | Shows steps, button active when API has data, fallback items shown when API empty + flag enabled |
|
|
201
|
+
| `/for-you-templates` | Shows `WallpapersName` + `AETemplatesSection` together | Shows only `AETemplatesSection` (already fixed) |
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Open questions
|
|
206
|
+
|
|
207
|
+
- Should `defaultItems` be defined per-locale in the SDK, or is one global list sufficient?
|
|
208
|
+
- Should the breadcrumb be hidden (`hideBreadcrumb: true`) when `WallpapersName` is inside `ForYouPage`
|
|
209
|
+
and the hub already handles navigation? Currently `WallpapersName` has no `hideBreadcrumb` prop
|
|
210
|
+
(unlike `Wallpapers`). This should also be added in Phase 1.
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Legal Manager - Guía de Uso
|
|
2
|
+
|
|
3
|
+
El **LegalManager** es una librería del `webs-sdk` que permite obtener textos legales (Términos y Condiciones, Política de Privacidad, Política de Cookies) desde la API de Fluver-AI.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
El LegalManager está incluido automáticamente en el `webs-sdk`. Solo necesitas importar el SDK:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import WebsSDK from 'webs-sdk';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Uso Básico
|
|
14
|
+
|
|
15
|
+
### Obtener Términos y Condiciones
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
try {
|
|
19
|
+
const termsAndConditions = await WebsSDK.Legal.getLegalText(
|
|
20
|
+
'mi-web-id', // ID de tu sitio web
|
|
21
|
+
'tc', // Tipo: 'tc' (Terms & Conditions)
|
|
22
|
+
'es' // Idioma (opcional, por defecto 'es')
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
console.log(termsAndConditions);
|
|
26
|
+
// {
|
|
27
|
+
// success: true,
|
|
28
|
+
// data: { ... contenido legal ... },
|
|
29
|
+
// website_id: 'mi-web-id',
|
|
30
|
+
// type: 'tc',
|
|
31
|
+
// language: 'es'
|
|
32
|
+
// }
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('Error al obtener términos y condiciones:', error);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Obtener Política de Privacidad
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
try {
|
|
42
|
+
const privacyPolicy = await WebsSDK.Legal.getLegalText(
|
|
43
|
+
'mi-web-id',
|
|
44
|
+
'privacy', // Tipo: 'privacy'
|
|
45
|
+
'en' // Idioma inglés
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
console.log(privacyPolicy.data);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error('Error al obtener política de privacidad:', error);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Obtener Política de Cookies
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
try {
|
|
58
|
+
const cookiePolicy = await WebsSDK.Legal.getLegalText(
|
|
59
|
+
'mi-web-id',
|
|
60
|
+
'cookies' // Tipo: 'cookies'
|
|
61
|
+
// Sin especificar idioma, usa 'es' por defecto
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
console.log(cookiePolicy.data);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error('Error al obtener política de cookies:', error);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API Reference
|
|
71
|
+
|
|
72
|
+
### `getLegalText(website_id, type, language?)`
|
|
73
|
+
|
|
74
|
+
Obtiene el texto legal especificado desde la API.
|
|
75
|
+
|
|
76
|
+
**Parámetros:**
|
|
77
|
+
|
|
78
|
+
- `website_id` (string, requerido): El identificador único de tu sitio web
|
|
79
|
+
- `type` (LegalDocumentType, requerido): El tipo de documento legal
|
|
80
|
+
- `'tc'` - Términos y Condiciones (Terms & Conditions)
|
|
81
|
+
- `'privacy'` - Política de Privacidad
|
|
82
|
+
- `'cookies'` - Política de Cookies
|
|
83
|
+
- `language` (string, opcional): Código del idioma (por defecto: `'es'`)
|
|
84
|
+
- Ejemplos: `'es'`, `'en'`, `'fr'`, `'de'`, etc.
|
|
85
|
+
|
|
86
|
+
**Retorna:**
|
|
87
|
+
|
|
88
|
+
Una `Promise` que resuelve con un objeto `LegalTextResponse`:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
interface LegalTextResponse {
|
|
92
|
+
success: boolean;
|
|
93
|
+
data: any; // Contenido del documento legal
|
|
94
|
+
website_id: string;
|
|
95
|
+
type: string;
|
|
96
|
+
language: string;
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Excepciones:**
|
|
101
|
+
|
|
102
|
+
Lanza un error si:
|
|
103
|
+
- La petición a la API falla
|
|
104
|
+
- El website_id o type no son válidos
|
|
105
|
+
- No hay conexión de red
|
|
106
|
+
|
|
107
|
+
## Ejemplos de Uso Completos
|
|
108
|
+
|
|
109
|
+
### Ejemplo 1: Mostrar T&C en una página web
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
async function displayTermsAndConditions() {
|
|
113
|
+
try {
|
|
114
|
+
const response = await WebsSDK.Legal.getLegalText('my-website', 'tc', 'es');
|
|
115
|
+
|
|
116
|
+
if (response.success) {
|
|
117
|
+
const contentDiv = document.getElementById('legal-content');
|
|
118
|
+
contentDiv.innerHTML = response.data.content;
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error('No se pudieron cargar los términos:', error);
|
|
122
|
+
alert('Error al cargar los términos y condiciones');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Ejemplo 2: Selector de idioma para documentos legales
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
async function loadLegalDocument(type: 'tc' | 'privacy' | 'cookies', language: string) {
|
|
131
|
+
const website_id = 'mi-sitio-web';
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const response = await WebsSDK.Legal.getLegalText(website_id, type, language);
|
|
135
|
+
|
|
136
|
+
return response.data;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error(`Error cargando documento ${type} en ${language}:`, error);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Uso
|
|
144
|
+
const spanishTC = await loadLegalDocument('tc', 'es');
|
|
145
|
+
const englishPrivacy = await loadLegalDocument('privacy', 'en');
|
|
146
|
+
const frenchCookies = await loadLegalDocument('cookies', 'fr');
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Ejemplo 3: Cache de documentos legales
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
class LegalDocumentCache {
|
|
153
|
+
private cache: Map<string, any> = new Map();
|
|
154
|
+
|
|
155
|
+
async getLegalDocument(
|
|
156
|
+
website_id: string,
|
|
157
|
+
type: 'tc' | 'privacy' | 'cookies',
|
|
158
|
+
language: string = 'es'
|
|
159
|
+
) {
|
|
160
|
+
const cacheKey = `${website_id}-${type}-${language}`;
|
|
161
|
+
|
|
162
|
+
// Verificar si está en cache
|
|
163
|
+
if (this.cache.has(cacheKey)) {
|
|
164
|
+
console.log('Retornando desde cache');
|
|
165
|
+
return this.cache.get(cacheKey);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Obtener desde API
|
|
169
|
+
try {
|
|
170
|
+
const response = await WebsSDK.Legal.getLegalText(website_id, type, language);
|
|
171
|
+
|
|
172
|
+
if (response.success) {
|
|
173
|
+
this.cache.set(cacheKey, response.data);
|
|
174
|
+
return response.data;
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.error('Error obteniendo documento legal:', error);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
clearCache() {
|
|
183
|
+
this.cache.clear();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Uso
|
|
188
|
+
const legalCache = new LegalDocumentCache();
|
|
189
|
+
const terms = await legalCache.getLegalDocument('my-site', 'tc', 'es');
|
|
190
|
+
```
|