@amityco/ts-sdk 7.28.0 → 7.28.1-1ea66ee3.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/dist/@types/core/errors.d.ts +4 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -0
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +13 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +86 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +11 -0
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +31 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/searchChannels/SearchChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/tests/integrations/getChannelsSortByLastMessage.integration.test.d.ts +2 -0
- package/dist/channelRepository/observers/tests/integrations/getChannelsSortByLastMessage.integration.test.d.ts.map +1 -0
- package/dist/channelRepository/utils/channelActivityOnLoginHandler.d.ts +16 -0
- package/dist/channelRepository/utils/channelActivityOnLoginHandler.d.ts.map +1 -0
- package/dist/channelRepository/utils/tests/integrations/channelActivity.integration.test.d.ts +2 -0
- package/dist/channelRepository/utils/tests/integrations/channelActivity.integration.test.d.ts.map +1 -0
- package/dist/channelRepository/utils/tests/updateChannelActivityTimestamps.test.d.ts +2 -0
- package/dist/channelRepository/utils/tests/updateChannelActivityTimestamps.test.d.ts.map +1 -0
- package/dist/channelRepository/utils/updateChannelActivityTimestamps.d.ts +34 -0
- package/dist/channelRepository/utils/updateChannelActivityTimestamps.d.ts.map +1 -0
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getModuleSettings.d.ts +25 -0
- package/dist/client/api/getModuleSettings.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/resumeSession.d.ts.map +1 -1
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/client/api/tests/integration/moduleSettings.integration.test.d.ts +2 -0
- package/dist/client/api/tests/integration/moduleSettings.integration.test.d.ts.map +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/utils/parseModuleSettings.d.ts +9 -0
- package/dist/client/utils/parseModuleSettings.d.ts.map +1 -0
- package/dist/client/utils/resolveModuleAvailability.d.ts +39 -0
- package/dist/client/utils/resolveModuleAvailability.d.ts.map +1 -0
- package/dist/client/utils/tests/resolveModuleAvailability.test.d.ts +2 -0
- package/dist/client/utils/tests/resolveModuleAvailability.test.d.ts.map +1 -0
- package/dist/commentRepository/api/flagComment.d.ts +72 -5
- package/dist/commentRepository/api/flagComment.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/flagCommentWithOptions.d.ts +13 -0
- package/dist/commentRepository/internalApi/flagCommentWithOptions.d.ts.map +1 -0
- package/dist/commentRepository/internalApi/flagCommentWithReasonString.d.ts +17 -0
- package/dist/commentRepository/internalApi/flagCommentWithReasonString.d.ts.map +1 -0
- package/dist/commentRepository/internalApi/index.d.ts +2 -0
- package/dist/commentRepository/internalApi/index.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/tests/integration/flagCommentWithOptions.integration.test.d.ts +2 -0
- package/dist/commentRepository/internalApi/tests/integration/flagCommentWithOptions.integration.test.d.ts.map +1 -0
- package/dist/commentRepository/internalApi/tests/integration/flagCommentWithReasonString.integration.test.d.ts +2 -0
- package/dist/commentRepository/internalApi/tests/integration/flagCommentWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/core/errors.d.ts +20 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/microtasks.d.ts.map +1 -1
- package/dist/core/query/sorting.d.ts +10 -0
- package/dist/core/query/sorting.d.ts.map +1 -1
- package/dist/core/query/tests/sorting.test.d.ts +2 -0
- package/dist/core/query/tests/sorting.test.d.ts.map +1 -0
- package/dist/core/tests/microtasks.test.d.ts +2 -0
- package/dist/core/tests/microtasks.test.d.ts.map +1 -0
- package/dist/core/transports/tests/integration/serverErrorCodes.integration.test.d.ts +2 -0
- package/dist/core/transports/tests/integration/serverErrorCodes.integration.test.d.ts.map +1 -0
- package/dist/core/transports/tests/moduleNotEntitled.test.d.ts +2 -0
- package/dist/core/transports/tests/moduleNotEntitled.test.d.ts.map +1 -0
- package/dist/core/transports/utils.d.ts.map +1 -1
- package/dist/index.cjs.js +853 -68
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +851 -69
- package/dist/index.umd.js +2 -2
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
- package/dist/messageRepository/api/flagMessage.d.ts +73 -6
- package/dist/messageRepository/api/flagMessage.d.ts.map +1 -1
- package/dist/messageRepository/api/tests/integration/flagMessage.overloads.integration.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/integration/flagMessage.overloads.integration.test.d.ts.map +1 -0
- package/dist/messageRepository/internalApi/flagMessageWithOptions.d.ts +13 -0
- package/dist/messageRepository/internalApi/flagMessageWithOptions.d.ts.map +1 -0
- package/dist/messageRepository/internalApi/flagMessageWithReasonString.d.ts +18 -0
- package/dist/messageRepository/internalApi/flagMessageWithReasonString.d.ts.map +1 -0
- package/dist/messageRepository/internalApi/tests/integration/flagMessageWithOptions.integration.test.d.ts +2 -0
- package/dist/messageRepository/internalApi/tests/integration/flagMessageWithOptions.integration.test.d.ts.map +1 -0
- package/dist/messageRepository/internalApi/tests/integration/flagMessageWithReasonString.integration.test.d.ts +2 -0
- package/dist/messageRepository/internalApi/tests/integration/flagMessageWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/postRepository/api/flagPost.d.ts +73 -6
- package/dist/postRepository/api/flagPost.d.ts.map +1 -1
- package/dist/postRepository/api/tests/integration/flagPost.overloads.integration.test.d.ts +2 -0
- package/dist/postRepository/api/tests/integration/flagPost.overloads.integration.test.d.ts.map +1 -0
- package/dist/postRepository/internalApi/flagPostWithOptions.d.ts +13 -0
- package/dist/postRepository/internalApi/flagPostWithOptions.d.ts.map +1 -0
- package/dist/postRepository/internalApi/flagPostWithReasonString.d.ts +17 -0
- package/dist/postRepository/internalApi/flagPostWithReasonString.d.ts.map +1 -0
- package/dist/postRepository/internalApi/index.d.ts +2 -0
- package/dist/postRepository/internalApi/index.d.ts.map +1 -1
- package/dist/postRepository/internalApi/tests/integration/flagPostWithOptions.integration.test.d.ts +2 -0
- package/dist/postRepository/internalApi/tests/integration/flagPostWithOptions.integration.test.d.ts.map +1 -0
- package/dist/postRepository/internalApi/tests/integration/flagPostWithReasonString.integration.test.d.ts +2 -0
- package/dist/postRepository/internalApi/tests/integration/flagPostWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/userRepository/api/flagUser.d.ts +50 -9
- package/dist/userRepository/api/flagUser.d.ts.map +1 -1
- package/dist/userRepository/api/flagUserBehavior.d.ts +29 -0
- package/dist/userRepository/api/flagUserBehavior.d.ts.map +1 -0
- package/dist/userRepository/api/flagUserProfile.d.ts +29 -0
- package/dist/userRepository/api/flagUserProfile.d.ts.map +1 -0
- package/dist/userRepository/api/index.d.ts +2 -0
- package/dist/userRepository/api/index.d.ts.map +1 -1
- package/dist/userRepository/api/tests/integration/flagUser.overloads.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUser.overloads.integration.test.d.ts.map +1 -0
- package/dist/userRepository/api/tests/integration/flagUserBehavior.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUserBehavior.integration.test.d.ts.map +1 -0
- package/dist/userRepository/api/tests/integration/flagUserProfile.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUserProfile.integration.test.d.ts.map +1 -0
- package/dist/userRepository/utils/submitUserReport.d.ts +10 -0
- package/dist/userRepository/utils/submitUserReport.d.ts.map +1 -0
- package/dist/userRepository/utils/userReport.d.ts +35 -0
- package/dist/userRepository/utils/userReport.d.ts.map +1 -0
- package/dist/utils/contentFlag.d.ts +28 -0
- package/dist/utils/contentFlag.d.ts.map +1 -0
- package/dist/utils/tests/dummy/channel.d.ts +4 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -58,6 +58,18 @@ exports.UserReportTypeEnum = void 0;
|
|
|
58
58
|
UserReportTypeEnum["AVATAR"] = "avatarFileId";
|
|
59
59
|
UserReportTypeEnum["BEHAVIOR"] = "behavior";
|
|
60
60
|
})(exports.UserReportTypeEnum || (exports.UserReportTypeEnum = {}));
|
|
61
|
+
/**
|
|
62
|
+
* The profile field a user is reported for in `UserRepository.flagUserProfile`.
|
|
63
|
+
* Each member is the backend `reportType` wire value. There is deliberately no
|
|
64
|
+
* behavior member: behavior reports need a reason and go through
|
|
65
|
+
* `UserRepository.flagUserBehavior`.
|
|
66
|
+
*/
|
|
67
|
+
exports.UserProfileFieldEnum = void 0;
|
|
68
|
+
(function (UserProfileFieldEnum) {
|
|
69
|
+
UserProfileFieldEnum["DISPLAY_NAME"] = "displayName";
|
|
70
|
+
UserProfileFieldEnum["DESCRIPTION"] = "description";
|
|
71
|
+
UserProfileFieldEnum["AVATAR"] = "avatarFileId";
|
|
72
|
+
})(exports.UserProfileFieldEnum || (exports.UserProfileFieldEnum = {}));
|
|
61
73
|
|
|
62
74
|
const FileType = Object.freeze({
|
|
63
75
|
FILE: 'file',
|
|
@@ -812,6 +824,40 @@ class ASCConnectionError extends ASCError {
|
|
|
812
824
|
this.event = event;
|
|
813
825
|
}
|
|
814
826
|
}
|
|
827
|
+
/**
|
|
828
|
+
* Thrown when the network does not own a module the call needs. Raised from
|
|
829
|
+
* any module endpoint under `enforce` enforcement, mapped from app code
|
|
830
|
+
* `400325` — never from HTTP 403 alone, which already covers a role problem
|
|
831
|
+
* (`400300` / `400301`), a visitor (`403999`) and a bot (`403998`).
|
|
832
|
+
*
|
|
833
|
+
* `modules` carries **every** key the refusal named, as raw strings, so a
|
|
834
|
+
* caller can say which entitlement is absent without a second request.
|
|
835
|
+
*
|
|
836
|
+
* @category Errors
|
|
837
|
+
*/
|
|
838
|
+
class AmityModuleNotEntitledError extends ASCApiError {
|
|
839
|
+
/**
|
|
840
|
+
* @param message The server's message, e.g. `Module not entitled: chat, live`
|
|
841
|
+
* @param modules Every module key from the rejection's `data.modules`
|
|
842
|
+
*/
|
|
843
|
+
constructor(message, modules = []) {
|
|
844
|
+
super(message, 400325 /* Amity.ServerError.MODULE_NOT_ENTITLED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
845
|
+
this.modules = modules;
|
|
846
|
+
this.type = 'AmityModuleNotEntitledError';
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Input sanitization related error
|
|
851
|
+
* @category Errors
|
|
852
|
+
*/
|
|
853
|
+
class ASCInvalidParameterError extends ASCError {
|
|
854
|
+
/**
|
|
855
|
+
* @param message A custom error message
|
|
856
|
+
*/
|
|
857
|
+
constructor(message) {
|
|
858
|
+
super(message, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
815
861
|
|
|
816
862
|
let activeClient = null;
|
|
817
863
|
/**
|
|
@@ -1585,6 +1631,24 @@ const sortByLastUpdated = ({ updatedAt: a = 0 }, { updatedAt: b = 0 }) => new Da
|
|
|
1585
1631
|
* Sorting a collection by the items with most recent activity
|
|
1586
1632
|
*/
|
|
1587
1633
|
const sortByLastActivity = ({ lastActivity: a }, { lastActivity: b }) => new Date(b).valueOf() - new Date(a).valueOf();
|
|
1634
|
+
/**
|
|
1635
|
+
* Sorting a channel collection by the time of its newest message (newest first).
|
|
1636
|
+
* Channels whose `lastMessageAt` is `null` sort last, ordered by `createdAt`
|
|
1637
|
+
* (newest first) among themselves, matching the server's `sortBy=lastMessage`
|
|
1638
|
+
* order so the local sort agrees with the page order.
|
|
1639
|
+
*/
|
|
1640
|
+
const sortByLastMessage = (a, b) => {
|
|
1641
|
+
var _a, _b;
|
|
1642
|
+
const aAt = (_a = a.lastMessageAt) !== null && _a !== void 0 ? _a : null;
|
|
1643
|
+
const bAt = (_b = b.lastMessageAt) !== null && _b !== void 0 ? _b : null;
|
|
1644
|
+
if (aAt !== null && bAt !== null)
|
|
1645
|
+
return new Date(bAt).valueOf() - new Date(aAt).valueOf();
|
|
1646
|
+
if (aAt !== null)
|
|
1647
|
+
return -1;
|
|
1648
|
+
if (bAt !== null)
|
|
1649
|
+
return 1;
|
|
1650
|
+
return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf();
|
|
1651
|
+
};
|
|
1588
1652
|
/**
|
|
1589
1653
|
* Filter items by untilAt timestamp based on sort direction
|
|
1590
1654
|
* - For 'lastCreated' (newest first): untilAt acts as lower bound, excludes items older than boundary
|
|
@@ -1669,8 +1733,13 @@ const scheduleTask = (task) => {
|
|
|
1669
1733
|
clearTimeout(timer);
|
|
1670
1734
|
tasks.push(task);
|
|
1671
1735
|
timer = setTimeout(() => {
|
|
1672
|
-
|
|
1736
|
+
// Swap the queue out before running it. A task that schedules another task
|
|
1737
|
+
// while the batch runs (an event handler that fires an event) must land in
|
|
1738
|
+
// a fresh queue and its own timer, not in the array being drained and then
|
|
1739
|
+
// discarded.
|
|
1740
|
+
const batch = tasks;
|
|
1673
1741
|
tasks = [];
|
|
1742
|
+
batch.forEach(fn => fn());
|
|
1674
1743
|
}, 0);
|
|
1675
1744
|
};
|
|
1676
1745
|
|
|
@@ -1961,6 +2030,22 @@ function computeUrl(type, region) {
|
|
|
1961
2030
|
|
|
1962
2031
|
const uuid = () => uuid__default["default"].v4().toString();
|
|
1963
2032
|
|
|
2033
|
+
/**
|
|
2034
|
+
* Reads the module keys a `MODULE_NOT_ENTITLED` rejection named.
|
|
2035
|
+
*
|
|
2036
|
+
* Every entry is kept, as a raw string: one call can need more than one
|
|
2037
|
+
* module, and a key this build predates is still the only part of the
|
|
2038
|
+
* payload a customer can act on.
|
|
2039
|
+
*
|
|
2040
|
+
* @category Transport
|
|
2041
|
+
* @hidden
|
|
2042
|
+
*/
|
|
2043
|
+
const extractNotEntitledModules = (data) => {
|
|
2044
|
+
const { modules } = data !== null && data !== void 0 ? data : {};
|
|
2045
|
+
if (!Array.isArray(modules))
|
|
2046
|
+
return [];
|
|
2047
|
+
return modules.filter((module) => typeof module === 'string');
|
|
2048
|
+
};
|
|
1964
2049
|
/**
|
|
1965
2050
|
* Unwraps v3 server payload (for error handling and type extraction)
|
|
1966
2051
|
*
|
|
@@ -1980,6 +2065,15 @@ const unwrapPayload = (response) => {
|
|
|
1980
2065
|
throw new ASCUnknownError(response.code);
|
|
1981
2066
|
}
|
|
1982
2067
|
else if (response.status === 'error') {
|
|
2068
|
+
/*
|
|
2069
|
+
* An entitlement refusal must not arrive as a generic failure: a customer
|
|
2070
|
+
* cannot then tell a module they have not bought from an outage. Keyed on
|
|
2071
|
+
* the app code, never on the HTTP status, so a role or membership problem
|
|
2072
|
+
* still maps to the generic error.
|
|
2073
|
+
*/
|
|
2074
|
+
if (response.code === 400325 /* Amity.ServerError.MODULE_NOT_ENTITLED */) {
|
|
2075
|
+
throw new AmityModuleNotEntitledError(response.message, extractNotEntitledModules(response.data));
|
|
2076
|
+
}
|
|
1983
2077
|
throw new ASCApiError(response.message, response.code, "error" /* Amity.ErrorLevel.ERROR */);
|
|
1984
2078
|
}
|
|
1985
2079
|
// unjust, but helps force uncast "T | undefined" to allow deconstruction without warnings
|
|
@@ -5476,6 +5570,95 @@ const getForYouFeedSetting = async () => {
|
|
|
5476
5570
|
};
|
|
5477
5571
|
/* end_public_function */
|
|
5478
5572
|
|
|
5573
|
+
const ENFORCEMENT_MODES = ['off', 'shadow', 'enforce'];
|
|
5574
|
+
/**
|
|
5575
|
+
* An unrecognised mode decodes to `off`, and so does an absent one. A mode
|
|
5576
|
+
* this build does not know must not withhold anything — defaulting to
|
|
5577
|
+
* `enforce` would let a server-side rename black out a customer's app.
|
|
5578
|
+
*
|
|
5579
|
+
* @category private
|
|
5580
|
+
*/
|
|
5581
|
+
const parseEnforcement = (mode) => {
|
|
5582
|
+
const match = ENFORCEMENT_MODES.find(value => value === mode);
|
|
5583
|
+
return match !== null && match !== void 0 ? match : 'off';
|
|
5584
|
+
};
|
|
5585
|
+
const parseGrants = (modules) => {
|
|
5586
|
+
const grants = {};
|
|
5587
|
+
Object.entries(modules !== null && modules !== void 0 ? modules : {}).forEach(([key, granted]) => {
|
|
5588
|
+
grants[key] = granted === true;
|
|
5589
|
+
});
|
|
5590
|
+
return grants;
|
|
5591
|
+
};
|
|
5592
|
+
/**
|
|
5593
|
+
* Every catalog entry survives, including one whose key this build has never
|
|
5594
|
+
* heard of, so a module added server-side is still listable.
|
|
5595
|
+
*
|
|
5596
|
+
* @category private
|
|
5597
|
+
*/
|
|
5598
|
+
const parseCatalog = (catalog) => {
|
|
5599
|
+
const parsed = {};
|
|
5600
|
+
Object.entries(catalog !== null && catalog !== void 0 ? catalog : {}).forEach(([key, definition]) => {
|
|
5601
|
+
const rawRequires = definition === null || definition === void 0 ? void 0 : definition.requires;
|
|
5602
|
+
const requires = Array.isArray(rawRequires)
|
|
5603
|
+
? rawRequires.filter((entry) => typeof entry === 'string')
|
|
5604
|
+
: [];
|
|
5605
|
+
parsed[key] = {
|
|
5606
|
+
label: typeof (definition === null || definition === void 0 ? void 0 : definition.label) === 'string' ? definition.label : key,
|
|
5607
|
+
kind: (definition === null || definition === void 0 ? void 0 : definition.kind) === 'setting' ? 'setting' : 'api',
|
|
5608
|
+
requires,
|
|
5609
|
+
};
|
|
5610
|
+
});
|
|
5611
|
+
return parsed;
|
|
5612
|
+
};
|
|
5613
|
+
/**
|
|
5614
|
+
* Decodes `GET /api/v3/network-settings/modules`. Nothing is trimmed: the
|
|
5615
|
+
* catalog is the dependency table callers resolve against, and a client that
|
|
5616
|
+
* cannot see it has to hardcode one.
|
|
5617
|
+
*
|
|
5618
|
+
* @category private
|
|
5619
|
+
*/
|
|
5620
|
+
const parseModuleSettings = (raw) => {
|
|
5621
|
+
var _a;
|
|
5622
|
+
return ({
|
|
5623
|
+
enforcement: parseEnforcement((_a = raw === null || raw === void 0 ? void 0 : raw.enforcement) !== null && _a !== void 0 ? _a : raw === null || raw === void 0 ? void 0 : raw.mode),
|
|
5624
|
+
modules: parseGrants(raw === null || raw === void 0 ? void 0 : raw.modules),
|
|
5625
|
+
catalog: parseCatalog(raw === null || raw === void 0 ? void 0 : raw.catalog),
|
|
5626
|
+
});
|
|
5627
|
+
};
|
|
5628
|
+
|
|
5629
|
+
/* begin_public_function
|
|
5630
|
+
id: client.getModuleSettings
|
|
5631
|
+
*/
|
|
5632
|
+
/**
|
|
5633
|
+
* ```js
|
|
5634
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
5635
|
+
* const moduleSettings = await Client.getModuleSettings()
|
|
5636
|
+
* ```
|
|
5637
|
+
*
|
|
5638
|
+
* Fetches the network's module entitlements: which modules the network was
|
|
5639
|
+
* granted, whether core is enforcing those grants, and the catalog of all
|
|
5640
|
+
* modules with their dependency chains.
|
|
5641
|
+
*
|
|
5642
|
+
* The payload is returned whole — `catalog` is the dependency table
|
|
5643
|
+
* {@link resolveModuleAvailability} reads, and a client that cannot see it has
|
|
5644
|
+
* to hardcode one.
|
|
5645
|
+
*
|
|
5646
|
+
* The read is **advisory**. It tells a host what to offer; under `enforce` the
|
|
5647
|
+
* backend refuses a call to an unowned module regardless of what was resolved
|
|
5648
|
+
* here, and that refusal arrives as `AmityModuleNotEntitledError`.
|
|
5649
|
+
*
|
|
5650
|
+
* @returns A Promise of {@link Amity.ModuleSettings} object
|
|
5651
|
+
*
|
|
5652
|
+
* @category Client API
|
|
5653
|
+
* @async
|
|
5654
|
+
*/
|
|
5655
|
+
const getModuleSettings = async () => {
|
|
5656
|
+
const client = getActiveClient();
|
|
5657
|
+
const { data } = await client.http.get(`/api/v3/network-settings/modules`);
|
|
5658
|
+
return parseModuleSettings(data);
|
|
5659
|
+
};
|
|
5660
|
+
/* end_public_function */
|
|
5661
|
+
|
|
5479
5662
|
const checkUserPermission = (userId, permission) => {
|
|
5480
5663
|
var _a;
|
|
5481
5664
|
const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -7906,6 +8089,140 @@ const postCommentCountEngineOnLoginHandler = () => onSessionStateChange(state =>
|
|
|
7906
8089
|
}
|
|
7907
8090
|
});
|
|
7908
8091
|
|
|
8092
|
+
const BOTH_FIELDS = { lastActivity: true, lastMessageAt: true };
|
|
8093
|
+
/**
|
|
8094
|
+
* The channel cache is keyed by `channelInternalId`, but a message names its
|
|
8095
|
+
* channel by whichever id the producer had: the raw MQTT payload carries the
|
|
8096
|
+
* internal id, a converted `Amity.InternalMessage` carries the public id, and
|
|
8097
|
+
* the optimistic message carries the sub-channel's `channelId`. Try the direct
|
|
8098
|
+
* key first, then match any of the three ids.
|
|
8099
|
+
*/
|
|
8100
|
+
const findCachedChannel = (channelId) => {
|
|
8101
|
+
var _a, _b, _c;
|
|
8102
|
+
const direct = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8103
|
+
if (direct)
|
|
8104
|
+
return direct;
|
|
8105
|
+
return (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => data.channelInternalId === channelId ||
|
|
8106
|
+
data.channelId === channelId ||
|
|
8107
|
+
data.channelPublicId === channelId)) === null || _c === void 0 ? void 0 : _c.data;
|
|
8108
|
+
};
|
|
8109
|
+
const isNewer = (stored, at) => !stored || convertDateStringToTimestamp(stored) < convertDateStringToTimestamp(at);
|
|
8110
|
+
const isSameInstant = (stored, at) => !!stored && convertDateStringToTimestamp(stored) === convertDateStringToTimestamp(at);
|
|
8111
|
+
/** Pushes the changed fields in one write and emits one `local.channel.updated`. */
|
|
8112
|
+
const commit = (channel, changes) => {
|
|
8113
|
+
if (Object.keys(changes).length === 0)
|
|
8114
|
+
return false;
|
|
8115
|
+
const updated = shallowClone(channel, changes);
|
|
8116
|
+
// Write back under the key the cache actually uses (the resolver key), not
|
|
8117
|
+
// under `channel.channelId`, which can differ from `channelInternalId`.
|
|
8118
|
+
pushToCache(['channel', 'get', getResolver('channel')(updated)], updated);
|
|
8119
|
+
fireEvent('local.channel.updated', {
|
|
8120
|
+
channels: [updated],
|
|
8121
|
+
channelUsers: [],
|
|
8122
|
+
users: [],
|
|
8123
|
+
files: [],
|
|
8124
|
+
});
|
|
8125
|
+
return true;
|
|
8126
|
+
};
|
|
8127
|
+
/**
|
|
8128
|
+
* Single owner of every local write to a channel's ordering timestamps,
|
|
8129
|
+
* `lastActivity` and `lastMessageAt` (ChannelActivityService v1).
|
|
8130
|
+
*
|
|
8131
|
+
* - Monotonic per field: a field moves only when `at` is newer than the stored
|
|
8132
|
+
* value (or the stored value is `null`), so a late or replayed event never
|
|
8133
|
+
* moves a channel down the list.
|
|
8134
|
+
* - One write: both fields are read, compared and pushed in a single cache
|
|
8135
|
+
* update, followed by one `local.channel.updated` event so every open channel
|
|
8136
|
+
* collection re-sorts once.
|
|
8137
|
+
* - Server channel payloads never go through here; they overwrite unguarded.
|
|
8138
|
+
*
|
|
8139
|
+
* @returns `true` when at least one field moved
|
|
8140
|
+
* @category private
|
|
8141
|
+
*/
|
|
8142
|
+
const updateChannelActivityTimestamps = (channelId, at, fields = BOTH_FIELDS) => {
|
|
8143
|
+
const client = getActiveClient();
|
|
8144
|
+
if (!client.cache || !channelId || !at)
|
|
8145
|
+
return false;
|
|
8146
|
+
const channel = findCachedChannel(channelId);
|
|
8147
|
+
if (!channel)
|
|
8148
|
+
return false;
|
|
8149
|
+
const changes = {};
|
|
8150
|
+
if (fields.lastActivity && isNewer(channel.lastActivity, at))
|
|
8151
|
+
changes.lastActivity = at;
|
|
8152
|
+
if (fields.lastMessageAt && isNewer(channel.lastMessageAt, at))
|
|
8153
|
+
changes.lastMessageAt = at;
|
|
8154
|
+
return commit(channel, changes);
|
|
8155
|
+
};
|
|
8156
|
+
/**
|
|
8157
|
+
* Local correction for the current user's own send (ChannelActivityService v1
|
|
8158
|
+
* REQ-009, Trigger Matrix row 1b). Once the server confirms the message, each
|
|
8159
|
+
* field that still holds the device-clock `localAt` written at send time is
|
|
8160
|
+
* replaced by the server's `serverAt`, even when that is older. A field a newer
|
|
8161
|
+
* message has already moved is left alone. One write, one change notification,
|
|
8162
|
+
* nothing when neither field still holds `localAt`.
|
|
8163
|
+
*
|
|
8164
|
+
* @returns `true` when at least one field was replaced
|
|
8165
|
+
* @category private
|
|
8166
|
+
*/
|
|
8167
|
+
const confirmOwnMessage = (channelId, localAt, serverAt) => {
|
|
8168
|
+
const client = getActiveClient();
|
|
8169
|
+
if (!client.cache || !channelId || !localAt || !serverAt)
|
|
8170
|
+
return false;
|
|
8171
|
+
if (isSameInstant(localAt, serverAt))
|
|
8172
|
+
return false;
|
|
8173
|
+
const channel = findCachedChannel(channelId);
|
|
8174
|
+
if (!channel)
|
|
8175
|
+
return false;
|
|
8176
|
+
const changes = {};
|
|
8177
|
+
if (isSameInstant(channel.lastActivity, localAt))
|
|
8178
|
+
changes.lastActivity = serverAt;
|
|
8179
|
+
if (isSameInstant(channel.lastMessageAt, localAt))
|
|
8180
|
+
changes.lastMessageAt = serverAt;
|
|
8181
|
+
return commit(channel, changes);
|
|
8182
|
+
};
|
|
8183
|
+
|
|
8184
|
+
/**
|
|
8185
|
+
* Session-wide owner of the local `lastActivity` / `lastMessageAt` updates
|
|
8186
|
+
* (ChannelActivityService v1, Web migration rows W1 – W5).
|
|
8187
|
+
*
|
|
8188
|
+
* Registered once per session from `setupLoginSubscriptions` and
|
|
8189
|
+
* `resumeSession`, so the update runs whether or not a channel collection is
|
|
8190
|
+
* open, and exactly once per message however many collections are open.
|
|
8191
|
+
*
|
|
8192
|
+
* It listens to the raw events rather than `onMessageCreatedMqtt`, so it does
|
|
8193
|
+
* not duplicate that subscriber's side effects (mark-read, unread recount).
|
|
8194
|
+
*
|
|
8195
|
+
* @category private
|
|
8196
|
+
*/
|
|
8197
|
+
const channelActivityOnLoginHandler = () => {
|
|
8198
|
+
const client = getActiveClient();
|
|
8199
|
+
const disposers = [
|
|
8200
|
+
// Any user's new message, in any message feed of the channel. The raw
|
|
8201
|
+
// payload's `channelId` is the channel's internal id.
|
|
8202
|
+
createEventSubscriber(client, 'channelActivity', 'message.created', payload => {
|
|
8203
|
+
payload.messages.forEach(message => {
|
|
8204
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
8205
|
+
});
|
|
8206
|
+
}),
|
|
8207
|
+
// The current user's own send fires this three times: with the optimistic
|
|
8208
|
+
// message at send time (Syncing), on the create response (Synced), and on
|
|
8209
|
+
// failure (Error). The device-clock time of the Syncing / Error fires was
|
|
8210
|
+
// already applied synchronously in createMessageOptimistic, and replaying it
|
|
8211
|
+
// here could undo the server correction made on the response
|
|
8212
|
+
// (confirmOwnMessage). Only the server-confirmed fire goes through the guard.
|
|
8213
|
+
createEventSubscriber(client, 'channelActivity', 'local.message.created', payload => {
|
|
8214
|
+
payload.messages.forEach(message => {
|
|
8215
|
+
if (message.syncState !== "synced" /* Amity.SyncState.Synced */)
|
|
8216
|
+
return;
|
|
8217
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
8218
|
+
});
|
|
8219
|
+
}),
|
|
8220
|
+
];
|
|
8221
|
+
return () => {
|
|
8222
|
+
disposers.forEach(fn => fn());
|
|
8223
|
+
};
|
|
8224
|
+
};
|
|
8225
|
+
|
|
7909
8226
|
const EVENTS = [
|
|
7910
8227
|
'disconnected',
|
|
7911
8228
|
'error',
|
|
@@ -8095,7 +8412,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
8095
8412
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
8096
8413
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
8097
8414
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
8098
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler());
|
|
8415
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler(), channelActivityOnLoginHandler());
|
|
8099
8416
|
if (client.useLegacyUnreadCount) {
|
|
8100
8417
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
8101
8418
|
}
|
|
@@ -9200,6 +9517,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9200
9517
|
getMarkerSyncConsistentMode,
|
|
9201
9518
|
getProductCatalogueSetting,
|
|
9202
9519
|
getForYouFeedSetting,
|
|
9520
|
+
getModuleSettings,
|
|
9203
9521
|
/**
|
|
9204
9522
|
* Prefix for the deviceId key in the local storage or async storage.
|
|
9205
9523
|
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
@@ -9355,7 +9673,7 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
9355
9673
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9356
9674
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9357
9675
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
9358
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
9676
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), channelActivityOnLoginHandler());
|
|
9359
9677
|
if (client.useLegacyUnreadCount) {
|
|
9360
9678
|
subscriptions$1.push(readReceiptSyncEngineOnLoginHandler());
|
|
9361
9679
|
}
|
|
@@ -10245,6 +10563,92 @@ const getUserUnread = (callback) => {
|
|
|
10245
10563
|
};
|
|
10246
10564
|
};
|
|
10247
10565
|
|
|
10566
|
+
/**
|
|
10567
|
+
* ```js
|
|
10568
|
+
* import { Client, resolveModuleAvailability } from '@amityco/ts-sdk'
|
|
10569
|
+
*
|
|
10570
|
+
* const moduleSettings = await Client.getModuleSettings()
|
|
10571
|
+
*
|
|
10572
|
+
* if (resolveModuleAvailability(moduleSettings, 'live').isAvailable) {
|
|
10573
|
+
* // offer the Live entry point
|
|
10574
|
+
* }
|
|
10575
|
+
* ```
|
|
10576
|
+
*
|
|
10577
|
+
* Resolves whether one module is usable on this network.
|
|
10578
|
+
*
|
|
10579
|
+
* Availability is a function of all three fields of
|
|
10580
|
+
* {@link Amity.ModuleSettings} — the enforcement mode, the module's own grant,
|
|
10581
|
+
* and its prerequisite chain — combined in that order. Reading `modules`
|
|
10582
|
+
* directly contradicts the mode: staging answers `mode: 'off'` with
|
|
10583
|
+
* `modules: {}`, and every module still works.
|
|
10584
|
+
*
|
|
10585
|
+
* The dependency table comes from the payload's `catalog`, never from a
|
|
10586
|
+
* hardcoded copy, so a chain the backend changes takes effect without an SDK
|
|
10587
|
+
* release.
|
|
10588
|
+
*
|
|
10589
|
+
* The SDK does not hold the settings — the caller keeps what it fetched and
|
|
10590
|
+
* resolves against it. With no settings at all (a fetch that never succeeded)
|
|
10591
|
+
* the caller reads that as every module available: under `enforce` the backend
|
|
10592
|
+
* refuses the calls anyway, so the exposure is a screen that offers too much,
|
|
10593
|
+
* not one that withholds what a customer paid for.
|
|
10594
|
+
*
|
|
10595
|
+
* @param moduleSettings The network's module settings
|
|
10596
|
+
* @param moduleKey The module to resolve — an {@link Amity.ModuleKey}, so the
|
|
10597
|
+
* 15 keys this build knows complete and type-check while a catalog entry it
|
|
10598
|
+
* does not know still resolves.
|
|
10599
|
+
* @returns An {@link Amity.ModuleAvailability} answer
|
|
10600
|
+
*
|
|
10601
|
+
* @category Client API
|
|
10602
|
+
*/
|
|
10603
|
+
const resolveModuleAvailability = (moduleSettings, moduleKey, seen = new Set()) => {
|
|
10604
|
+
var _a, _b, _c, _d, _e;
|
|
10605
|
+
const isGranted = (_a = moduleSettings.modules[moduleKey]) !== null && _a !== void 0 ? _a : false;
|
|
10606
|
+
/*
|
|
10607
|
+
* Not enforcing: nothing is withheld, and no graph walk is needed. This has
|
|
10608
|
+
* to come first — `off` and `shadow` resolve available whatever the grant
|
|
10609
|
+
* says, and a cycle would otherwise return unavailable under `off` too.
|
|
10610
|
+
*/
|
|
10611
|
+
if (moduleSettings.enforcement !== 'enforce') {
|
|
10612
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10613
|
+
}
|
|
10614
|
+
// A cycle in `requires` resolves unavailable rather than recursing.
|
|
10615
|
+
if (seen.has(moduleKey)) {
|
|
10616
|
+
return {
|
|
10617
|
+
moduleKey,
|
|
10618
|
+
isAvailable: false,
|
|
10619
|
+
isGranted,
|
|
10620
|
+
reason: 'prerequisiteUnavailable',
|
|
10621
|
+
unsatisfied: (_c = (_b = moduleSettings.catalog[moduleKey]) === null || _b === void 0 ? void 0 : _b.requires) !== null && _c !== void 0 ? _c : [],
|
|
10622
|
+
};
|
|
10623
|
+
}
|
|
10624
|
+
// The module's own grant is evaluated before its prerequisites, so
|
|
10625
|
+
// `notGranted` is reported in preference when both hold.
|
|
10626
|
+
if (!isGranted) {
|
|
10627
|
+
return { moduleKey, isAvailable: false, isGranted, reason: 'notGranted' };
|
|
10628
|
+
}
|
|
10629
|
+
const requires = (_e = (_d = moduleSettings.catalog[moduleKey]) === null || _d === void 0 ? void 0 : _d.requires) !== null && _e !== void 0 ? _e : [];
|
|
10630
|
+
if (requires.length === 0)
|
|
10631
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10632
|
+
// `requires` is satisfied by any one entry, transitively.
|
|
10633
|
+
const isSatisfied = requires.some(dependency => resolveModuleAvailability(moduleSettings, dependency, new Set([...seen, moduleKey]))
|
|
10634
|
+
.isAvailable);
|
|
10635
|
+
if (isSatisfied)
|
|
10636
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10637
|
+
/*
|
|
10638
|
+
* `unsatisfied` carries the whole `requires` list rather than one entry. Any
|
|
10639
|
+
* one of them would have satisfied the requirement, so naming a single
|
|
10640
|
+
* module misdirects: telling a Community-only customer "Comment needs post"
|
|
10641
|
+
* hides that Story would also have done.
|
|
10642
|
+
*/
|
|
10643
|
+
return {
|
|
10644
|
+
moduleKey,
|
|
10645
|
+
isAvailable: false,
|
|
10646
|
+
isGranted,
|
|
10647
|
+
reason: 'prerequisiteUnavailable',
|
|
10648
|
+
unsatisfied: requires,
|
|
10649
|
+
};
|
|
10650
|
+
};
|
|
10651
|
+
|
|
10248
10652
|
var index$t = /*#__PURE__*/Object.freeze({
|
|
10249
10653
|
__proto__: null,
|
|
10250
10654
|
getActiveClient: getActiveClient,
|
|
@@ -10268,6 +10672,7 @@ var index$t = /*#__PURE__*/Object.freeze({
|
|
|
10268
10672
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
10269
10673
|
getProductCatalogueSetting: getProductCatalogueSetting,
|
|
10270
10674
|
getForYouFeedSetting: getForYouFeedSetting,
|
|
10675
|
+
getModuleSettings: getModuleSettings,
|
|
10271
10676
|
loginAsVisitor: loginAsVisitor,
|
|
10272
10677
|
loginAsBot: loginAsBot,
|
|
10273
10678
|
getCurrentUser: getCurrentUser,
|
|
@@ -10295,7 +10700,8 @@ var index$t = /*#__PURE__*/Object.freeze({
|
|
|
10295
10700
|
startMarkerSync: startMarkerSync,
|
|
10296
10701
|
startUnreadSync: startUnreadSync,
|
|
10297
10702
|
stopUnreadSync: stopUnreadSync,
|
|
10298
|
-
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
10703
|
+
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode,
|
|
10704
|
+
resolveModuleAvailability: resolveModuleAvailability
|
|
10299
10705
|
});
|
|
10300
10706
|
|
|
10301
10707
|
/* begin_public_function
|
|
@@ -13226,7 +13632,7 @@ const getWatchSessionStorage = () => {
|
|
|
13226
13632
|
return storageInstance;
|
|
13227
13633
|
};
|
|
13228
13634
|
|
|
13229
|
-
const privateKey = "
|
|
13635
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9DvylZOTa2R15NJpK3WLcTqVIGhsn/FL5owfvFah6zSsmXZParZm5zY9NZE03ALZhOB9/cz0e3kf/EbpfeL2mW7MApyiUt5i09ycchroOpcWp73ipIxvgigtZyUGFmsQicWhUs28F0D7w4Qfk76yG3nqXeb+BAMhCaIaa/k/aAxhiZG/ygEQWQrcC8gfe+jyicMAQPDEVS9YuUMGsLjIjKuVLZzp2xirQnhc2i2zVNEIvG6soprPOBEMQugzrtX5ECgYEA3b7KAbBIbDl1e4ZSCWhHdHkiWVZHaopsR/LhqDDNhXjWjq3AesgV6k0j9EdziMn/HmmOso0bz99GTV3JZf4A9ztTLumJlkHbdVtlgOqSjrFLj12rH9KXTheyIhWSpUmm8+WB1xasFbqpvJaGo7F3pd2Fqj1XR4mp5BO7c/t7LJ0CgYEA3aouEzXQ9THRKYocdfY69EI1Il1t/d/RSqqd9BxEjxBgxkM13ZiYIn/R4WW/nCUrlmhxG44Aa2Gob4Ahfsui2xKTg/g/3Zk/rAxAEGkfOLGoenaJMD41fH4wUq3FRYwkvnaMb9Hd6f/TlBHslIRa2NN58bSBGJCyBP2b59+2+EcCgYEAixDVRXvV37GlYUOa/XVdosk5Zoe6oDGRuQm0xbNdoUBoZvDHDvme7ONWEiQha/8qtVsD+CyQ7awcPfb8kK9c0bBt+bTS6d4BkTcxkEkMgtrkBVR8Nqfu5jXsLH4VCv4G61zbMhZw8+ut+az5YX2yCN7Frj9sFlxapMRPQmzMEe0CgYEAumsAzM8ZqNv4mAK65Mnr0rhLj1cbxcKRdUYACOgtEFQpzxN/HZnTeFAe5nx3pI3uFlRHq3DFEYnT6dHMWaJQmAULYpVIwMi9L6gtyJ9fzoI6uqMtxRDMUqKdaSsTGOY/kJ6KhQ/unXi1K3XXjR+yd1+C0q+HUm1+CYxvrZYLfskCgYEArsEy+IQOiqniJ0NE2vVUF+UK/IRZaic9YKcpov5Ot7Vvzm/MnnW4N1ljVskocETBWMmPUvNSExVjPebi+rxd8fa5kY8BJScPTzMFbunZn/wjtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
|
|
13230
13636
|
/*
|
|
13231
13637
|
* The crypto algorithm used for importing key and signing string
|
|
13232
13638
|
*/
|
|
@@ -15025,18 +15431,18 @@ const buildFlagUserBody = (options) => {
|
|
|
15025
15431
|
/**
|
|
15026
15432
|
* ```js
|
|
15027
15433
|
* import { UserRepository } from '@amityco/ts-sdk'
|
|
15434
|
+
*
|
|
15435
|
+
* // Typeless report (supported).
|
|
15028
15436
|
* const flagged = await UserRepository.flagUser('userId')
|
|
15029
|
-
* const flaggedBehavior = await UserRepository.flagUser('userId', {
|
|
15030
|
-
* reportType: 'behavior',
|
|
15031
|
-
* reason: 'Harassment or bullying',
|
|
15032
|
-
* comment: 'optional free-text',
|
|
15033
|
-
* })
|
|
15034
15437
|
* ```
|
|
15035
15438
|
*
|
|
15439
|
+
* Flags a user. Two call shapes are accepted (see the overloads): id-only, which
|
|
15440
|
+
* sends no body and stays supported, and the deprecated structured options object,
|
|
15441
|
+
* whose request mapping is unchanged. New code reporting a profile field or behavior
|
|
15442
|
+
* should use `flagUserProfile` or `flagUserBehavior`.
|
|
15443
|
+
*
|
|
15036
15444
|
* @param userId The ID of the user to be flagged
|
|
15037
|
-
* @param options
|
|
15038
|
-
* body: `reportType`, `reason`, `comment`. Only non-null fields are included.
|
|
15039
|
-
* All validation is server-side; a bodyless call produces a typeless report.
|
|
15445
|
+
* @param options Deprecated report metadata; omit for a typeless report
|
|
15040
15446
|
* @returns the flagged {@link Amity.User}
|
|
15041
15447
|
*
|
|
15042
15448
|
* @category User API
|
|
@@ -15057,6 +15463,156 @@ const flagUser = async (userId, options) => {
|
|
|
15057
15463
|
};
|
|
15058
15464
|
/* end_public_function */
|
|
15059
15465
|
|
|
15466
|
+
/**
|
|
15467
|
+
* Sends a validated split user report (`flagUserProfile` / `flagUserBehavior`) to the
|
|
15468
|
+
* same endpoint as `flagUser`, then persists the returned user and fires `user.flagged`
|
|
15469
|
+
* exactly as `flagUser` does, so all three calls share return, cache and event behaviour.
|
|
15470
|
+
*
|
|
15471
|
+
* Not exported from the public API.
|
|
15472
|
+
*/
|
|
15473
|
+
const submitUserReport = async (apiName, userId, body) => {
|
|
15474
|
+
var _a;
|
|
15475
|
+
const client = getActiveClient();
|
|
15476
|
+
client.log(`user/${apiName}`, { userId, body });
|
|
15477
|
+
const { data } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(userId)}`, body);
|
|
15478
|
+
const payload = prepareUserPayload(data);
|
|
15479
|
+
if (client.cache) {
|
|
15480
|
+
ingestInCache(payload);
|
|
15481
|
+
}
|
|
15482
|
+
fireEvent('user.flagged', data);
|
|
15483
|
+
return (_a = payload.users.find(user => user.userId === userId)) !== null && _a !== void 0 ? _a : payload.users[0];
|
|
15484
|
+
};
|
|
15485
|
+
|
|
15486
|
+
/** Maximum `comment` length, in string length units, after trimming. */
|
|
15487
|
+
const USER_REPORT_COMMENT_MAX_LENGTH = 300;
|
|
15488
|
+
const PROFILE_FIELDS = Object.values(exports.UserProfileFieldEnum);
|
|
15489
|
+
const BEHAVIOR_REASONS = Object.values(exports.ContentFlagReasonEnum);
|
|
15490
|
+
const assertOptionsObject = (apiName, options, shape) => {
|
|
15491
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
15492
|
+
throw new ASCInvalidParameterError(`${apiName}: expected an options object \`${shape}\``);
|
|
15493
|
+
}
|
|
15494
|
+
return options;
|
|
15495
|
+
};
|
|
15496
|
+
/**
|
|
15497
|
+
* Normalizes an optional reporter `comment`: it must be a string when supplied (`null`
|
|
15498
|
+
* is not a valid supplied comment); it is trimmed; a blank result is omitted (the
|
|
15499
|
+
* backend rejects `""`); a result longer than 300 characters is rejected before any
|
|
15500
|
+
* request. Otherwise the trimmed text is returned unchanged.
|
|
15501
|
+
*
|
|
15502
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` for a non-string or over-length comment
|
|
15503
|
+
*/
|
|
15504
|
+
const normalizeUserReportComment = (apiName, comment) => {
|
|
15505
|
+
if (comment === undefined)
|
|
15506
|
+
return undefined;
|
|
15507
|
+
if (typeof comment !== 'string') {
|
|
15508
|
+
throw new ASCInvalidParameterError(`${apiName}: \`comment\` must be a string when supplied`);
|
|
15509
|
+
}
|
|
15510
|
+
const trimmed = comment.trim();
|
|
15511
|
+
if (trimmed.length === 0)
|
|
15512
|
+
return undefined;
|
|
15513
|
+
if (trimmed.length > USER_REPORT_COMMENT_MAX_LENGTH) {
|
|
15514
|
+
throw new ASCInvalidParameterError(`${apiName}: \`comment\` must be at most ${USER_REPORT_COMMENT_MAX_LENGTH} characters after trimming`);
|
|
15515
|
+
}
|
|
15516
|
+
return trimmed;
|
|
15517
|
+
};
|
|
15518
|
+
const withComment = (body, comment) => comment === undefined ? body : Object.assign(Object.assign({}, body), { comment });
|
|
15519
|
+
/**
|
|
15520
|
+
* Validates `flagUserProfile` options and builds its request body. Untyped callers can
|
|
15521
|
+
* pass anything at runtime, so nothing is trusted from the declared type. Any `reason`
|
|
15522
|
+
* key is ignored and never sent.
|
|
15523
|
+
*
|
|
15524
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
15525
|
+
*/
|
|
15526
|
+
const toUserProfileReportBody = (options) => {
|
|
15527
|
+
const apiName = 'flagUserProfile';
|
|
15528
|
+
const { field, comment } = assertOptionsObject(apiName, options, '{ field, comment? }');
|
|
15529
|
+
if (typeof field !== 'string' || !PROFILE_FIELDS.includes(field)) {
|
|
15530
|
+
throw new ASCInvalidParameterError(`${apiName}: \`field\` must be a \`UserProfileFieldEnum\` value`);
|
|
15531
|
+
}
|
|
15532
|
+
return withComment({ reportType: field }, normalizeUserReportComment(apiName, comment));
|
|
15533
|
+
};
|
|
15534
|
+
/**
|
|
15535
|
+
* Validates `flagUserBehavior` options and builds its request body. `reason` must be one
|
|
15536
|
+
* of the nine `ContentFlagReasonEnum` values and is sent as that canonical label;
|
|
15537
|
+
* `reportType` is always `behavior`.
|
|
15538
|
+
*
|
|
15539
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
15540
|
+
*/
|
|
15541
|
+
const toUserBehaviorReportBody = (options) => {
|
|
15542
|
+
const apiName = 'flagUserBehavior';
|
|
15543
|
+
const { reason, comment } = assertOptionsObject(apiName, options, '{ reason, comment? }');
|
|
15544
|
+
if (typeof reason !== 'string' || !BEHAVIOR_REASONS.includes(reason)) {
|
|
15545
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reason\` must be a \`ContentFlagReasonEnum\` value`);
|
|
15546
|
+
}
|
|
15547
|
+
return withComment({ reportType: 'behavior', reason }, normalizeUserReportComment(apiName, comment));
|
|
15548
|
+
};
|
|
15549
|
+
|
|
15550
|
+
/* begin_public_function
|
|
15551
|
+
id: user.flag_profile
|
|
15552
|
+
*/
|
|
15553
|
+
/**
|
|
15554
|
+
* ```js
|
|
15555
|
+
* import { UserRepository, UserProfileFieldEnum } from '@amityco/ts-sdk'
|
|
15556
|
+
* const flagged = await UserRepository.flagUserProfile('userId', {
|
|
15557
|
+
* field: UserProfileFieldEnum.AVATAR,
|
|
15558
|
+
* comment: 'Nudity in profile photo',
|
|
15559
|
+
* })
|
|
15560
|
+
* ```
|
|
15561
|
+
*
|
|
15562
|
+
* Reports one of a user's profile fields (display name, description or avatar). The
|
|
15563
|
+
* call has no reason: profile reports never carry one, so the backend's reason rules
|
|
15564
|
+
* cannot be violated from here. A `reason` key passed at runtime is ignored and never sent.
|
|
15565
|
+
*
|
|
15566
|
+
* `comment` is trimmed; a blank comment is omitted from the request; a comment longer
|
|
15567
|
+
* than 300 characters after trimming is rejected before any request. Otherwise the
|
|
15568
|
+
* trimmed text is sent unchanged.
|
|
15569
|
+
*
|
|
15570
|
+
* Sends `POST /api/v4/me/flags/:userId` with `{ reportType: <field>, comment? }`.
|
|
15571
|
+
*
|
|
15572
|
+
* @param userId The ID of the user to be reported
|
|
15573
|
+
* @param options `field` is a `UserProfileFieldEnum` value; `comment` is optional free text
|
|
15574
|
+
* @returns the flagged {@link Amity.User}
|
|
15575
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is missing or malformed, or `comment` is over 300 characters, before any request is made
|
|
15576
|
+
*
|
|
15577
|
+
* @category User API
|
|
15578
|
+
* @async
|
|
15579
|
+
* */
|
|
15580
|
+
const flagUserProfile = async (userId, options) => submitUserReport('flagUserProfile', userId, toUserProfileReportBody(options));
|
|
15581
|
+
/* end_public_function */
|
|
15582
|
+
|
|
15583
|
+
/* begin_public_function
|
|
15584
|
+
id: user.flag_behavior
|
|
15585
|
+
*/
|
|
15586
|
+
/**
|
|
15587
|
+
* ```js
|
|
15588
|
+
* import { UserRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
15589
|
+
* const flagged = await UserRepository.flagUserBehavior('userId', {
|
|
15590
|
+
* reason: ContentFlagReasonEnum.Others,
|
|
15591
|
+
* comment: 'Impersonating our brand',
|
|
15592
|
+
* })
|
|
15593
|
+
* ```
|
|
15594
|
+
*
|
|
15595
|
+
* Reports a user's behavior. `reason` is required and is one of the nine
|
|
15596
|
+
* `ContentFlagReasonEnum` values, sent as its canonical label. Reporter text, including
|
|
15597
|
+
* the explanation for `Others`, always travels in `comment`; the reason never carries text.
|
|
15598
|
+
*
|
|
15599
|
+
* `comment` is trimmed; a blank comment is omitted from the request; a comment longer
|
|
15600
|
+
* than 300 characters after trimming is rejected before any request. Otherwise the
|
|
15601
|
+
* trimmed text is sent unchanged.
|
|
15602
|
+
*
|
|
15603
|
+
* Sends `POST /api/v4/me/flags/:userId` with `{ reportType: 'behavior', reason, comment? }`.
|
|
15604
|
+
*
|
|
15605
|
+
* @param userId The ID of the user to be reported
|
|
15606
|
+
* @param options `reason` is a `ContentFlagReasonEnum` value; `comment` is optional free text
|
|
15607
|
+
* @returns the flagged {@link Amity.User}
|
|
15608
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is missing or malformed, `reason` is missing or unknown, or `comment` is over 300 characters, before any request is made
|
|
15609
|
+
*
|
|
15610
|
+
* @category User API
|
|
15611
|
+
* @async
|
|
15612
|
+
* */
|
|
15613
|
+
const flagUserBehavior = async (userId, options) => submitUserReport('flagUserBehavior', userId, toUserBehaviorReportBody(options));
|
|
15614
|
+
/* end_public_function */
|
|
15615
|
+
|
|
15060
15616
|
/* begin_public_function
|
|
15061
15617
|
id: user.unflag
|
|
15062
15618
|
*/
|
|
@@ -16231,6 +16787,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
16231
16787
|
getUserByIds: getUserByIds,
|
|
16232
16788
|
updateUser: updateUser,
|
|
16233
16789
|
flagUser: flagUser,
|
|
16790
|
+
flagUserProfile: flagUserProfile,
|
|
16791
|
+
flagUserBehavior: flagUserBehavior,
|
|
16234
16792
|
unflagUser: unflagUser,
|
|
16235
16793
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
16236
16794
|
getAllBlockedUsers: getAllBlockedUsers,
|
|
@@ -19300,9 +19858,16 @@ const createMessageOptimistic = (bundle) => {
|
|
|
19300
19858
|
}
|
|
19301
19859
|
// as reused to update created and updated time, which should be the same
|
|
19302
19860
|
const createdTime = new Date().toISOString();
|
|
19303
|
-
const message = Object.assign({
|
|
19861
|
+
const message = Object.assign({
|
|
19862
|
+
// The optimistic message must name its channel so the session-wide channel
|
|
19863
|
+
// activity handler can move lastActivity / lastMessageAt at send time.
|
|
19864
|
+
channelId: subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.channelId, creatorId: client.userId, creatorPrivateId: getActiveUser()._id, channelSegment: ((_b = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime, syncState: "syncing" /* Amity.SyncState.Syncing */, isDeleted: false }, bundleWithMessageId);
|
|
19304
19865
|
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
19305
19866
|
pushToCache(['message', 'get', message.messageId], message, { cachedAt });
|
|
19867
|
+
// Own-send update (ChannelActivityService row 1): move the channel at send
|
|
19868
|
+
// time, synchronously, so the confirmation on the send response always sees
|
|
19869
|
+
// this value rather than racing the scheduled local event below.
|
|
19870
|
+
updateChannelActivityTimestamps(message.channelId, message.createdAt);
|
|
19306
19871
|
fireEvent('local.message.created', { messages: [message] });
|
|
19307
19872
|
return message;
|
|
19308
19873
|
};
|
|
@@ -19342,6 +19907,9 @@ const createMessage = async (bundle) => {
|
|
|
19342
19907
|
if (client.cache) {
|
|
19343
19908
|
ingestInCache(data, { cachedAt });
|
|
19344
19909
|
}
|
|
19910
|
+
// The own-send update wrote the device-clock createdAt; replace it with the
|
|
19911
|
+
// server's now that the message is confirmed (ChannelActivityService REQ-009).
|
|
19912
|
+
confirmOwnMessage(optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.channelId, optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.createdAt, messages[0].createdAt);
|
|
19345
19913
|
fireEvent('local.message.created', {
|
|
19346
19914
|
messages: [Object.assign(Object.assign({}, messages[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
|
|
19347
19915
|
});
|
|
@@ -19935,23 +20503,85 @@ getDeliveredUsers.locally = (query) => {
|
|
|
19935
20503
|
return { data: users, cachedAt, prevPage, nextPage };
|
|
19936
20504
|
};
|
|
19937
20505
|
|
|
19938
|
-
|
|
19939
|
-
id: message.flag
|
|
19940
|
-
*/
|
|
20506
|
+
const CONTENT_FLAG_REASONS = Object.values(exports.ContentFlagReasonEnum);
|
|
19941
20507
|
/**
|
|
19942
|
-
*
|
|
19943
|
-
*
|
|
19944
|
-
*
|
|
19945
|
-
|
|
20508
|
+
* True when a public `flagX(id, input)` argument is the legacy shape (a reason string
|
|
20509
|
+
* or nothing). Anything else is routed to the `Amity.ContentFlagOptions` path, whose
|
|
20510
|
+
* validation rejects malformed values before any request is made.
|
|
20511
|
+
*/
|
|
20512
|
+
const isLegacyContentFlagReason = (input) => input === undefined || typeof input === 'string';
|
|
20513
|
+
/**
|
|
20514
|
+
* Validates an `Amity.ContentFlagOptions` argument. Untyped (plain JS) callers can pass
|
|
20515
|
+
* anything at runtime, so the checks do not trust the declared type: the value must be a
|
|
20516
|
+
* plain object, `reason` must be one of the nine `ContentFlagReasonEnum` values and
|
|
20517
|
+
* `detail`, when supplied, must be a string (`null` is not a valid supplied detail).
|
|
19946
20518
|
*
|
|
19947
|
-
* @param
|
|
19948
|
-
* @
|
|
19949
|
-
|
|
20519
|
+
* @param apiName used in the error message, e.g. `flagPost`
|
|
20520
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
20521
|
+
*/
|
|
20522
|
+
const validateContentFlagOptions = (apiName, options) => {
|
|
20523
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
20524
|
+
throw new ASCInvalidParameterError(`${apiName}: expected an options object \`{ reason, detail? }\``);
|
|
20525
|
+
}
|
|
20526
|
+
const { reason, detail } = options;
|
|
20527
|
+
if (typeof reason !== 'string' || !CONTENT_FLAG_REASONS.includes(reason)) {
|
|
20528
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reason\` must be a \`ContentFlagReasonEnum\` value`);
|
|
20529
|
+
}
|
|
20530
|
+
if (detail !== undefined && typeof detail !== 'string') {
|
|
20531
|
+
throw new ASCInvalidParameterError(`${apiName}: \`detail\` must be a string when supplied`);
|
|
20532
|
+
}
|
|
20533
|
+
return { reason: reason, detail };
|
|
20534
|
+
};
|
|
20535
|
+
/**
|
|
20536
|
+
* Builds the request body for validated options. `detail` is forwarded unchanged (empty
|
|
20537
|
+
* and whitespace-only strings included) and omitted from the body when `undefined`; the
|
|
20538
|
+
* backend enforces the 300-character limit.
|
|
20539
|
+
*/
|
|
20540
|
+
const toContentFlagBody = ({ reason, detail }) => detail === undefined ? { reason } : { reason, detail };
|
|
20541
|
+
|
|
20542
|
+
/**
|
|
20543
|
+
* New `flagMessage(messageId, { reason, detail? })` implementation. Any category,
|
|
20544
|
+
* including `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
20545
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
20546
|
+
* the backend enforces the 300-character limit.
|
|
19950
20547
|
*
|
|
19951
|
-
*
|
|
19952
|
-
*
|
|
19953
|
-
*
|
|
19954
|
-
|
|
20548
|
+
* Not exported from the public API. It is reached through the
|
|
20549
|
+
* `MessageRepository.flagMessage(messageId, options)` overload; see `api/flagMessage.ts`.
|
|
20550
|
+
*
|
|
20551
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
20552
|
+
*/
|
|
20553
|
+
const flagMessageWithOptions = async (messageId, options) => {
|
|
20554
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
20555
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
20556
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagMessage', options));
|
|
20557
|
+
const client = getActiveClient();
|
|
20558
|
+
client.log('message/flag', messageId);
|
|
20559
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`, body);
|
|
20560
|
+
if (client.cache) {
|
|
20561
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
20562
|
+
ingestInCache(messagePayload);
|
|
20563
|
+
}
|
|
20564
|
+
fireEvent('message.flagged', payload);
|
|
20565
|
+
return !!payload;
|
|
20566
|
+
};
|
|
20567
|
+
|
|
20568
|
+
/**
|
|
20569
|
+
* Legacy `flagMessage(messageId, reason?)` implementation, kept verbatim so existing
|
|
20570
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
20571
|
+
*
|
|
20572
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
20573
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
20574
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
20575
|
+
* (for `undefined` the message body carries `detail: undefined`, which JSON serialization omits)
|
|
20576
|
+
*
|
|
20577
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
20578
|
+
* `MessageRepository.flagMessage(messageId, reason)` overload; see `api/flagMessage.ts`.
|
|
20579
|
+
*
|
|
20580
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
20581
|
+
* `flagMessage`, which carries the deprecation tag. New code should use `flagMessageWithOptions`
|
|
20582
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
20583
|
+
*/
|
|
20584
|
+
const flagMessageWithReasonString = async (messageId, reason) => {
|
|
19955
20585
|
const client = getActiveClient();
|
|
19956
20586
|
client.log('message/flag', messageId);
|
|
19957
20587
|
const isPredefinedReason = reason &&
|
|
@@ -19968,6 +20598,42 @@ const flagMessage = async (messageId, reason) => {
|
|
|
19968
20598
|
fireEvent('message.flagged', payload);
|
|
19969
20599
|
return !!payload;
|
|
19970
20600
|
};
|
|
20601
|
+
|
|
20602
|
+
/* begin_public_function
|
|
20603
|
+
id: message.flag
|
|
20604
|
+
*/
|
|
20605
|
+
/**
|
|
20606
|
+
* ```js
|
|
20607
|
+
* import { MessageRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
20608
|
+
*
|
|
20609
|
+
* // No reason.
|
|
20610
|
+
* await MessageRepository.flagMessage(messageId)
|
|
20611
|
+
*
|
|
20612
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
20613
|
+
* await MessageRepository.flagMessage(messageId, {
|
|
20614
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
20615
|
+
* detail: 'Repeated promotional links',
|
|
20616
|
+
* })
|
|
20617
|
+
* ```
|
|
20618
|
+
*
|
|
20619
|
+
* Reports a message to moderation. Three call shapes are accepted (see the overloads):
|
|
20620
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
20621
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
20622
|
+
* so the legacy path is untouched by the new contract:
|
|
20623
|
+
*
|
|
20624
|
+
* - `undefined` or a string → `flagMessageWithReasonString` (unchanged legacy mapping)
|
|
20625
|
+
* - anything else → `flagMessageWithOptions` (validated `{ reason, detail? }`)
|
|
20626
|
+
*
|
|
20627
|
+
* @param messageId The ID of the message to flag
|
|
20628
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
20629
|
+
* @returns `true` when the report was created
|
|
20630
|
+
*
|
|
20631
|
+
* @category Message API
|
|
20632
|
+
* @async
|
|
20633
|
+
* */
|
|
20634
|
+
const flagMessage = (messageId, input) => isLegacyContentFlagReason(input)
|
|
20635
|
+
? flagMessageWithReasonString(messageId, input)
|
|
20636
|
+
: flagMessageWithOptions(messageId, input);
|
|
19971
20637
|
/* end_public_function */
|
|
19972
20638
|
|
|
19973
20639
|
/* begin_public_function
|
|
@@ -21687,6 +22353,9 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21687
22353
|
case 'lastCreated':
|
|
21688
22354
|
channels = channels.sort(sortByLastCreated);
|
|
21689
22355
|
break;
|
|
22356
|
+
case 'lastMessage':
|
|
22357
|
+
channels = channels.sort(sortByLastMessage);
|
|
22358
|
+
break;
|
|
21690
22359
|
case 'displayName':
|
|
21691
22360
|
/*
|
|
21692
22361
|
* The server returns channels with empty | null displayName's first before
|
|
@@ -21747,9 +22416,8 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21747
22416
|
objectResolverEngine.resolve(message.channelId, "channel" /* Amity.ReferenceType.CHANNEL */);
|
|
21748
22417
|
}
|
|
21749
22418
|
else {
|
|
21750
|
-
|
|
21751
|
-
|
|
21752
|
-
});
|
|
22419
|
+
// lastActivity / lastMessageAt are moved by channelActivityOnLoginHandler
|
|
22420
|
+
// (session-wide, monotonic, one write). This listener only re-sorts.
|
|
21753
22421
|
callback(message);
|
|
21754
22422
|
}
|
|
21755
22423
|
});
|
|
@@ -21767,9 +22435,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21767
22435
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21768
22436
|
if (!cacheData)
|
|
21769
22437
|
return;
|
|
21770
|
-
|
|
21771
|
-
lastActivity: message.createdAt,
|
|
21772
|
-
});
|
|
22438
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
21773
22439
|
callback(message);
|
|
21774
22440
|
});
|
|
21775
22441
|
}, 'channelId', 'channel'),
|
|
@@ -22507,9 +23173,7 @@ class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22507
23173
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22508
23174
|
if (!cacheData)
|
|
22509
23175
|
return;
|
|
22510
|
-
|
|
22511
|
-
lastActivity: message.createdAt,
|
|
22512
|
-
});
|
|
23176
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
22513
23177
|
callback(message);
|
|
22514
23178
|
});
|
|
22515
23179
|
}, 'channelId', 'channel'),
|
|
@@ -22526,9 +23190,7 @@ class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22526
23190
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22527
23191
|
if (!cacheData)
|
|
22528
23192
|
return;
|
|
22529
|
-
|
|
22530
|
-
lastActivity: message.createdAt,
|
|
22531
|
-
});
|
|
23193
|
+
// Timestamps are moved by channelActivityOnLoginHandler; only re-sort here.
|
|
22532
23194
|
callback(message);
|
|
22533
23195
|
});
|
|
22534
23196
|
}, 'channelId', 'channel'),
|
|
@@ -27113,23 +27775,22 @@ const declineComment = async (commentId, reason) => {
|
|
|
27113
27775
|
};
|
|
27114
27776
|
/* end_public_function */
|
|
27115
27777
|
|
|
27116
|
-
/* begin_public_function
|
|
27117
|
-
id: comment.flag
|
|
27118
|
-
*/
|
|
27119
27778
|
/**
|
|
27120
|
-
*
|
|
27121
|
-
*
|
|
27122
|
-
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
27123
|
-
* ```
|
|
27779
|
+
* Legacy `flagComment(commentId, reason?)` implementation, kept verbatim so existing
|
|
27780
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
27124
27781
|
*
|
|
27125
|
-
*
|
|
27126
|
-
*
|
|
27127
|
-
*
|
|
27782
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
27783
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
27784
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
27128
27785
|
*
|
|
27129
|
-
*
|
|
27130
|
-
*
|
|
27131
|
-
*
|
|
27132
|
-
|
|
27786
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
27787
|
+
* `CommentRepository.flagComment(commentId, reason)` overload; see `api/flagComment.ts`.
|
|
27788
|
+
*
|
|
27789
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
27790
|
+
* `flagComment`, which carries the deprecation tag. New code should use `flagCommentWithOptions`
|
|
27791
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
27792
|
+
*/
|
|
27793
|
+
const flagCommentWithReasonString = async (commentId, reason) => {
|
|
27133
27794
|
const client = getActiveClient();
|
|
27134
27795
|
client.log('comment/flagComment', commentId);
|
|
27135
27796
|
const isPredefinedReason = reason &&
|
|
@@ -27145,6 +27806,67 @@ const flagComment = async (commentId, reason) => {
|
|
|
27145
27806
|
fireEvent('comment.flagged', payload);
|
|
27146
27807
|
return !!payload;
|
|
27147
27808
|
};
|
|
27809
|
+
|
|
27810
|
+
/**
|
|
27811
|
+
* New `flagComment(commentId, { reason, detail? })` implementation. Any category,
|
|
27812
|
+
* including `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
27813
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
27814
|
+
* the backend enforces the 300-character limit.
|
|
27815
|
+
*
|
|
27816
|
+
* Not exported from the public API. It is reached through the
|
|
27817
|
+
* `CommentRepository.flagComment(commentId, options)` overload; see `api/flagComment.ts`.
|
|
27818
|
+
*
|
|
27819
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
27820
|
+
*/
|
|
27821
|
+
const flagCommentWithOptions = async (commentId, options) => {
|
|
27822
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
27823
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
27824
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagComment', options));
|
|
27825
|
+
const client = getActiveClient();
|
|
27826
|
+
client.log('comment/flagComment', commentId);
|
|
27827
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
27828
|
+
if (client.cache) {
|
|
27829
|
+
ingestInCache(payload);
|
|
27830
|
+
}
|
|
27831
|
+
fireEvent('comment.flagged', payload);
|
|
27832
|
+
return !!payload;
|
|
27833
|
+
};
|
|
27834
|
+
|
|
27835
|
+
/* begin_public_function
|
|
27836
|
+
id: comment.flag
|
|
27837
|
+
*/
|
|
27838
|
+
/**
|
|
27839
|
+
* ```js
|
|
27840
|
+
* import { CommentRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
27841
|
+
*
|
|
27842
|
+
* // No reason: sent as Others with an empty detail.
|
|
27843
|
+
* await CommentRepository.flagComment(commentId)
|
|
27844
|
+
*
|
|
27845
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
27846
|
+
* await CommentRepository.flagComment(commentId, {
|
|
27847
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
27848
|
+
* detail: 'Repeated promotional links',
|
|
27849
|
+
* })
|
|
27850
|
+
* ```
|
|
27851
|
+
*
|
|
27852
|
+
* Reports a comment to moderation. Three call shapes are accepted (see the overloads):
|
|
27853
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
27854
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
27855
|
+
* so the legacy path is untouched by the new contract:
|
|
27856
|
+
*
|
|
27857
|
+
* - `undefined` or a string → `flagCommentWithReasonString` (unchanged legacy mapping)
|
|
27858
|
+
* - anything else → `flagCommentWithOptions` (validated `{ reason, detail? }`)
|
|
27859
|
+
*
|
|
27860
|
+
* @param commentId The ID of the comment to flag
|
|
27861
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
27862
|
+
* @returns `true` when the report was created
|
|
27863
|
+
*
|
|
27864
|
+
* @category Comment API
|
|
27865
|
+
* @async
|
|
27866
|
+
* */
|
|
27867
|
+
const flagComment = (commentId, input) => isLegacyContentFlagReason(input)
|
|
27868
|
+
? flagCommentWithReasonString(commentId, input)
|
|
27869
|
+
: flagCommentWithOptions(commentId, input);
|
|
27148
27870
|
/* end_public_function */
|
|
27149
27871
|
|
|
27150
27872
|
/* begin_public_function
|
|
@@ -29498,23 +30220,47 @@ const declinePost = async (postId) => {
|
|
|
29498
30220
|
};
|
|
29499
30221
|
/* end_public_function */
|
|
29500
30222
|
|
|
29501
|
-
/* begin_public_function
|
|
29502
|
-
id: post.flag
|
|
29503
|
-
*/
|
|
29504
30223
|
/**
|
|
29505
|
-
*
|
|
29506
|
-
*
|
|
29507
|
-
*
|
|
29508
|
-
*
|
|
30224
|
+
* New `flagPost(postId, { reason, detail? })` implementation. Any category, including
|
|
30225
|
+
* `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
30226
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
30227
|
+
* the backend enforces the 300-character limit.
|
|
29509
30228
|
*
|
|
29510
|
-
*
|
|
29511
|
-
*
|
|
29512
|
-
* @returns a boolean
|
|
30229
|
+
* Not exported from the public API. It is reached through the
|
|
30230
|
+
* `PostRepository.flagPost(postId, options)` overload; see `api/flagPost.ts`.
|
|
29513
30231
|
*
|
|
29514
|
-
* @
|
|
29515
|
-
|
|
29516
|
-
|
|
29517
|
-
|
|
30232
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
30233
|
+
*/
|
|
30234
|
+
const flagPostWithOptions = async (postId, options) => {
|
|
30235
|
+
// Validate first: an input error must surface as INVALID_PARAMETERS regardless of
|
|
30236
|
+
// whether a client is active, and validation needs nothing from the client.
|
|
30237
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagPost', options));
|
|
30238
|
+
const client = getActiveClient();
|
|
30239
|
+
client.log('post/flagPost', postId);
|
|
30240
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
30241
|
+
if (client.cache) {
|
|
30242
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
30243
|
+
}
|
|
30244
|
+
fireEvent('post.flagged', payload);
|
|
30245
|
+
return !!payload;
|
|
30246
|
+
};
|
|
30247
|
+
|
|
30248
|
+
/**
|
|
30249
|
+
* Legacy `flagPost(postId, reason?)` implementation, kept verbatim so existing
|
|
30250
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
30251
|
+
*
|
|
30252
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
30253
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
30254
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
30255
|
+
*
|
|
30256
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
30257
|
+
* `PostRepository.flagPost(postId, reason)` overload; see `api/flagPost.ts`.
|
|
30258
|
+
*
|
|
30259
|
+
* Not itself deprecated: it implements the deprecated legacy-string overload of the public
|
|
30260
|
+
* `flagPost`, which carries the deprecation tag. New code should use `flagPostWithOptions`
|
|
30261
|
+
* (the `{ reason, detail? }` contract). This path stays available throughout the current major version.
|
|
30262
|
+
*/
|
|
30263
|
+
const flagPostWithReasonString = async (postId, reason) => {
|
|
29518
30264
|
const client = getActiveClient();
|
|
29519
30265
|
client.log('post/flagPost', postId);
|
|
29520
30266
|
const isPredefinedReason = reason &&
|
|
@@ -29530,6 +30276,42 @@ const flagPost = async (postId, reason) => {
|
|
|
29530
30276
|
fireEvent('post.flagged', payload);
|
|
29531
30277
|
return !!payload;
|
|
29532
30278
|
};
|
|
30279
|
+
|
|
30280
|
+
/* begin_public_function
|
|
30281
|
+
id: post.flag
|
|
30282
|
+
*/
|
|
30283
|
+
/**
|
|
30284
|
+
* ```js
|
|
30285
|
+
* import { PostRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
30286
|
+
*
|
|
30287
|
+
* // No reason.
|
|
30288
|
+
* await PostRepository.flagPost(postId)
|
|
30289
|
+
*
|
|
30290
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
30291
|
+
* await PostRepository.flagPost(postId, {
|
|
30292
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
30293
|
+
* detail: 'Repeated promotional links',
|
|
30294
|
+
* })
|
|
30295
|
+
* ```
|
|
30296
|
+
*
|
|
30297
|
+
* Reports a post to moderation. Three call shapes are accepted (see the overloads):
|
|
30298
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
30299
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
30300
|
+
* so the legacy path is untouched by the new contract:
|
|
30301
|
+
*
|
|
30302
|
+
* - `undefined` or a string → `flagPostWithReasonString` (unchanged legacy mapping)
|
|
30303
|
+
* - anything else → `flagPostWithOptions` (validated `{ reason, detail? }`)
|
|
30304
|
+
*
|
|
30305
|
+
* @param postId The ID of the post to flag
|
|
30306
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
30307
|
+
* @returns `true` when the report was created
|
|
30308
|
+
*
|
|
30309
|
+
* @category Post API
|
|
30310
|
+
* @async
|
|
30311
|
+
* */
|
|
30312
|
+
const flagPost = (postId, input) => isLegacyContentFlagReason(input)
|
|
30313
|
+
? flagPostWithReasonString(postId, input)
|
|
30314
|
+
: flagPostWithOptions(postId, input);
|
|
29533
30315
|
/* end_public_function */
|
|
29534
30316
|
|
|
29535
30317
|
/* begin_public_function
|
|
@@ -36913,6 +37695,7 @@ class AmityAttachmentProductTags {
|
|
|
36913
37695
|
exports.API_REGIONS = API_REGIONS;
|
|
36914
37696
|
exports.AdRepository = index$6;
|
|
36915
37697
|
exports.AmityAttachmentProductTags = AmityAttachmentProductTags;
|
|
37698
|
+
exports.AmityModuleNotEntitledError = AmityModuleNotEntitledError;
|
|
36916
37699
|
exports.CategoryRepository = index$g;
|
|
36917
37700
|
exports.ChannelRepository = index$k;
|
|
36918
37701
|
exports.Client = index$t;
|
|
@@ -37021,6 +37804,7 @@ exports.pushToCache = pushToCache;
|
|
|
37021
37804
|
exports.queryCache = queryCache;
|
|
37022
37805
|
exports.queryOptions = queryOptions;
|
|
37023
37806
|
exports.queryRoles = queryRoles;
|
|
37807
|
+
exports.resolveModuleAvailability = resolveModuleAvailability;
|
|
37024
37808
|
exports.restoreCache = restoreCache;
|
|
37025
37809
|
exports.runQuery = runQuery;
|
|
37026
37810
|
exports.sortByChannelSegment = sortByChannelSegment;
|
|
@@ -37029,6 +37813,7 @@ exports.sortByFirstCreated = sortByFirstCreated;
|
|
|
37029
37813
|
exports.sortByFirstUpdated = sortByFirstUpdated;
|
|
37030
37814
|
exports.sortByLastActivity = sortByLastActivity;
|
|
37031
37815
|
exports.sortByLastCreated = sortByLastCreated;
|
|
37816
|
+
exports.sortByLastMessage = sortByLastMessage;
|
|
37032
37817
|
exports.sortByLastUpdated = sortByLastUpdated;
|
|
37033
37818
|
exports.sortByLocalSortingDate = sortByLocalSortingDate;
|
|
37034
37819
|
exports.sortByName = sortByName;
|