@devvit/public-api 0.11.12-next-2025-03-31-566c67869.0 → 0.11.12-next-2025-04-02-73ad9615e.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/apis/settings/SettingsClient.d.ts +3 -1
- package/apis/settings/SettingsClient.d.ts.map +1 -1
- package/apis/settings/SettingsClient.js +34 -0
- package/devvit/internals/csrf.d.ts.map +1 -1
- package/devvit/internals/csrf.js +0 -2
- package/meta.json +10 -5
- package/meta.min.json +16 -6
- package/package.json +7 -7
- package/public-api.iife.js +22 -3
- package/public-api.min.js +6 -6
- package/public-api.min.js.map +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FormFieldValue, type Metadata } from '@devvit/protos';
|
|
2
|
+
import type { SettingsResponse } from '@devvit/protos/types/devvit/plugin/settings/v1alpha/settings.js';
|
|
2
3
|
import type { SettingsClient as _SettingsClient, SettingsFormField, SettingsValues } from '../../types/settings.js';
|
|
3
4
|
export declare class SettingsClient implements _SettingsClient {
|
|
4
5
|
#private;
|
|
@@ -6,6 +7,7 @@ export declare class SettingsClient implements _SettingsClient {
|
|
|
6
7
|
get<T = string | number | boolean | string[] | undefined>(name: string): Promise<T | undefined>;
|
|
7
8
|
getAll<T extends object = SettingsValues>(): Promise<T>;
|
|
8
9
|
}
|
|
10
|
+
export declare function cleanAppSettings(response: SettingsResponse): void;
|
|
9
11
|
export declare function getSettingsValues(results: {
|
|
10
12
|
[key: string]: FormFieldValue;
|
|
11
13
|
}, settingsDefinitions: SettingsFormField[] | undefined): SettingsValues;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SettingsClient.d.ts","sourceRoot":"","sources":["../../../src/apis/settings/SettingsClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"SettingsClient.d.ts","sourceRoot":"","sources":["../../../src/apis/settings/SettingsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iEAAiE,CAAC;AAGxG,OAAO,KAAK,EACV,cAAc,IAAI,eAAe,EACjC,iBAAiB,EACjB,cAAc,EACf,MAAM,yBAAyB,CAAC;AAGjC,qBAAa,cAAe,YAAW,eAAe;;gBAGxC,QAAQ,EAAE,QAAQ;IAIxB,GAAG,CAAC,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS,EAC5D,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAKnB,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC;CAoB9D;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAoCjE;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,EAC1C,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,SAAS,GACnD,cAAc,CAWhB;AAED,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,iBAAiB,EAAE,GACvC,IAAI,CAeN"}
|
|
@@ -10,6 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _SettingsClient_metadata;
|
|
13
|
+
import { FormFieldType } from '@devvit/protos';
|
|
13
14
|
import { Devvit } from '../../devvit/Devvit.js';
|
|
14
15
|
import { flattenFormFieldValue } from '../ui/helpers/getFormValues.js';
|
|
15
16
|
export class SettingsClient {
|
|
@@ -30,6 +31,7 @@ export class SettingsClient {
|
|
|
30
31
|
if (!response.appSettings) {
|
|
31
32
|
throw new Error('Could not get app settings');
|
|
32
33
|
}
|
|
34
|
+
cleanAppSettings(response);
|
|
33
35
|
return {
|
|
34
36
|
...getSettingsValues(response.installationSettings.settings, Devvit.installationSettings),
|
|
35
37
|
...getSettingsValues(response.appSettings.settings, Devvit.appSettings),
|
|
@@ -37,6 +39,38 @@ export class SettingsClient {
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
_SettingsClient_metadata = new WeakMap();
|
|
42
|
+
export function cleanAppSettings(response) {
|
|
43
|
+
if (!response.appSettings) {
|
|
44
|
+
throw new Error('Could not get app settings');
|
|
45
|
+
}
|
|
46
|
+
// FIX: appSettings don't come back typed correctly for bools or numbers.
|
|
47
|
+
// Fix that. This is a workaround. We intend to make appSettings set this
|
|
48
|
+
// way entirely obsolete in the future; this is just a stopgap.
|
|
49
|
+
for (const [key, value] of Object.entries(response.appSettings.settings)) {
|
|
50
|
+
// Find the matching setting definition, because we can't trust the types in the response.
|
|
51
|
+
const settingDefinition = Devvit.appSettings?.find((s) => s.type !== 'group' && s.name === key);
|
|
52
|
+
if (!settingDefinition) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
// If the setting is a boolean or number, we need to convert it from string to the correct type.
|
|
56
|
+
if (settingDefinition.type === 'boolean' &&
|
|
57
|
+
value.fieldType === FormFieldType.STRING &&
|
|
58
|
+
value.boolValue == null &&
|
|
59
|
+
value.stringValue != null) {
|
|
60
|
+
value.fieldType = FormFieldType.BOOLEAN;
|
|
61
|
+
value.boolValue = Boolean(value.stringValue);
|
|
62
|
+
delete value.stringValue;
|
|
63
|
+
}
|
|
64
|
+
else if (settingDefinition.type === 'number' &&
|
|
65
|
+
value.fieldType === FormFieldType.STRING &&
|
|
66
|
+
value.numberValue == null &&
|
|
67
|
+
value.stringValue != null) {
|
|
68
|
+
value.fieldType = FormFieldType.NUMBER;
|
|
69
|
+
value.numberValue = Number(value.stringValue);
|
|
70
|
+
delete value.stringValue;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
40
74
|
export function getSettingsValues(results, settingsDefinitions) {
|
|
41
75
|
const settingsValues = Object.keys(results).reduce((acc, key) => {
|
|
42
76
|
acc[key] = flattenFormFieldValue(results[key]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csrf.d.ts","sourceRoot":"","sources":["../../../src/devvit/internals/csrf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGjF,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAuB7E,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,WAAW,GAAG,iBAAiB,EACxC,GAAG,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"csrf.d.ts","sourceRoot":"","sources":["../../../src/devvit/internals/csrf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGjF,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAuB7E,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,WAAW,GAAG,iBAAiB,EACxC,GAAG,EAAE,oBAAoB,iBAkF1B;AAWD,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,WAAW,GAAG,iBAAiB,EACxC,GAAG,EAAE,oBAAoB,iBAa1B"}
|
package/devvit/internals/csrf.js
CHANGED
|
@@ -83,7 +83,6 @@ export async function addCSRFTokenToContext(context, req) {
|
|
|
83
83
|
*/
|
|
84
84
|
await context.redis.set(`${userHeader}${subredditHeader}${targetId}${req.actionId}`, JSON.stringify(val));
|
|
85
85
|
await context.redis.expire(`${userHeader}${subredditHeader}${targetId}${req.actionId}`, 600);
|
|
86
|
-
console.debug('CSRF token added: ' + JSON.stringify(val));
|
|
87
86
|
}
|
|
88
87
|
async function isModerator(context) {
|
|
89
88
|
const userHeader = getUserHeader(context);
|
|
@@ -104,5 +103,4 @@ export async function validateCSRFToken(context, req) {
|
|
|
104
103
|
if (csrf.needsModCheck && !(await isModerator(context))) {
|
|
105
104
|
throw new Error('User is not a moderator: ' + userHeader + '; ' + subredditHeader);
|
|
106
105
|
}
|
|
107
|
-
console.debug('CSRF token validated: ' + csrfData);
|
|
108
106
|
}
|
package/meta.json
CHANGED
|
@@ -7656,8 +7656,13 @@
|
|
|
7656
7656
|
"format": "esm"
|
|
7657
7657
|
},
|
|
7658
7658
|
"src/apis/settings/SettingsClient.ts": {
|
|
7659
|
-
"bytes":
|
|
7659
|
+
"bytes": 4212,
|
|
7660
7660
|
"imports": [
|
|
7661
|
+
{
|
|
7662
|
+
"path": "../protos/dist/index.js",
|
|
7663
|
+
"kind": "import-statement",
|
|
7664
|
+
"original": "@devvit/protos"
|
|
7665
|
+
},
|
|
7661
7666
|
{
|
|
7662
7667
|
"path": "src/devvit/Devvit.ts",
|
|
7663
7668
|
"kind": "import-statement",
|
|
@@ -8070,7 +8075,7 @@
|
|
|
8070
8075
|
"format": "esm"
|
|
8071
8076
|
},
|
|
8072
8077
|
"src/devvit/internals/csrf.ts": {
|
|
8073
|
-
"bytes":
|
|
8078
|
+
"bytes": 4444,
|
|
8074
8079
|
"imports": [
|
|
8075
8080
|
{
|
|
8076
8081
|
"path": "../shared-types/dist/Header.js",
|
|
@@ -10138,7 +10143,7 @@
|
|
|
10138
10143
|
"bytesInOutput": 1819
|
|
10139
10144
|
},
|
|
10140
10145
|
"src/apis/settings/SettingsClient.ts": {
|
|
10141
|
-
"bytesInOutput":
|
|
10146
|
+
"bytesInOutput": 2681
|
|
10142
10147
|
},
|
|
10143
10148
|
"src/apis/ui/UIClient.ts": {
|
|
10144
10149
|
"bytesInOutput": 3245
|
|
@@ -10189,7 +10194,7 @@
|
|
|
10189
10194
|
"bytesInOutput": 663
|
|
10190
10195
|
},
|
|
10191
10196
|
"src/devvit/internals/csrf.ts": {
|
|
10192
|
-
"bytesInOutput":
|
|
10197
|
+
"bytesInOutput": 3386
|
|
10193
10198
|
},
|
|
10194
10199
|
"src/devvit/internals/menu-items.ts": {
|
|
10195
10200
|
"bytesInOutput": 2374
|
|
@@ -10348,7 +10353,7 @@
|
|
|
10348
10353
|
"bytesInOutput": 4013
|
|
10349
10354
|
}
|
|
10350
10355
|
},
|
|
10351
|
-
"bytes":
|
|
10356
|
+
"bytes": 12481264
|
|
10352
10357
|
}
|
|
10353
10358
|
}
|
|
10354
10359
|
}
|
package/meta.min.json
CHANGED
|
@@ -496,8 +496,13 @@
|
|
|
496
496
|
"format": "esm"
|
|
497
497
|
},
|
|
498
498
|
"src/apis/settings/SettingsClient.ts": {
|
|
499
|
-
"bytes":
|
|
499
|
+
"bytes": 4212,
|
|
500
500
|
"imports": [
|
|
501
|
+
{
|
|
502
|
+
"path": "@devvit/protos",
|
|
503
|
+
"kind": "import-statement",
|
|
504
|
+
"external": true
|
|
505
|
+
},
|
|
501
506
|
{
|
|
502
507
|
"path": "src/devvit/Devvit.ts",
|
|
503
508
|
"kind": "import-statement",
|
|
@@ -910,7 +915,7 @@
|
|
|
910
915
|
"format": "esm"
|
|
911
916
|
},
|
|
912
917
|
"src/devvit/internals/csrf.ts": {
|
|
913
|
-
"bytes":
|
|
918
|
+
"bytes": 4444,
|
|
914
919
|
"imports": [
|
|
915
920
|
{
|
|
916
921
|
"path": "../shared-types/dist/Header.js",
|
|
@@ -2526,7 +2531,7 @@
|
|
|
2526
2531
|
"imports": [],
|
|
2527
2532
|
"exports": [],
|
|
2528
2533
|
"inputs": {},
|
|
2529
|
-
"bytes":
|
|
2534
|
+
"bytes": 1064348
|
|
2530
2535
|
},
|
|
2531
2536
|
"dist/public-api.min.js": {
|
|
2532
2537
|
"imports": [
|
|
@@ -2695,6 +2700,11 @@
|
|
|
2695
2700
|
"kind": "import-statement",
|
|
2696
2701
|
"external": true
|
|
2697
2702
|
},
|
|
2703
|
+
{
|
|
2704
|
+
"path": "@devvit/protos",
|
|
2705
|
+
"kind": "import-statement",
|
|
2706
|
+
"external": true
|
|
2707
|
+
},
|
|
2698
2708
|
{
|
|
2699
2709
|
"path": "@devvit/protos",
|
|
2700
2710
|
"kind": "import-statement",
|
|
@@ -2873,7 +2883,7 @@
|
|
|
2873
2883
|
"bytesInOutput": 709
|
|
2874
2884
|
},
|
|
2875
2885
|
"src/apis/settings/SettingsClient.ts": {
|
|
2876
|
-
"bytesInOutput":
|
|
2886
|
+
"bytesInOutput": 1247
|
|
2877
2887
|
},
|
|
2878
2888
|
"src/apis/ui/UIClient.ts": {
|
|
2879
2889
|
"bytesInOutput": 1373
|
|
@@ -2921,7 +2931,7 @@
|
|
|
2921
2931
|
"bytesInOutput": 1322
|
|
2922
2932
|
},
|
|
2923
2933
|
"src/devvit/internals/csrf.ts": {
|
|
2924
|
-
"bytesInOutput":
|
|
2934
|
+
"bytesInOutput": 1706
|
|
2925
2935
|
},
|
|
2926
2936
|
"src/devvit/internals/plugins.ts": {
|
|
2927
2937
|
"bytesInOutput": 47
|
|
@@ -3077,7 +3087,7 @@
|
|
|
3077
3087
|
"bytesInOutput": 107
|
|
3078
3088
|
}
|
|
3079
3089
|
},
|
|
3080
|
-
"bytes":
|
|
3090
|
+
"bytes": 219719
|
|
3081
3091
|
}
|
|
3082
3092
|
}
|
|
3083
3093
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/public-api",
|
|
3
|
-
"version": "0.11.12-next-2025-
|
|
3
|
+
"version": "0.11.12-next-2025-04-02-73ad9615e.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
},
|
|
31
31
|
"types": "./index.d.ts",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@devvit/metrics": "0.11.12-next-2025-
|
|
34
|
-
"@devvit/protos": "0.11.12-next-2025-
|
|
35
|
-
"@devvit/shared-types": "0.11.12-next-2025-
|
|
33
|
+
"@devvit/metrics": "0.11.12-next-2025-04-02-73ad9615e.0",
|
|
34
|
+
"@devvit/protos": "0.11.12-next-2025-04-02-73ad9615e.0",
|
|
35
|
+
"@devvit/shared-types": "0.11.12-next-2025-04-02-73ad9615e.0",
|
|
36
36
|
"base64-js": "1.5.1",
|
|
37
37
|
"clone-deep": "4.0.1",
|
|
38
38
|
"moderndash": "4.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@ampproject/filesize": "4.3.0",
|
|
42
|
-
"@devvit/repo-tools": "0.11.12-next-2025-
|
|
43
|
-
"@devvit/tsconfig": "0.11.12-next-2025-
|
|
42
|
+
"@devvit/repo-tools": "0.11.12-next-2025-04-02-73ad9615e.0",
|
|
43
|
+
"@devvit/tsconfig": "0.11.12-next-2025-04-02-73ad9615e.0",
|
|
44
44
|
"@microsoft/api-extractor": "7.41.0",
|
|
45
45
|
"@reddit/faceplate-ui": "18.0.1",
|
|
46
46
|
"@types/clone-deep": "4.0.1",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"source": "./src/index.ts",
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "aaf2d046ceea92df25c9c9e8f6dfde5b6ac3cd0f"
|
|
65
65
|
}
|