@amityco/ts-sdk 7.27.1-7ad3a1bf.0 → 7.27.1-8317d53.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 +2 -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/client.d.ts +86 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +0 -11
- package/dist/@types/domains/content.d.ts.map +1 -1
- 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/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 +5 -67
- package/dist/commentRepository/api/flagComment.d.ts.map +1 -1
- package/dist/core/errors.d.ts +20 -0
- package/dist/core/errors.d.ts.map +1 -1
- 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 +239 -54
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +238 -55
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -796,6 +796,28 @@ class ASCConnectionError extends ASCError {
|
|
|
796
796
|
this.event = event;
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
|
+
/**
|
|
800
|
+
* Thrown when the network does not own a module the call needs. Raised from
|
|
801
|
+
* any module endpoint under `enforce` enforcement, mapped from app code
|
|
802
|
+
* `400325` — never from HTTP 403 alone, which already covers a role problem
|
|
803
|
+
* (`400300` / `400301`), a visitor (`403999`) and a bot (`403998`).
|
|
804
|
+
*
|
|
805
|
+
* `modules` carries **every** key the refusal named, as raw strings, so a
|
|
806
|
+
* caller can say which entitlement is absent without a second request.
|
|
807
|
+
*
|
|
808
|
+
* @category Errors
|
|
809
|
+
*/
|
|
810
|
+
class AmityModuleNotEntitledError extends ASCApiError {
|
|
811
|
+
/**
|
|
812
|
+
* @param message The server's message, e.g. `Module not entitled: chat, live`
|
|
813
|
+
* @param modules Every module key from the rejection's `data.modules`
|
|
814
|
+
*/
|
|
815
|
+
constructor(message, modules = []) {
|
|
816
|
+
super(message, 400325 /* Amity.ServerError.MODULE_NOT_ENTITLED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
817
|
+
this.modules = modules;
|
|
818
|
+
this.type = 'AmityModuleNotEntitledError';
|
|
819
|
+
}
|
|
820
|
+
}
|
|
799
821
|
|
|
800
822
|
let activeClient = null;
|
|
801
823
|
/**
|
|
@@ -1945,6 +1967,22 @@ function computeUrl(type, region) {
|
|
|
1945
1967
|
|
|
1946
1968
|
const uuid = () => uuid$1.v4().toString();
|
|
1947
1969
|
|
|
1970
|
+
/**
|
|
1971
|
+
* Reads the module keys a `MODULE_NOT_ENTITLED` rejection named.
|
|
1972
|
+
*
|
|
1973
|
+
* Every entry is kept, as a raw string: one call can need more than one
|
|
1974
|
+
* module, and a key this build predates is still the only part of the
|
|
1975
|
+
* payload a customer can act on.
|
|
1976
|
+
*
|
|
1977
|
+
* @category Transport
|
|
1978
|
+
* @hidden
|
|
1979
|
+
*/
|
|
1980
|
+
const extractNotEntitledModules = (data) => {
|
|
1981
|
+
const { modules } = data !== null && data !== void 0 ? data : {};
|
|
1982
|
+
if (!Array.isArray(modules))
|
|
1983
|
+
return [];
|
|
1984
|
+
return modules.filter((module) => typeof module === 'string');
|
|
1985
|
+
};
|
|
1948
1986
|
/**
|
|
1949
1987
|
* Unwraps v3 server payload (for error handling and type extraction)
|
|
1950
1988
|
*
|
|
@@ -1964,6 +2002,15 @@ const unwrapPayload = (response) => {
|
|
|
1964
2002
|
throw new ASCUnknownError(response.code);
|
|
1965
2003
|
}
|
|
1966
2004
|
else if (response.status === 'error') {
|
|
2005
|
+
/*
|
|
2006
|
+
* An entitlement refusal must not arrive as a generic failure: a customer
|
|
2007
|
+
* cannot then tell a module they have not bought from an outage. Keyed on
|
|
2008
|
+
* the app code, never on the HTTP status, so a role or membership problem
|
|
2009
|
+
* still maps to the generic error.
|
|
2010
|
+
*/
|
|
2011
|
+
if (response.code === 400325 /* Amity.ServerError.MODULE_NOT_ENTITLED */) {
|
|
2012
|
+
throw new AmityModuleNotEntitledError(response.message, extractNotEntitledModules(response.data));
|
|
2013
|
+
}
|
|
1967
2014
|
throw new ASCApiError(response.message, response.code, "error" /* Amity.ErrorLevel.ERROR */);
|
|
1968
2015
|
}
|
|
1969
2016
|
// unjust, but helps force uncast "T | undefined" to allow deconstruction without warnings
|
|
@@ -5473,6 +5520,95 @@ const getForYouFeedSetting = async () => {
|
|
|
5473
5520
|
};
|
|
5474
5521
|
/* end_public_function */
|
|
5475
5522
|
|
|
5523
|
+
const ENFORCEMENT_MODES = ['off', 'shadow', 'enforce'];
|
|
5524
|
+
/**
|
|
5525
|
+
* An unrecognised mode decodes to `off`, and so does an absent one. A mode
|
|
5526
|
+
* this build does not know must not withhold anything — defaulting to
|
|
5527
|
+
* `enforce` would let a server-side rename black out a customer's app.
|
|
5528
|
+
*
|
|
5529
|
+
* @category private
|
|
5530
|
+
*/
|
|
5531
|
+
const parseEnforcement = (mode) => {
|
|
5532
|
+
const match = ENFORCEMENT_MODES.find(value => value === mode);
|
|
5533
|
+
return match !== null && match !== void 0 ? match : 'off';
|
|
5534
|
+
};
|
|
5535
|
+
const parseGrants = (modules) => {
|
|
5536
|
+
const grants = {};
|
|
5537
|
+
Object.entries(modules !== null && modules !== void 0 ? modules : {}).forEach(([key, granted]) => {
|
|
5538
|
+
grants[key] = granted === true;
|
|
5539
|
+
});
|
|
5540
|
+
return grants;
|
|
5541
|
+
};
|
|
5542
|
+
/**
|
|
5543
|
+
* Every catalog entry survives, including one whose key this build has never
|
|
5544
|
+
* heard of, so a module added server-side is still listable.
|
|
5545
|
+
*
|
|
5546
|
+
* @category private
|
|
5547
|
+
*/
|
|
5548
|
+
const parseCatalog = (catalog) => {
|
|
5549
|
+
const parsed = {};
|
|
5550
|
+
Object.entries(catalog !== null && catalog !== void 0 ? catalog : {}).forEach(([key, definition]) => {
|
|
5551
|
+
const rawRequires = definition === null || definition === void 0 ? void 0 : definition.requires;
|
|
5552
|
+
const requires = Array.isArray(rawRequires)
|
|
5553
|
+
? rawRequires.filter((entry) => typeof entry === 'string')
|
|
5554
|
+
: [];
|
|
5555
|
+
parsed[key] = {
|
|
5556
|
+
label: typeof (definition === null || definition === void 0 ? void 0 : definition.label) === 'string' ? definition.label : key,
|
|
5557
|
+
kind: (definition === null || definition === void 0 ? void 0 : definition.kind) === 'setting' ? 'setting' : 'api',
|
|
5558
|
+
requires,
|
|
5559
|
+
};
|
|
5560
|
+
});
|
|
5561
|
+
return parsed;
|
|
5562
|
+
};
|
|
5563
|
+
/**
|
|
5564
|
+
* Decodes `GET /api/v3/network-settings/modules`. Nothing is trimmed: the
|
|
5565
|
+
* catalog is the dependency table callers resolve against, and a client that
|
|
5566
|
+
* cannot see it has to hardcode one.
|
|
5567
|
+
*
|
|
5568
|
+
* @category private
|
|
5569
|
+
*/
|
|
5570
|
+
const parseModuleSettings = (raw) => {
|
|
5571
|
+
var _a;
|
|
5572
|
+
return ({
|
|
5573
|
+
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),
|
|
5574
|
+
modules: parseGrants(raw === null || raw === void 0 ? void 0 : raw.modules),
|
|
5575
|
+
catalog: parseCatalog(raw === null || raw === void 0 ? void 0 : raw.catalog),
|
|
5576
|
+
});
|
|
5577
|
+
};
|
|
5578
|
+
|
|
5579
|
+
/* begin_public_function
|
|
5580
|
+
id: client.getModuleSettings
|
|
5581
|
+
*/
|
|
5582
|
+
/**
|
|
5583
|
+
* ```js
|
|
5584
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
5585
|
+
* const moduleSettings = await Client.getModuleSettings()
|
|
5586
|
+
* ```
|
|
5587
|
+
*
|
|
5588
|
+
* Fetches the network's module entitlements: which modules the network was
|
|
5589
|
+
* granted, whether core is enforcing those grants, and the catalog of all
|
|
5590
|
+
* modules with their dependency chains.
|
|
5591
|
+
*
|
|
5592
|
+
* The payload is returned whole — `catalog` is the dependency table
|
|
5593
|
+
* {@link resolveModuleAvailability} reads, and a client that cannot see it has
|
|
5594
|
+
* to hardcode one.
|
|
5595
|
+
*
|
|
5596
|
+
* The read is **advisory**. It tells a host what to offer; under `enforce` the
|
|
5597
|
+
* backend refuses a call to an unowned module regardless of what was resolved
|
|
5598
|
+
* here, and that refusal arrives as `AmityModuleNotEntitledError`.
|
|
5599
|
+
*
|
|
5600
|
+
* @returns A Promise of {@link Amity.ModuleSettings} object
|
|
5601
|
+
*
|
|
5602
|
+
* @category Client API
|
|
5603
|
+
* @async
|
|
5604
|
+
*/
|
|
5605
|
+
const getModuleSettings = async () => {
|
|
5606
|
+
const client = getActiveClient();
|
|
5607
|
+
const { data } = await client.http.get(`/api/v3/network-settings/modules`);
|
|
5608
|
+
return parseModuleSettings(data);
|
|
5609
|
+
};
|
|
5610
|
+
/* end_public_function */
|
|
5611
|
+
|
|
5476
5612
|
const checkUserPermission = (userId, permission) => {
|
|
5477
5613
|
var _a;
|
|
5478
5614
|
const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -9197,6 +9333,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9197
9333
|
getMarkerSyncConsistentMode,
|
|
9198
9334
|
getProductCatalogueSetting,
|
|
9199
9335
|
getForYouFeedSetting,
|
|
9336
|
+
getModuleSettings,
|
|
9200
9337
|
/**
|
|
9201
9338
|
* Prefix for the deviceId key in the local storage or async storage.
|
|
9202
9339
|
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
@@ -10242,6 +10379,92 @@ const getUserUnread = (callback) => {
|
|
|
10242
10379
|
};
|
|
10243
10380
|
};
|
|
10244
10381
|
|
|
10382
|
+
/**
|
|
10383
|
+
* ```js
|
|
10384
|
+
* import { Client, resolveModuleAvailability } from '@amityco/ts-sdk'
|
|
10385
|
+
*
|
|
10386
|
+
* const moduleSettings = await Client.getModuleSettings()
|
|
10387
|
+
*
|
|
10388
|
+
* if (resolveModuleAvailability(moduleSettings, 'live').isAvailable) {
|
|
10389
|
+
* // offer the Live entry point
|
|
10390
|
+
* }
|
|
10391
|
+
* ```
|
|
10392
|
+
*
|
|
10393
|
+
* Resolves whether one module is usable on this network.
|
|
10394
|
+
*
|
|
10395
|
+
* Availability is a function of all three fields of
|
|
10396
|
+
* {@link Amity.ModuleSettings} — the enforcement mode, the module's own grant,
|
|
10397
|
+
* and its prerequisite chain — combined in that order. Reading `modules`
|
|
10398
|
+
* directly contradicts the mode: staging answers `mode: 'off'` with
|
|
10399
|
+
* `modules: {}`, and every module still works.
|
|
10400
|
+
*
|
|
10401
|
+
* The dependency table comes from the payload's `catalog`, never from a
|
|
10402
|
+
* hardcoded copy, so a chain the backend changes takes effect without an SDK
|
|
10403
|
+
* release.
|
|
10404
|
+
*
|
|
10405
|
+
* The SDK does not hold the settings — the caller keeps what it fetched and
|
|
10406
|
+
* resolves against it. With no settings at all (a fetch that never succeeded)
|
|
10407
|
+
* the caller reads that as every module available: under `enforce` the backend
|
|
10408
|
+
* refuses the calls anyway, so the exposure is a screen that offers too much,
|
|
10409
|
+
* not one that withholds what a customer paid for.
|
|
10410
|
+
*
|
|
10411
|
+
* @param moduleSettings The network's module settings
|
|
10412
|
+
* @param moduleKey The module to resolve — an {@link Amity.ModuleKey}, so the
|
|
10413
|
+
* 15 keys this build knows complete and type-check while a catalog entry it
|
|
10414
|
+
* does not know still resolves.
|
|
10415
|
+
* @returns An {@link Amity.ModuleAvailability} answer
|
|
10416
|
+
*
|
|
10417
|
+
* @category Client API
|
|
10418
|
+
*/
|
|
10419
|
+
const resolveModuleAvailability = (moduleSettings, moduleKey, seen = new Set()) => {
|
|
10420
|
+
var _a, _b, _c, _d, _e;
|
|
10421
|
+
const isGranted = (_a = moduleSettings.modules[moduleKey]) !== null && _a !== void 0 ? _a : false;
|
|
10422
|
+
/*
|
|
10423
|
+
* Not enforcing: nothing is withheld, and no graph walk is needed. This has
|
|
10424
|
+
* to come first — `off` and `shadow` resolve available whatever the grant
|
|
10425
|
+
* says, and a cycle would otherwise return unavailable under `off` too.
|
|
10426
|
+
*/
|
|
10427
|
+
if (moduleSettings.enforcement !== 'enforce') {
|
|
10428
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10429
|
+
}
|
|
10430
|
+
// A cycle in `requires` resolves unavailable rather than recursing.
|
|
10431
|
+
if (seen.has(moduleKey)) {
|
|
10432
|
+
return {
|
|
10433
|
+
moduleKey,
|
|
10434
|
+
isAvailable: false,
|
|
10435
|
+
isGranted,
|
|
10436
|
+
reason: 'prerequisiteUnavailable',
|
|
10437
|
+
unsatisfied: (_c = (_b = moduleSettings.catalog[moduleKey]) === null || _b === void 0 ? void 0 : _b.requires) !== null && _c !== void 0 ? _c : [],
|
|
10438
|
+
};
|
|
10439
|
+
}
|
|
10440
|
+
// The module's own grant is evaluated before its prerequisites, so
|
|
10441
|
+
// `notGranted` is reported in preference when both hold.
|
|
10442
|
+
if (!isGranted) {
|
|
10443
|
+
return { moduleKey, isAvailable: false, isGranted, reason: 'notGranted' };
|
|
10444
|
+
}
|
|
10445
|
+
const requires = (_e = (_d = moduleSettings.catalog[moduleKey]) === null || _d === void 0 ? void 0 : _d.requires) !== null && _e !== void 0 ? _e : [];
|
|
10446
|
+
if (requires.length === 0)
|
|
10447
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10448
|
+
// `requires` is satisfied by any one entry, transitively.
|
|
10449
|
+
const isSatisfied = requires.some(dependency => resolveModuleAvailability(moduleSettings, dependency, new Set([...seen, moduleKey]))
|
|
10450
|
+
.isAvailable);
|
|
10451
|
+
if (isSatisfied)
|
|
10452
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10453
|
+
/*
|
|
10454
|
+
* `unsatisfied` carries the whole `requires` list rather than one entry. Any
|
|
10455
|
+
* one of them would have satisfied the requirement, so naming a single
|
|
10456
|
+
* module misdirects: telling a Community-only customer "Comment needs post"
|
|
10457
|
+
* hides that Story would also have done.
|
|
10458
|
+
*/
|
|
10459
|
+
return {
|
|
10460
|
+
moduleKey,
|
|
10461
|
+
isAvailable: false,
|
|
10462
|
+
isGranted,
|
|
10463
|
+
reason: 'prerequisiteUnavailable',
|
|
10464
|
+
unsatisfied: requires,
|
|
10465
|
+
};
|
|
10466
|
+
};
|
|
10467
|
+
|
|
10245
10468
|
var index$t = /*#__PURE__*/Object.freeze({
|
|
10246
10469
|
__proto__: null,
|
|
10247
10470
|
getActiveClient: getActiveClient,
|
|
@@ -10265,6 +10488,7 @@ var index$t = /*#__PURE__*/Object.freeze({
|
|
|
10265
10488
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
10266
10489
|
getProductCatalogueSetting: getProductCatalogueSetting,
|
|
10267
10490
|
getForYouFeedSetting: getForYouFeedSetting,
|
|
10491
|
+
getModuleSettings: getModuleSettings,
|
|
10268
10492
|
loginAsVisitor: loginAsVisitor,
|
|
10269
10493
|
loginAsBot: loginAsBot,
|
|
10270
10494
|
getCurrentUser: getCurrentUser,
|
|
@@ -10292,7 +10516,8 @@ var index$t = /*#__PURE__*/Object.freeze({
|
|
|
10292
10516
|
startMarkerSync: startMarkerSync,
|
|
10293
10517
|
startUnreadSync: startUnreadSync,
|
|
10294
10518
|
stopUnreadSync: stopUnreadSync,
|
|
10295
|
-
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
10519
|
+
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode,
|
|
10520
|
+
resolveModuleAvailability: resolveModuleAvailability
|
|
10296
10521
|
});
|
|
10297
10522
|
|
|
10298
10523
|
/* begin_public_function
|
|
@@ -27110,73 +27335,31 @@ const declineComment = async (commentId, reason) => {
|
|
|
27110
27335
|
};
|
|
27111
27336
|
/* end_public_function */
|
|
27112
27337
|
|
|
27113
|
-
const FLAG_REASONS = Object.values(ContentFlagReasonEnum);
|
|
27114
|
-
/**
|
|
27115
|
-
* Legacy string / undefined input. Byte-for-byte the previous mapping:
|
|
27116
|
-
* predefined value → `{ reason, detail: '' }`; any other non-empty string (including
|
|
27117
|
-
* the literal `'Others'`) → `{ reason: 'Others', detail: string }`; `undefined` or `''`
|
|
27118
|
-
* → `{ reason: 'Others', detail: '' }`.
|
|
27119
|
-
*/
|
|
27120
|
-
const toLegacyFlagCommentBody = (reason) => {
|
|
27121
|
-
if (reason && reason !== ContentFlagReasonEnum.Others && FLAG_REASONS.includes(reason)) {
|
|
27122
|
-
return { reason, detail: '' };
|
|
27123
|
-
}
|
|
27124
|
-
return { reason: ContentFlagReasonEnum.Others, detail: reason || '' };
|
|
27125
|
-
};
|
|
27126
|
-
const invalidFlagCommentOptions = (message) => new ASCError(`flagComment: ${message}`, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
27127
|
-
/**
|
|
27128
|
-
* New options input. Validated before any request is made: the argument must be a
|
|
27129
|
-
* plain object, `reason` must be one of the nine `ContentFlagReasonEnum` values and
|
|
27130
|
-
* `detail`, when supplied, must be a string. `detail` is forwarded unchanged and is
|
|
27131
|
-
* omitted from the body when `undefined`.
|
|
27132
|
-
*/
|
|
27133
|
-
const toFlagCommentBody = (options) => {
|
|
27134
|
-
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
27135
|
-
throw invalidFlagCommentOptions('expected an options object `{ reason, detail? }` or a legacy reason string');
|
|
27136
|
-
}
|
|
27137
|
-
const { reason, detail } = options;
|
|
27138
|
-
if (typeof reason !== 'string' || !FLAG_REASONS.includes(reason)) {
|
|
27139
|
-
throw invalidFlagCommentOptions('`reason` must be a `ContentFlagReasonEnum` value');
|
|
27140
|
-
}
|
|
27141
|
-
if (detail !== undefined && typeof detail !== 'string') {
|
|
27142
|
-
throw invalidFlagCommentOptions('`detail` must be a string when supplied');
|
|
27143
|
-
}
|
|
27144
|
-
return detail === undefined ? { reason } : { reason, detail };
|
|
27145
|
-
};
|
|
27146
27338
|
/* begin_public_function
|
|
27147
27339
|
id: comment.flag
|
|
27148
27340
|
*/
|
|
27149
27341
|
/**
|
|
27150
27342
|
* ```js
|
|
27151
|
-
* import { CommentRepository
|
|
27152
|
-
*
|
|
27153
|
-
* // No reason: sent as Others with an empty detail.
|
|
27154
|
-
* await CommentRepository.flagComment(commentId)
|
|
27155
|
-
*
|
|
27156
|
-
* // Category plus optional reporter context (any category, including Others).
|
|
27157
|
-
* await CommentRepository.flagComment(commentId, {
|
|
27158
|
-
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
27159
|
-
* detail: 'Repeated promotional links',
|
|
27160
|
-
* })
|
|
27343
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
27344
|
+
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
27161
27345
|
* ```
|
|
27162
27346
|
*
|
|
27163
|
-
* Reports a comment to moderation. Three call shapes are accepted (see the overloads):
|
|
27164
|
-
* id-only, an options object, and the deprecated legacy reason string.
|
|
27165
|
-
*
|
|
27166
27347
|
* @param commentId The ID of the comment to flag
|
|
27167
|
-
* @param
|
|
27168
|
-
* @returns
|
|
27348
|
+
* @param reason the reason to flag the comment
|
|
27349
|
+
* @returns the created report result
|
|
27169
27350
|
*
|
|
27170
27351
|
* @category Comment API
|
|
27171
27352
|
* @async
|
|
27172
27353
|
* */
|
|
27173
|
-
const flagComment = async (commentId,
|
|
27354
|
+
const flagComment = async (commentId, reason) => {
|
|
27174
27355
|
const client = getActiveClient();
|
|
27175
27356
|
client.log('comment/flagComment', commentId);
|
|
27176
|
-
|
|
27177
|
-
|
|
27178
|
-
|
|
27179
|
-
:
|
|
27357
|
+
const isPredefinedReason = reason &&
|
|
27358
|
+
Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
|
|
27359
|
+
const body = {
|
|
27360
|
+
reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
|
|
27361
|
+
detail: reason && !isPredefinedReason ? reason : '',
|
|
27362
|
+
};
|
|
27180
27363
|
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
27181
27364
|
if (client.cache) {
|
|
27182
27365
|
ingestInCache(payload);
|
|
@@ -36949,4 +37132,4 @@ class AmityAttachmentProductTags {
|
|
|
36949
37132
|
}
|
|
36950
37133
|
}
|
|
36951
37134
|
|
|
36952
|
-
export { API_REGIONS, index$6 as AdRepository, AmityAttachmentProductTags, AmityAutoSubscription, AmityChannelNotificationModeEnum, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AmityLiveViewerCountMode, AmitySharableContentType, AnalyticsSourceTypeEnum, index$g as CategoryRepository, index$k as ChannelRepository, index$t as Client, index$f as CommentRepository, CommunityNotificationEventNameEnum, CommunityPostSettingMaps, CommunityPostSettings, index$h as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, index as CuratedContentRepository, DefaultCommunityPostSetting, index$2 as EventRepository, FeedDataTypeEnum, index$e as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$q as FileRepository, FileType, GET_WATCHER_URLS, index$4 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$3 as LiveReactionRepository, index$8 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$o as MessageRepository, NotificationRolesFilterTypeEnum, NotificationSettingsLevelEnum, index$9 as PollRepository, PostContentType, index$c as PostRepository, PostStructureType, index$1 as ProductRepository, index$p as ReactionRepository, index$a as RoomPresenceRepository, index$d as RoomRepository, SearchUsersByEnum, index$7 as StoryRepository, index$b as StreamRepository, index$n as SubChannelRepository, SubscriptionLevels, UserNotificationModuleNameEnum, UserReportTypeEnum, index$r as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, filterCommentsByBlockUsers, filterPostsByBlockUsers, getBlockUsersId, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkId, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$5 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };
|
|
37135
|
+
export { API_REGIONS, index$6 as AdRepository, AmityAttachmentProductTags, AmityAutoSubscription, AmityChannelNotificationModeEnum, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AmityLiveViewerCountMode, AmityModuleNotEntitledError, AmitySharableContentType, AnalyticsSourceTypeEnum, index$g as CategoryRepository, index$k as ChannelRepository, index$t as Client, index$f as CommentRepository, CommunityNotificationEventNameEnum, CommunityPostSettingMaps, CommunityPostSettings, index$h as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, index as CuratedContentRepository, DefaultCommunityPostSetting, index$2 as EventRepository, FeedDataTypeEnum, index$e as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$q as FileRepository, FileType, GET_WATCHER_URLS, index$4 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$3 as LiveReactionRepository, index$8 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$o as MessageRepository, NotificationRolesFilterTypeEnum, NotificationSettingsLevelEnum, index$9 as PollRepository, PostContentType, index$c as PostRepository, PostStructureType, index$1 as ProductRepository, index$p as ReactionRepository, index$a as RoomPresenceRepository, index$d as RoomRepository, SearchUsersByEnum, index$7 as StoryRepository, index$b as StreamRepository, index$n as SubChannelRepository, SubscriptionLevels, UserNotificationModuleNameEnum, UserReportTypeEnum, index$r as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, filterCommentsByBlockUsers, filterPostsByBlockUsers, getBlockUsersId, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkId, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$5 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, resolveModuleAvailability, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };
|