@smartico/public-api 0.0.386 → 0.0.387
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 +1 -1
- package/dist/Avatars/AvatarCustomizeErrorCode.d.ts +7 -1
- package/dist/Avatars/AvatarCustomizeResponse.d.ts +16 -0
- package/dist/Avatars/index.d.ts +1 -0
- package/dist/Missions/UserAchievementTask.d.ts +4 -0
- package/dist/SmarticoAPI.d.ts +11 -0
- package/dist/WSAPI/WSAPIAvatars.d.ts +103 -0
- package/dist/WSAPI/WSAPITypes.d.ts +6 -2
- package/dist/index.js +260 -78
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +168 -6
- package/dist/index.modern.mjs.map +1 -1
- package/docs/SmarticoObject.md +15 -0
- package/docs/api/README.md +2 -0
- package/docs/api/classes/WSAPIAvatars.md +135 -0
- package/docs/api/classes/WSAPIClans.md +3 -5
- package/docs/api/documents/SmarticoObject.md +15 -0
- package/docs/api/enumerations/AvatarCustomizeErrorCode.md +21 -0
- package/docs/api/enumerations/JoinClanErrorCode.md +16 -17
- package/docs/api/interfaces/AvatarCustomizeResponse.md +31 -0
- package/docs/api/interfaces/TAvatarPrompt.md +2 -2
- package/docs/api/interfaces/TMissionOrBadgeTask.md +16 -0
- package/docs/api/interfaces/UserAchievementTask.md +16 -0
- package/docs/native/PROTOCOL.md +3 -1
- package/docs/ui/avatars/UIGuide_avatarsCustomize.md +69 -0
- package/package.json +1 -1
- package/src/Avatars/AvatarCustomizeErrorCode.ts +7 -5
- package/src/Avatars/AvatarCustomizeResponse.ts +17 -0
- package/src/Avatars/index.ts +1 -0
- package/src/Missions/UserAchievement.ts +2 -0
- package/src/Missions/UserAchievementTask.ts +4 -0
- package/src/SmarticoAPI.ts +53 -0
- package/src/WSAPI/WSAPIAvatars.ts +121 -0
- package/src/WSAPI/WSAPITypes.ts +6 -2
- package/tsconfig.json +3 -1
package/docs/SmarticoObject.md
CHANGED
|
@@ -108,6 +108,14 @@ login payload and (optionally) the language. Both are being consolidated into
|
|
|
108
108
|
Logs the current user out, forgets the session, and reconnects as anonymous.
|
|
109
109
|
Fires the `logout` callback on success.
|
|
110
110
|
|
|
111
|
+
### `checkSuccessfullyIdentify()`
|
|
112
|
+
|
|
113
|
+
Returns `true` once the SDK is initialized **and** a user has been
|
|
114
|
+
successfully identified, `false` otherwise. Use it as a synchronous gate
|
|
115
|
+
before calling user-scoped `_smartico.api.*` methods (e.g. `getUserProfile()`),
|
|
116
|
+
as an alternative to waiting on the `identify` callback. Returns `false` in
|
|
117
|
+
visitor mode.
|
|
118
|
+
|
|
111
119
|
### `changeLanguage(language)`
|
|
112
120
|
|
|
113
121
|
Switches the active language. The code is normalized to a 2-letter form
|
|
@@ -396,6 +404,13 @@ Returns `true` on mobile user agents.
|
|
|
396
404
|
Parse the current page URL / URL hash into an object (helpers for reading
|
|
397
405
|
query / hash parameters).
|
|
398
406
|
|
|
407
|
+
### `sendServerError(message)` · `sendServerDebug(message)`
|
|
408
|
+
|
|
409
|
+
Forward a client-side message to Smartico's servers for support correlation —
|
|
410
|
+
`sendServerError` for error conditions, `sendServerDebug` for diagnostic
|
|
411
|
+
detail. Useful when reporting an integration issue so the message lands
|
|
412
|
+
alongside your session server-side. No-ops if the SDK isn't initialized.
|
|
413
|
+
|
|
399
414
|
---
|
|
400
415
|
|
|
401
416
|
## Setup notes
|
package/docs/api/README.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
- [PointChangeSourceType](enumerations/PointChangeSourceType.md)
|
|
12
12
|
- [UserBalanceType](enumerations/UserBalanceType.md)
|
|
13
|
+
- [AvatarCustomizeErrorCode](enumerations/AvatarCustomizeErrorCode.md)
|
|
13
14
|
- [BonusStatus](enumerations/BonusStatus.md)
|
|
14
15
|
- [JoinClanErrorCode](enumerations/JoinClanErrorCode.md)
|
|
15
16
|
- [ActivityTypeLimited](enumerations/ActivityTypeLimited.md)
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
|
|
79
80
|
- [PointsLog](interfaces/PointsLog.md)
|
|
80
81
|
- [GemsDiamondsLog](interfaces/GemsDiamondsLog.md)
|
|
82
|
+
- [AvatarCustomizeResponse](interfaces/AvatarCustomizeResponse.md)
|
|
81
83
|
- [AvatarCustomized](interfaces/AvatarCustomized.md)
|
|
82
84
|
- [AvatarDefinition](interfaces/AvatarDefinition.md)
|
|
83
85
|
- [AvatarPrompt](interfaces/AvatarPrompt.md)
|
|
@@ -342,3 +342,138 @@ switch (r.err_code) {
|
|
|
342
342
|
```
|
|
343
343
|
|
|
344
344
|
***
|
|
345
|
+
|
|
346
|
+
### avatarsCustomize()
|
|
347
|
+
|
|
348
|
+
> **avatarsCustomize**(`props`): `Promise`\<[`AvatarCustomizeResponse`](../interfaces/AvatarCustomizeResponse.md)\>
|
|
349
|
+
|
|
350
|
+
Generates an AI-customized variant of a base avatar by applying an
|
|
351
|
+
operator-defined style prompt, returning the CDN URL of the result.
|
|
352
|
+
This is a paid, generate-only step: it does NOT change the user's
|
|
353
|
+
active avatar — pass the returned `cdn_url` to [setAvatar](#setavatar) to
|
|
354
|
+
activate it.
|
|
355
|
+
|
|
356
|
+
#### Parameters
|
|
357
|
+
|
|
358
|
+
##### props
|
|
359
|
+
|
|
360
|
+
###### label_id
|
|
361
|
+
|
|
362
|
+
`number`
|
|
363
|
+
|
|
364
|
+
Numeric Smartico label (brand) ID the user belongs to.
|
|
365
|
+
|
|
366
|
+
###### user_id
|
|
367
|
+
|
|
368
|
+
`number`
|
|
369
|
+
|
|
370
|
+
Numeric Smartico user ID.
|
|
371
|
+
|
|
372
|
+
###### prompt_id
|
|
373
|
+
|
|
374
|
+
`number`
|
|
375
|
+
|
|
376
|
+
Style-prompt ID (`prompt_id`) from [getAvatarPrompts](#getavatarprompts).
|
|
377
|
+
|
|
378
|
+
###### avatar_url
|
|
379
|
+
|
|
380
|
+
`string`
|
|
381
|
+
|
|
382
|
+
CDN URL of the base avatar to customize.
|
|
383
|
+
|
|
384
|
+
###### avatar_real_id
|
|
385
|
+
|
|
386
|
+
`number`
|
|
387
|
+
|
|
388
|
+
`avatar_real_id` of the base avatar.
|
|
389
|
+
|
|
390
|
+
#### Returns
|
|
391
|
+
|
|
392
|
+
`Promise`\<[`AvatarCustomizeResponse`](../interfaces/AvatarCustomizeResponse.md)\>
|
|
393
|
+
|
|
394
|
+
[AvatarCustomizeResponse](../interfaces/AvatarCustomizeResponse.md) — `cdn_url` set on success;
|
|
395
|
+
`errCode` / `errMessage` set on failure.
|
|
396
|
+
|
|
397
|
+
#### Remarks
|
|
398
|
+
|
|
399
|
+
**Preconditions**
|
|
400
|
+
- Authenticated session required; not available in visitor mode (throws).
|
|
401
|
+
- All five fields are mandatory — the SDK throws synchronously
|
|
402
|
+
(`Error("<field> is required")`) if any is missing or zero.
|
|
403
|
+
- `prompt_id` must be one of the prompts from [getAvatarPrompts](#getavatarprompts);
|
|
404
|
+
`avatar_url` / `avatar_real_id` identify the base avatar to style.
|
|
405
|
+
|
|
406
|
+
**Cost**
|
|
407
|
+
Each generation costs the currency the operator configured on the
|
|
408
|
+
chosen prompt (points, gems, or diamonds — some prompts are free; read
|
|
409
|
+
`cost_currency_type_id` / `cost_value` from the [getAvatarPrompts](#getavatarprompts)
|
|
410
|
+
entry to gate the UI before calling). The cost is charged only on
|
|
411
|
+
success; if the user can't afford it the call fails with `errCode -1`
|
|
412
|
+
and nothing is generated or charged.
|
|
413
|
+
|
|
414
|
+
**Latency**
|
|
415
|
+
Generation runs server-side AI image synthesis and is synchronous from
|
|
416
|
+
the caller's side — expect several seconds (roughly 5–20 s) before the
|
|
417
|
+
promise resolves. There is no SDK cache and no push/subscription; show
|
|
418
|
+
a loading state for the full duration and disable the trigger to
|
|
419
|
+
prevent duplicate submissions.
|
|
420
|
+
|
|
421
|
+
**Result & error codes**
|
|
422
|
+
On success the result has `cdn_url` set; on failure it has `errCode` /
|
|
423
|
+
`errMessage` set and no `cdn_url`. Branch on `errCode` — the generic
|
|
424
|
+
message is fixed text, not cause-specific:
|
|
425
|
+
- `12001` (`AvatarCustomizeErrorCode.AVATAR_USER_LIMIT`) — the user hit
|
|
426
|
+
their monthly per-user generation cap. Nothing is generated or charged.
|
|
427
|
+
- `12002` (`AvatarCustomizeErrorCode.AVATAR_LABEL_LIMIT`) — the brand's
|
|
428
|
+
shared monthly pool is exhausted. Nothing is generated or charged;
|
|
429
|
+
surface a "try again later" message.
|
|
430
|
+
- `-1` — generic failure: insufficient balance, an unavailable prompt,
|
|
431
|
+
or a generation error. Nothing is charged. Allow the user to retry.
|
|
432
|
+
|
|
433
|
+
Both monthly caps are operator-configured and reset at the start of
|
|
434
|
+
each calendar month.
|
|
435
|
+
|
|
436
|
+
**Side effects (on success)**
|
|
437
|
+
The generated variant is persisted to the user's customization history
|
|
438
|
+
and counts toward the monthly caps **whether or not** it is later
|
|
439
|
+
activated — generation is not reversible. The SDK clears the
|
|
440
|
+
[getAvatarsCustomized](#getavatarscustomized) cache so the next call surfaces the new
|
|
441
|
+
variant. The user's active avatar is unchanged until you call
|
|
442
|
+
[setAvatar](#setavatar) with the returned `cdn_url`.
|
|
443
|
+
|
|
444
|
+
**Idempotency**: not idempotent — each successful call generates (and
|
|
445
|
+
charges for) a new variant. Guard the call site against double-clicks.
|
|
446
|
+
|
|
447
|
+
**UI guidance**: see [UI Guide — `avatarsCustomize`](../_media/UIGuide_avatarsCustomize.md).
|
|
448
|
+
|
|
449
|
+
**Visitor mode**: not supported (throws).
|
|
450
|
+
|
|
451
|
+
#### Example
|
|
452
|
+
|
|
453
|
+
```ts
|
|
454
|
+
// label_id / user_id identify the Smartico user being customized.
|
|
455
|
+
const prompts = await window._smartico.api.getAvatarPrompts();
|
|
456
|
+
const prompt = prompts[0];
|
|
457
|
+
|
|
458
|
+
console.log('[smartico] generating avatar — show a spinner for ~5-20s and disable the Generate button');
|
|
459
|
+
const result = await window._smartico.api.avatarsCustomize({
|
|
460
|
+
label_id,
|
|
461
|
+
user_id,
|
|
462
|
+
prompt_id: prompt.prompt_id,
|
|
463
|
+
avatar_url: baseAvatar.avatar_url,
|
|
464
|
+
avatar_real_id: baseAvatar.avatar_real_id,
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
if (result.cdn_url) {
|
|
468
|
+
console.log('[smartico] generation succeeded — preview this URL, then call setAvatar to apply it:', result.cdn_url);
|
|
469
|
+
// await window._smartico.api.setAvatar({ avatar_url: result.cdn_url, avatar_real_id: baseAvatar.avatar_real_id });
|
|
470
|
+
} else if (result.errCode === 12001) {
|
|
471
|
+
console.error('[smartico] user monthly limit reached — show "you have used all your custom avatars this month"');
|
|
472
|
+
} else if (result.errCode === 12002) {
|
|
473
|
+
console.error('[smartico] brand monthly pool exhausted — show "custom avatars are unavailable right now, try later"');
|
|
474
|
+
} else {
|
|
475
|
+
console.error('[smartico] generation failed (e.g. not enough balance) — let the user retry:', result.errMessage);
|
|
476
|
+
}
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
***
|
|
@@ -334,12 +334,10 @@ below.
|
|
|
334
334
|
tournament requires the user to be in a clan first.
|
|
335
335
|
- `1006` (`JOIN_CLAN_COOLDOWN_ACTIVE`) — user is inside the
|
|
336
336
|
switch-cooldown window from a previous clan join (default
|
|
337
|
-
7 days, configurable per label).
|
|
337
|
+
7 days, configurable per label). Only reachable when the user is
|
|
338
|
+
already in a *different* clan (this call is then a clan switch);
|
|
339
|
+
a first-time join never returns `1006`. Surface the
|
|
338
340
|
`TClans.cooldown_until` expiry in the disabled CTA.
|
|
339
|
-
- `1007` (`JOIN_CLAN_ARCHIVED`) — defined on the public enum but
|
|
340
|
-
the server does NOT emit this code in practice (archived clans
|
|
341
|
-
are reported as `1001`). Handle it as a synonym for `1001`
|
|
342
|
-
defensively, but do not rely on it.
|
|
343
341
|
- `1011` (`JOIN_CLAN_JOINED_AFTER_TOURNAMENT_START`) — this
|
|
344
342
|
method does NOT return `1011` directly. The code fires on
|
|
345
343
|
[registerInTournament](WSAPITournaments.md#registerintournament) responses when the user joined
|
|
@@ -108,6 +108,14 @@ login payload and (optionally) the language. Both are being consolidated into
|
|
|
108
108
|
Logs the current user out, forgets the session, and reconnects as anonymous.
|
|
109
109
|
Fires the `logout` callback on success.
|
|
110
110
|
|
|
111
|
+
### `checkSuccessfullyIdentify()`
|
|
112
|
+
|
|
113
|
+
Returns `true` once the SDK is initialized **and** a user has been
|
|
114
|
+
successfully identified, `false` otherwise. Use it as a synchronous gate
|
|
115
|
+
before calling user-scoped `_smartico.api.*` methods (e.g. `getUserProfile()`),
|
|
116
|
+
as an alternative to waiting on the `identify` callback. Returns `false` in
|
|
117
|
+
visitor mode.
|
|
118
|
+
|
|
111
119
|
### `changeLanguage(language)`
|
|
112
120
|
|
|
113
121
|
Switches the active language. The code is normalized to a 2-letter form
|
|
@@ -396,6 +404,13 @@ Returns `true` on mobile user agents.
|
|
|
396
404
|
Parse the current page URL / URL hash into an object (helpers for reading
|
|
397
405
|
query / hash parameters).
|
|
398
406
|
|
|
407
|
+
### `sendServerError(message)` · `sendServerDebug(message)`
|
|
408
|
+
|
|
409
|
+
Forward a client-side message to Smartico's servers for support correlation —
|
|
410
|
+
`sendServerError` for error conditions, `sendServerDebug` for diagnostic
|
|
411
|
+
detail. Useful when reporting an integration issue so the message lands
|
|
412
|
+
alongside your session server-side. No-ops if the SDK isn't initialized.
|
|
413
|
+
|
|
399
414
|
---
|
|
400
415
|
|
|
401
416
|
## Setup notes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Enumeration: AvatarCustomizeErrorCode
|
|
2
|
+
|
|
3
|
+
Limit error codes returned in `errCode` by the `avatarsCustomize` method.
|
|
4
|
+
See the `avatarsCustomize` TSDoc for the full table (including the generic
|
|
5
|
+
`-1` failure, which has no named member here).
|
|
6
|
+
|
|
7
|
+
## Enumeration Members
|
|
8
|
+
|
|
9
|
+
### AVATAR\_USER\_LIMIT
|
|
10
|
+
|
|
11
|
+
> **AVATAR\_USER\_LIMIT**: `12001`
|
|
12
|
+
|
|
13
|
+
The user has reached the operator-configured per-user monthly cap on custom-avatar generations.
|
|
14
|
+
|
|
15
|
+
***
|
|
16
|
+
|
|
17
|
+
### AVATAR\_LABEL\_LIMIT
|
|
18
|
+
|
|
19
|
+
> **AVATAR\_LABEL\_LIMIT**: `12002`
|
|
20
|
+
|
|
21
|
+
The brand's operator-configured shared monthly pool of custom-avatar generations is exhausted.
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# Enumeration: JoinClanErrorCode
|
|
2
2
|
|
|
3
|
+
Error codes returned in `errCode` by the `joinClan` method (also carried
|
|
4
|
+
on `TClanJoinResult`). These are terse value definitions for lookup; the
|
|
5
|
+
full per-code narrative and UI handling lives in the `joinClan` method
|
|
6
|
+
TSDoc, which owns the error table.
|
|
7
|
+
|
|
3
8
|
## Enumeration Members
|
|
4
9
|
|
|
5
10
|
### JOIN\_CLAN\_OK
|
|
6
11
|
|
|
7
12
|
> **JOIN\_CLAN\_OK**: `0`
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
Success — join completed; entry fee (if any) deducted.
|
|
10
15
|
|
|
11
16
|
***
|
|
12
17
|
|
|
@@ -14,7 +19,7 @@ No error, join completed
|
|
|
14
19
|
|
|
15
20
|
> **JOIN\_CLAN\_INVALID\_PARAMETERS**: `1000`
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
Request was malformed (missing or invalid parameters).
|
|
18
23
|
|
|
19
24
|
***
|
|
20
25
|
|
|
@@ -22,7 +27,7 @@ Invalid parameters
|
|
|
22
27
|
|
|
23
28
|
> **JOIN\_CLAN\_NOT\_FOUND**: `1001`
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
Clan doesn't exist for this label. Archived clans are also reported as `1001`.
|
|
26
31
|
|
|
27
32
|
***
|
|
28
33
|
|
|
@@ -30,7 +35,7 @@ clan_id doesn't exist for this label
|
|
|
30
35
|
|
|
31
36
|
> **JOIN\_CLAN\_FULL**: `1002`
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
Clan is full — member capacity reached.
|
|
34
39
|
|
|
35
40
|
***
|
|
36
41
|
|
|
@@ -38,7 +43,7 @@ members_count >= capacity_limit
|
|
|
38
43
|
|
|
39
44
|
> **JOIN\_CLAN\_INSUFFICIENT\_FUNDS**: `1003`
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
Insufficient balance for the entry fee (points / gems / diamonds).
|
|
42
47
|
|
|
43
48
|
***
|
|
44
49
|
|
|
@@ -46,7 +51,7 @@ Not enough Points / Gems / Diamonds for entry fee
|
|
|
46
51
|
|
|
47
52
|
> **JOIN\_CLAN\_SEGMENT\_MISMATCH**: `1004`
|
|
48
53
|
|
|
49
|
-
User doesn't
|
|
54
|
+
User doesn't meet the clan's entry segment or conditions.
|
|
50
55
|
|
|
51
56
|
***
|
|
52
57
|
|
|
@@ -54,7 +59,8 @@ User doesn't satisfy entry_conditions / entry_segment_id
|
|
|
54
59
|
|
|
55
60
|
> **JOIN\_CLAN\_USER\_IS\_NOT\_IN\_CLAN**: `1005`
|
|
56
61
|
|
|
57
|
-
User is not in a clan
|
|
62
|
+
User is not in a clan. Note: a `registerInTournament` response code
|
|
63
|
+
that shares this enum — never returned by `joinClan`.
|
|
58
64
|
|
|
59
65
|
***
|
|
60
66
|
|
|
@@ -62,15 +68,7 @@ User is not in a clan
|
|
|
62
68
|
|
|
63
69
|
> **JOIN\_CLAN\_COOLDOWN\_ACTIVE**: `1006`
|
|
64
70
|
|
|
65
|
-
User is within the
|
|
66
|
-
|
|
67
|
-
***
|
|
68
|
-
|
|
69
|
-
### JOIN\_CLAN\_ARCHIVED
|
|
70
|
-
|
|
71
|
-
> **JOIN\_CLAN\_ARCHIVED**: `1007`
|
|
72
|
-
|
|
73
|
-
clan_status_id != 1 (clan is archived)
|
|
71
|
+
User is within the clan-switch cooldown window (switch only).
|
|
74
72
|
|
|
75
73
|
***
|
|
76
74
|
|
|
@@ -78,4 +76,5 @@ clan_status_id != 1 (clan is archived)
|
|
|
78
76
|
|
|
79
77
|
> **JOIN\_CLAN\_JOINED\_AFTER\_TOURNAMENT\_START**: `1011`
|
|
80
78
|
|
|
81
|
-
Clan joined after tournament start
|
|
79
|
+
Clan joined after tournament start. Note: a `registerInTournament`
|
|
80
|
+
response code that shares this enum — never returned by `joinClan`.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Interface: AvatarCustomizeResponse
|
|
2
|
+
|
|
3
|
+
Result of `_smartico.api.avatarsCustomize()`. On success only `cdn_url` is
|
|
4
|
+
set; on failure only `errCode` / `errMessage`.
|
|
5
|
+
|
|
6
|
+
## Properties
|
|
7
|
+
|
|
8
|
+
### cdn\_url?
|
|
9
|
+
|
|
10
|
+
> `optional` **cdn\_url?**: `string`
|
|
11
|
+
|
|
12
|
+
CDN URL of the generated avatar variant. Present on success.
|
|
13
|
+
|
|
14
|
+
***
|
|
15
|
+
|
|
16
|
+
### errCode?
|
|
17
|
+
|
|
18
|
+
> `optional` **errCode?**: `number`
|
|
19
|
+
|
|
20
|
+
Error code. Present on failure. Typed values are members of
|
|
21
|
+
[AvatarCustomizeErrorCode](../enumerations/AvatarCustomizeErrorCode.md); `-1` is a generic failure. See the
|
|
22
|
+
`avatarsCustomize` TSDoc for the full table.
|
|
23
|
+
|
|
24
|
+
***
|
|
25
|
+
|
|
26
|
+
### errMessage?
|
|
27
|
+
|
|
28
|
+
> `optional` **errMessage?**: `string`
|
|
29
|
+
|
|
30
|
+
Optional error message. Present on failure; the generic (`-1`) message
|
|
31
|
+
is fixed text, so branch on `errCode`, not this string.
|
|
@@ -33,7 +33,7 @@ Absolute CDN URL of the prompt's preview icon.
|
|
|
33
33
|
|
|
34
34
|
> **cost\_currency\_type\_id**: `number`
|
|
35
35
|
|
|
36
|
-
Currency used to pay for the customization. `0` = points, `1` = gems, `2` = diamonds.
|
|
36
|
+
Currency used to pay for the customization. `0` = points, `1` = gems, `2` = diamonds, `3` = free. A `cost_value` of `0` is also free.
|
|
37
37
|
|
|
38
38
|
***
|
|
39
39
|
|
|
@@ -41,4 +41,4 @@ Currency used to pay for the customization. `0` = points, `1` = gems, `2` = diam
|
|
|
41
41
|
|
|
42
42
|
> **cost\_value**: `number`
|
|
43
43
|
|
|
44
|
-
Cost amount in the currency named by `cost_currency_type_id`.
|
|
44
|
+
Cost amount in the currency named by `cost_currency_type_id`. `0` = free.
|
|
@@ -44,6 +44,22 @@ Reward for completing the task in points
|
|
|
44
44
|
|
|
45
45
|
***
|
|
46
46
|
|
|
47
|
+
### gems\_reward?
|
|
48
|
+
|
|
49
|
+
> `optional` **gems\_reward?**: `number`
|
|
50
|
+
|
|
51
|
+
Reward for completing the task in gems
|
|
52
|
+
|
|
53
|
+
***
|
|
54
|
+
|
|
55
|
+
### diamonds\_reward?
|
|
56
|
+
|
|
57
|
+
> `optional` **diamonds\_reward?**: `number`
|
|
58
|
+
|
|
59
|
+
Reward for completing the task in diamonds
|
|
60
|
+
|
|
61
|
+
***
|
|
62
|
+
|
|
47
63
|
### execution\_count\_expected?
|
|
48
64
|
|
|
49
65
|
> `optional` **execution\_count\_expected?**: `number`
|
|
@@ -20,6 +20,22 @@
|
|
|
20
20
|
|
|
21
21
|
***
|
|
22
22
|
|
|
23
|
+
### gems\_reward?
|
|
24
|
+
|
|
25
|
+
> `optional` **gems\_reward?**: `number`
|
|
26
|
+
|
|
27
|
+
Gems awarded when this task is completed.
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
31
|
+
### diamonds\_reward?
|
|
32
|
+
|
|
33
|
+
> `optional` **diamonds\_reward?**: `number`
|
|
34
|
+
|
|
35
|
+
Diamonds awarded when this task is completed.
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
23
39
|
### task\_type\_id
|
|
24
40
|
|
|
25
41
|
> **task\_type\_id**: [`AchievementTaskType`](../enumerations/AchievementTaskType.md)
|
package/docs/native/PROTOCOL.md
CHANGED
|
@@ -1802,6 +1802,8 @@ Join (or switch to) a clan. On labels with no cooldown, switching clans re-charg
|
|
|
1802
1802
|
|
|
1803
1803
|
Avatar selection (`setAvatar`) is documented under [User](#setavatar). The methods below read the avatar catalog and the user's AI-customized avatars.
|
|
1804
1804
|
|
|
1805
|
+
> **Note:** Generating a new AI-customized variant (`avatarsCustomize` in the JS SDK) is a separate **HTTP POST** to the avatar server, not part of this WebSocket protocol. It returns a CDN URL that you then activate via `setAvatar`. Native clients must call that HTTP endpoint directly; it is out of scope for this spec.
|
|
1806
|
+
|
|
1805
1807
|
### getAvatarsList
|
|
1806
1808
|
|
|
1807
1809
|
Get the avatar catalog available to the current user.
|
|
@@ -1862,7 +1864,7 @@ No method-specific fields. Send only the common fields (see [Common Message Fiel
|
|
|
1862
1864
|
|-------|------|-------------|
|
|
1863
1865
|
| `prompts` | [`AvatarPrompt[]`](../api/interfaces/AvatarPrompt.md) | Available AI style prompts |
|
|
1864
1866
|
|
|
1865
|
-
> **Note:** Prompt name/icon are nested at `public_meta.name` / `public_meta.icon_url`. `cost_currency_type_id`: `0` = points, `1` = gems, `2` = diamonds; `cost_value` is the amount.
|
|
1867
|
+
> **Note:** Prompt name/icon are nested at `public_meta.name` / `public_meta.icon_url`. `cost_currency_type_id`: `0` = points, `1` = gems, `2` = diamonds, `3` = free; `cost_value` is the amount (a `cost_value` of `0` is also free).
|
|
1866
1868
|
|
|
1867
1869
|
---
|
|
1868
1870
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# UI Guide — `avatarsCustomize`
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
- A **paid, generate-only** AI step: it applies an operator-defined style
|
|
5
|
+
prompt to a base avatar and returns a `cdn_url` for the generated image.
|
|
6
|
+
- It does **not** change the user's active avatar. Activation is a second,
|
|
7
|
+
explicit step — call `setAvatar({ avatar_url: cdn_url, avatar_real_id })`.
|
|
8
|
+
- Synchronous and slow (~5–20 s). No SDK cache, no push.
|
|
9
|
+
|
|
10
|
+
## Flow (the default Smartico UI)
|
|
11
|
+
1. **Pick a base avatar** from the avatar catalogue (`getAvatarsList()` /
|
|
12
|
+
`getAvatarsCustomized()`), then open the "Customize" panel.
|
|
13
|
+
2. **Pick a style prompt** from `getAvatarPrompts()`. Each prompt carries its
|
|
14
|
+
cost (`cost_currency_type_id` + `cost_value`); render the price on the
|
|
15
|
+
prompt tile and pre-disable prompts the user can't afford (compare against
|
|
16
|
+
the balances on `getUserProfile()`).
|
|
17
|
+
3. **Generate.** On tap, call `avatarsCustomize(...)`. Immediately enter a
|
|
18
|
+
loading state (see below) and lock the prompt list + Generate button.
|
|
19
|
+
4. **Preview.** On success, render `cdn_url` as a preview. The user can keep
|
|
20
|
+
browsing previously generated variants (they live in the customization
|
|
21
|
+
history surfaced by `getAvatarsCustomized()`).
|
|
22
|
+
5. **Apply (explicit).** Only when the user taps "Apply" do you call
|
|
23
|
+
`setAvatar(...)` with the currently-selected URL (which may be the new
|
|
24
|
+
`cdn_url`, a history item, or the untouched base avatar).
|
|
25
|
+
|
|
26
|
+
## Loading state
|
|
27
|
+
- The generation blocks for several seconds. Show a spinner/skeleton in the
|
|
28
|
+
preview slot for the full duration; keep the modal open.
|
|
29
|
+
- Disable the Generate trigger and the prompt list while in flight — there is
|
|
30
|
+
no SDK-side debounce, so a second tap fires a second (charged) generation.
|
|
31
|
+
|
|
32
|
+
## Cost gating
|
|
33
|
+
- Read `cost_currency_type_id` (`0` points · `1` gems · `2` diamonds · `3`
|
|
34
|
+
free) and `cost_value` from the chosen `getAvatarPrompts()` entry.
|
|
35
|
+
- `cost_value === 0` (or type `3`) is free.
|
|
36
|
+
- Gate before calling: if the user can't afford the prompt, disable the tile
|
|
37
|
+
and show the price; don't rely on the server to be the only guard
|
|
38
|
+
(insufficient balance comes back as the generic `-1`).
|
|
39
|
+
|
|
40
|
+
## Error / limit handling
|
|
41
|
+
| Result | UI |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `cdn_url` set | Success. Render the preview; enable "Apply". |
|
|
44
|
+
| `errCode === 12001` | User hit their **monthly per-user cap**. Show e.g. "You've used all your custom avatars this month." Nothing was charged. |
|
|
45
|
+
| `errCode === 12002` | The **brand's monthly pool** is exhausted. Show "Custom avatars are unavailable right now — try again later." Nothing was charged. |
|
|
46
|
+
| `errCode === -1` | Generic failure (insufficient balance, unavailable prompt, generation error). Show a retryable error; nothing was charged. `errMessage` is fixed text — don't surface it as the reason. |
|
|
47
|
+
|
|
48
|
+
Both monthly caps are operator-configured and reset at the start of each
|
|
49
|
+
calendar month.
|
|
50
|
+
|
|
51
|
+
## Important behavioral caveats
|
|
52
|
+
- **Generation is irreversible and counts toward the monthly caps on success
|
|
53
|
+
— even if the user never applies it.** Don't auto-generate on hover/scroll;
|
|
54
|
+
require an explicit tap.
|
|
55
|
+
- **Apply uses the currently-selected image**, which may be the new variant, a
|
|
56
|
+
history item, or the base avatar. Track selection explicitly so "Apply"
|
|
57
|
+
sends the right URL.
|
|
58
|
+
- After a successful generation the SDK refreshes the
|
|
59
|
+
`getAvatarsCustomized()` cache, so the new variant appears in the history
|
|
60
|
+
list on the next call.
|
|
61
|
+
|
|
62
|
+
## Empty / unavailable states
|
|
63
|
+
- No prompts returned by `getAvatarPrompts()` → hide the Customize entry point.
|
|
64
|
+
- `12002` for the whole brand → consider hiding/greying the Customize entry
|
|
65
|
+
point until next month rather than letting every tap fail.
|
|
66
|
+
|
|
67
|
+
## Visitor mode
|
|
68
|
+
- Not supported — `avatarsCustomize` throws in visitor mode. Hide the
|
|
69
|
+
customization surface for unauthenticated sessions.
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Limit error codes returned in `errCode` by the `avatarsCustomize` method.
|
|
3
|
+
* See the `avatarsCustomize` TSDoc for the full table (including the generic
|
|
4
|
+
* `-1` failure, which has no named member here).
|
|
5
|
+
*/
|
|
1
6
|
export enum AvatarCustomizeErrorCode {
|
|
7
|
+
/** The user has reached the operator-configured per-user monthly cap on custom-avatar generations. */
|
|
2
8
|
AVATAR_USER_LIMIT = 12001,
|
|
9
|
+
/** The brand's operator-configured shared monthly pool of custom-avatar generations is exhausted. */
|
|
3
10
|
AVATAR_LABEL_LIMIT = 12002,
|
|
4
11
|
}
|
|
5
|
-
|
|
6
|
-
export const AvatarCustomizeErrorMessage: Record<AvatarCustomizeErrorCode, string> = {
|
|
7
|
-
[AvatarCustomizeErrorCode.AVATAR_USER_LIMIT]: 'You have exceeded number of custom avatars creation, please try later',
|
|
8
|
-
[AvatarCustomizeErrorCode.AVATAR_LABEL_LIMIT]: 'The custom avatars are not available, please try again later',
|
|
9
|
-
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AvatarCustomizeErrorCode } from './AvatarCustomizeErrorCode';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result of `_smartico.api.avatarsCustomize()`. On success only `cdn_url` is
|
|
5
|
+
* set; on failure only `errCode` / `errMessage`.
|
|
6
|
+
*/
|
|
7
|
+
export interface AvatarCustomizeResponse {
|
|
8
|
+
/** CDN URL of the generated avatar variant. Present on success. */
|
|
9
|
+
cdn_url?: string;
|
|
10
|
+
/** Error code. Present on failure. Typed values are members of
|
|
11
|
+
* {@link AvatarCustomizeErrorCode}; `-1` is a generic failure. See the
|
|
12
|
+
* `avatarsCustomize` TSDoc for the full table. */
|
|
13
|
+
errCode?: AvatarCustomizeErrorCode | number;
|
|
14
|
+
/** Optional error message. Present on failure; the generic (`-1`) message
|
|
15
|
+
* is fixed text, so branch on `errCode`, not this string. */
|
|
16
|
+
errMessage?: string;
|
|
17
|
+
}
|
package/src/Avatars/index.ts
CHANGED
|
@@ -123,6 +123,8 @@ export const UserAchievementTransform = (items: UserAchievement[]): TMissionOrBa
|
|
|
123
123
|
id: t.task_id,
|
|
124
124
|
name: t.task_public_meta?.name,
|
|
125
125
|
points_reward: t.points_reward,
|
|
126
|
+
gems_reward: t.gems_reward,
|
|
127
|
+
diamonds_reward: t.diamonds_reward,
|
|
126
128
|
is_completed: t.isCompleted,
|
|
127
129
|
progress: t.userProgress,
|
|
128
130
|
execution_count_expected: t.executionCount,
|
|
@@ -6,6 +6,10 @@ export interface UserAchievementTask {
|
|
|
6
6
|
task_id?: number;
|
|
7
7
|
task_public_meta?: AchievementTaskPublicMeta;
|
|
8
8
|
points_reward?: number;
|
|
9
|
+
/** Gems awarded when this task is completed. */
|
|
10
|
+
gems_reward?: number;
|
|
11
|
+
/** Diamonds awarded when this task is completed. */
|
|
12
|
+
diamonds_reward?: number;
|
|
9
13
|
task_type_id: AchievementTaskType;
|
|
10
14
|
isCompleted?: boolean;
|
|
11
15
|
userExecutedCount?: number; // This is the number of times the user has executed 'activity' of the task. e.g. he bet 5 times out of 100. here will be 5
|