@devvit/shared-types 0.12.0-next-2025-04-30-5d2b49b36.0 → 0.12.0-next-2025-08-12-20-06-14-50f19bb3e.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.
Files changed (89) hide show
  1. package/AdsMetadata.d.ts +6 -0
  2. package/AdsMetadata.d.ts.map +1 -0
  3. package/AdsMetadata.js +5 -0
  4. package/Assets.d.ts +0 -2
  5. package/Assets.d.ts.map +1 -1
  6. package/Assets.js +0 -2
  7. package/CircuitBreaker.d.ts.map +1 -1
  8. package/Config.d.ts +3 -3
  9. package/Config.d.ts.map +1 -1
  10. package/ConfigImpl.d.ts +8 -8
  11. package/ConfigImpl.d.ts.map +1 -1
  12. package/ConfigImpl.js +22 -31
  13. package/Header.d.ts +1 -0
  14. package/Header.d.ts.map +1 -1
  15. package/Header.js +1 -0
  16. package/PostData.d.ts +8 -0
  17. package/PostData.d.ts.map +1 -0
  18. package/ProjectTemplateInfo.d.ts +21 -0
  19. package/ProjectTemplateInfo.d.ts.map +1 -0
  20. package/ProjectTemplateInfo.js +10 -0
  21. package/client/emit-effect.d.ts +24 -0
  22. package/client/emit-effect.d.ts.map +1 -0
  23. package/client/emit-effect.js +56 -0
  24. package/client/emit-effect.test.d.ts.map +1 -0
  25. package/client/share.d.ts +3 -0
  26. package/client/share.d.ts.map +1 -0
  27. package/client/share.js +2 -0
  28. package/constants.d.ts +9 -0
  29. package/constants.d.ts.map +1 -1
  30. package/constants.js +9 -0
  31. package/fetch-domains.d.ts +14 -0
  32. package/fetch-domains.d.ts.map +1 -0
  33. package/fetch-domains.js +42 -0
  34. package/fetch-domains.test.d.ts.map +1 -0
  35. package/isDevvitDependency.js +1 -1
  36. package/json.d.ts +12 -12
  37. package/package.json +18 -13
  38. package/richtext/index.d.ts +6 -0
  39. package/richtext/index.d.ts.map +1 -0
  40. package/richtext/index.js +1 -0
  41. package/schemas/config-file.v1.d.ts +272 -0
  42. package/schemas/config-file.v1.d.ts.map +1 -0
  43. package/schemas/config-file.v1.js +254 -0
  44. package/schemas/config-file.v1.json +683 -0
  45. package/schemas/config-file.v1.test.d.ts.map +1 -0
  46. package/schemas/constants.d.ts +4 -0
  47. package/schemas/constants.d.ts.map +1 -0
  48. package/schemas/constants.js +3 -0
  49. package/{payments/products.schema.json → schemas/products.json} +1 -1
  50. package/{payments/productSchemaJSONValidator.d.ts → schemas/productsSchemaJSONValidator.d.ts} +2 -2
  51. package/schemas/productsSchemaJSONValidator.d.ts.map +1 -0
  52. package/{payments/productSchemaJSONValidator.js → schemas/productsSchemaJSONValidator.js} +1 -1
  53. package/schemas/productsSchemaJSONValidator.test.d.ts.map +1 -0
  54. package/server/get-devvit-config.d.ts +7 -0
  55. package/server/get-devvit-config.d.ts.map +1 -0
  56. package/server/get-devvit-config.js +10 -0
  57. package/shared/devvit-worker-global.d.ts +47 -0
  58. package/shared/devvit-worker-global.d.ts.map +1 -0
  59. package/shared/devvit-worker-global.js +7 -0
  60. package/{forms/types.d.ts → shared/form.d.ts} +16 -72
  61. package/shared/form.d.ts.map +1 -0
  62. package/tid.d.ts +26 -32
  63. package/tid.d.ts.map +1 -1
  64. package/tid.js +43 -62
  65. package/web-view-scripts-constants.d.ts +14 -0
  66. package/web-view-scripts-constants.d.ts.map +1 -0
  67. package/web-view-scripts-constants.js +13 -0
  68. package/forms/assertValidFormFields.d.ts +0 -11
  69. package/forms/assertValidFormFields.d.ts.map +0 -1
  70. package/forms/assertValidFormFields.js +0 -29
  71. package/forms/assertValidFormFields.test.d.ts.map +0 -1
  72. package/forms/getFormValues.d.ts +0 -6
  73. package/forms/getFormValues.d.ts.map +0 -1
  74. package/forms/getFormValues.js +0 -31
  75. package/forms/getFormValues.test.d.ts.map +0 -1
  76. package/forms/transformForm.d.ts +0 -4
  77. package/forms/transformForm.d.ts.map +0 -1
  78. package/forms/transformForm.js +0 -141
  79. package/forms/transformForm.test.d.ts.map +0 -1
  80. package/forms/types.d.ts.map +0 -1
  81. package/index.d.ts +0 -2
  82. package/index.d.ts.map +0 -1
  83. package/payments/index.d.ts +0 -4
  84. package/payments/index.d.ts.map +0 -1
  85. package/payments/index.js +0 -3
  86. package/payments/productSchemaJSONValidator.d.ts.map +0 -1
  87. package/payments/productSchemaJSONValidator.test.d.ts.map +0 -1
  88. /package/{index.js → PostData.js} +0 -0
  89. /package/{forms/types.js → shared/form.js} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/schemas/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,eAAe,CAAC;AAEnD,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,EAAG,SAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export const UNINITIALIZED_APP_NAME = '<% name %>';
2
+ /** The default and fallback entrypoint every web view app must provide. */
3
+ export const defaultPostEntry = 'default';
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "id": "https://developers.reddit.com/payments/products.schema.json",
3
+ "$id": "https://developers.reddit.com/schema/products.json",
4
4
  "title": "Devvit Payments - Product Schema",
5
5
  "description": "Schema for Devvit products",
6
6
  "type": "object",
@@ -1,7 +1,7 @@
1
- import type { Product } from './Product.js';
1
+ import type { Product } from '../payments/Product.js';
2
2
  /**
3
3
  * This function validates the `products.json` file of a devvit project and returns the parsed
4
4
  * objects
5
5
  */
6
6
  export declare function validateProductsJSON(json: unknown): Product[];
7
- //# sourceMappingURL=productSchemaJSONValidator.d.ts.map
7
+ //# sourceMappingURL=productsSchemaJSONValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productsSchemaJSONValidator.d.ts","sourceRoot":"","sources":["../../src/schemas/productsSchemaJSONValidator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGtD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,EAAE,CAO7D"}
@@ -1,5 +1,5 @@
1
1
  import jsonschema from 'jsonschema/lib/index.js';
2
- import productSchema from './products.schema.json' with { type: 'json' };
2
+ import productSchema from './products.json' with { type: 'json' };
3
3
  /**
4
4
  * This function validates the `products.json` file of a devvit project and returns the parsed
5
5
  * objects
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productsSchemaJSONValidator.test.d.ts","sourceRoot":"","sources":["../../src/schemas/productsSchemaJSONValidator.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import type { Config } from '../Config.js';
2
+ /**
3
+ * Gets the Config object that the runtime drops on globalThis. For internal use only.
4
+ * @internal
5
+ */
6
+ export declare function getDevvitConfig(): Config;
7
+ //# sourceMappingURL=get-devvit-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-devvit-config.d.ts","sourceRoot":"","sources":["../../src/server/get-devvit-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAOxC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Gets the Config object that the runtime drops on globalThis. For internal use only.
3
+ * @internal
4
+ */
5
+ export function getDevvitConfig() {
6
+ if (!globalThis.devvit?.config) {
7
+ throw new Error('Devvit config is not available. Make sure to call getDevvitConfig() after the Devvit runtime has been initialized.');
8
+ }
9
+ return globalThis.devvit.config;
10
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Workers are expected to implement the MessagePort type where = onmessage()
3
+ * is the worker ingress / runtime egress and postMessage() is the worker
4
+ * egress / runtime ingress. See WorkerDispatcher.bindToWorkerPort() references
5
+ * for where the runtime-worker bidirectional connection is established.
6
+ */
7
+ import type { Metadata } from '@devvit/protos';
8
+ import type { AssetMap } from '../Assets.js';
9
+ import type { Config } from '../Config.js';
10
+ import type { AppConfig } from '../schemas/config-file.v1.js';
11
+ import type { FormField } from './form.js';
12
+ declare global {
13
+ var devvit: DevvitWorkerGlobal | undefined;
14
+ }
15
+ /**
16
+ * State initialized by the bootstrap (local runtime or compute) or `Devvit`
17
+ * singleton.
18
+ *
19
+ * Webbit apps have two copies of the Devvit singleton in two bundles
20
+ * (concatenated JavaScript): 1) blocks.template.ts 2) `@devvit/*` package
21
+ * dependencies on `@devvit/public-api`. Only the first is actually constructed
22
+ * by the classic bootstrap. The second is referenced indirectly by API calls
23
+ * like `BlocksHandler` but static state is never initialized.
24
+ */
25
+ export type DevvitWorkerGlobal = {
26
+ /** Available to Webbit apps only. Initialized by `Devvit` singleton. */
27
+ appConfig?: AppConfig;
28
+ /** Initialized by `Devvit` singleton. */
29
+ assets?: AssetMap;
30
+ /** See bundle.template.cjs and PlatformUtil. Initialized by bootstrap. */
31
+ compute?: {
32
+ platform: 'web' | 'go' | 'node';
33
+ };
34
+ /** Nullish until initialized by bootloader. */
35
+ config?: Config;
36
+ /**
37
+ * Provide a way for webbit apps to manage their own async local storage for
38
+ * metadata. Initialized by bootstrap.
39
+ */
40
+ metadataProvider?: () => Readonly<Metadata> | undefined;
41
+ /** Initialized by `Devvit` singleton. */
42
+ settings?: {
43
+ app?: FormField[] | undefined;
44
+ installation?: FormField[] | undefined;
45
+ };
46
+ };
47
+ //# sourceMappingURL=devvit-worker-global.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devvit-worker-global.d.ts","sourceRoot":"","sources":["../../src/shared/devvit-worker-global.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC;CAC5C;AAKD;;;;;;;;;GASG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,wEAAwE;IACxE,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,yCAAyC;IACzC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAGlB,0EAA0E;IAC1E,OAAO,CAAC,EAAE;QAAE,QAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,CAAA;KAAE,CAAC;IAE9C,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,QAAQ,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IAExD,yCAAyC;IACzC,QAAQ,CAAC,EAAE;QACT,GAAG,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;QAC9B,YAAY,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;KACxC,CAAC;CACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Workers are expected to implement the MessagePort type where = onmessage()
3
+ * is the worker ingress / runtime egress and postMessage() is the worker
4
+ * egress / runtime ingress. See WorkerDispatcher.bindToWorkerPort() references
5
+ * for where the runtime-worker bidirectional connection is established.
6
+ */
7
+ export {};
@@ -1,10 +1,19 @@
1
1
  import type { FieldConfig_Boolean, FieldConfig_Number, FieldConfig_Paragraph, FieldConfig_Selection, FieldConfig_Selection_Item, FieldConfig_String } from '@devvit/protos';
2
- import type { JSONObject } from '../json.js';
2
+ import type { JsonObject } from '../json.js';
3
3
  import type { Prettify } from '../Prettify.js';
4
- export type FormValues = JSONObject;
5
- export type FormOnSubmitEvent<T extends Partial<JSONObject>> = {
6
- /** The form values that were submitted */
7
- values: T;
4
+ export type FormValues<T extends JsonObject> = T;
5
+ export type FormRequest<T extends JsonObject> = T;
6
+ export type Form = {
7
+ /** The fields that will be displayed in the form */
8
+ fields: readonly FormField[];
9
+ /** An optional title for the form */
10
+ title?: string;
11
+ /** An optional description for the form */
12
+ description?: string;
13
+ /** An optional label for the submit button */
14
+ acceptLabel?: string;
15
+ /** An optional label for the cancel button */
16
+ cancelLabel?: string;
8
17
  };
9
18
  export type BaseField<ValueType> = {
10
19
  /**
@@ -72,75 +81,10 @@ export type FormFieldGroup = {
72
81
  /** The label of the group that will be displayed to the user */
73
82
  label: string;
74
83
  /** The fields that will be displayed in the group */
75
- fields: readonly FormField[];
84
+ fields: FormField[];
76
85
  /** An optional help text that will be displayed below the group */
77
86
  helpText?: string | undefined;
78
87
  required?: never;
79
88
  };
80
89
  export type FormField = StringField | ImageField | ParagraphField | NumberField | BooleanField | SelectField | FormFieldGroup;
81
- export type Form = {
82
- /** The fields that will be displayed in the form */
83
- fields: readonly FormField[];
84
- /** An optional title for the form */
85
- title?: string;
86
- /** An optional description for the form */
87
- description?: string;
88
- /** An optional label for the submit button */
89
- acceptLabel?: string;
90
- /** An optional label for the cancel button */
91
- cancelLabel?: string;
92
- };
93
- /**
94
- * A function that returns a form. You can use this to dynamically generate a form.
95
- * @example
96
- * ```ts
97
- * const formKey = Devvit.createForm((data) => ({
98
- * fields: data.fields,
99
- * title: data.title,
100
- * }), callback);
101
- *
102
- * ...
103
- *
104
- * ui.showForm(formKey, {
105
- * fields: [{ type: 'string', name: 'title', label: 'Title' }]
106
- * title: 'My dynamic form'
107
- * });
108
- * ```
109
- * */
110
- export type FormFunction<T extends {
111
- [key: string]: any;
112
- } = {
113
- [key: string]: any;
114
- }> = (data: T) => Form;
115
- export type FormToFormValues<T extends Form | FormFunction = Form | FormFunction> = FormFieldsToFormValues<(T extends FormFunction ? ReturnType<T> : T)['fields']>;
116
- /**
117
- * Input is a FormField[], output is a
118
- * {fieldNameA: fieldTypeA, fieldNameB: fieldTypeB}.
119
- */
120
- type FormFieldsToFormValues<T extends readonly FormField[]> = T extends readonly [
121
- infer Field extends FormField,
122
- ...infer Rest extends FormField[]
123
- ] ? FormFieldToFormValue<Field> & FormFieldsToFormValues<Rest> : {
124
- [key: string]: any;
125
- };
126
- /** Input is a FormField, output is a {fieldName: fieldType}. */
127
- type FormFieldToFormValue<T extends FormField> = T extends BooleanField ? {
128
- [_ in T['name']]: boolean;
129
- } : T extends ImageField | ParagraphField | StringField ? FormFieldToRequiredFormValue<T, string> : T extends NumberField ? FormFieldToRequiredFormValue<T, number> : T extends SelectField ? {
130
- [_ in T['name']]: string[];
131
- } : T extends FormFieldGroup ? FormFieldsToFormValues<T['fields']> : never;
132
- /**
133
- * Input is a FormField, output is a {fieldName: fieldType} or
134
- * {fieldName?: fieldType}.
135
- */
136
- type FormFieldToRequiredFormValue<T extends ImageField | ParagraphField | StringField | NumberField, V> = T extends {
137
- required: true;
138
- } | {
139
- defaultValue: boolean | number | string;
140
- } ? {
141
- [_ in T['name']]: V;
142
- } : {
143
- [_ in T['name']]?: V;
144
- };
145
- export {};
146
- //# sourceMappingURL=types.d.ts.map
90
+ //# sourceMappingURL=form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/shared/form.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,CAAC;AAGjD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,UAAU,IAAI,CAAC,CAAC;AAElD,MAAM,MAAM,IAAI,GAAG;IACjB,oDAAoD;IACpD,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IA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"t6_"
8
8
  }
9
9
  /** Commment thing ID. */
10
- export type T1ID = `${T_PREFIX.COMMENT}${string}`;
10
+ export type T1 = `${T_PREFIX.COMMENT}${string}`;
11
11
  /** Account thing ID. */
12
- export type T2ID = `${T_PREFIX.ACCOUNT}${string}`;
12
+ export type T2 = `${T_PREFIX.ACCOUNT}${string}`;
13
13
  /** Post (also called link) thing ID. */
14
- export type T3ID = `${T_PREFIX.LINK}${string}`;
14
+ export type T3 = `${T_PREFIX.LINK}${string}`;
15
15
  /** Message thing ID. */
16
- export type T4ID = `${T_PREFIX.MESSAGE}${string}`;
16
+ export type T4 = `${T_PREFIX.MESSAGE}${string}`;
17
17
  /** Subreddit thing ID. */
18
- export type T5ID = `${T_PREFIX.SUBREDDIT}${string}`;
18
+ export type T5 = `${T_PREFIX.SUBREDDIT}${string}`;
19
19
  /** Award thing ID. */
20
- export type T6ID = `${T_PREFIX.AWARD}${string}`;
21
- export type TID = T1ID | T2ID | T3ID | T4ID | T5ID | T6ID;
22
- export declare function isT1ID(id: string): id is T1ID;
23
- export declare function isT2ID(id: string): id is T2ID;
24
- export declare function isT3ID(id: string): id is T3ID;
25
- export declare function isT4ID(id: string): id is T4ID;
26
- export declare function isT5ID(id: string): id is T5ID;
27
- export declare function isT6ID(id: string): id is T6ID;
28
- export declare function assertT1ID(id: string): asserts id is T1ID;
29
- export declare function assertT2ID(id: string): asserts id is T2ID;
30
- export declare function assertT3ID(id: string): asserts id is T3ID;
31
- export declare function assertT4ID(id: string): asserts id is T4ID;
32
- export declare function assertT5ID(id: string): asserts id is T5ID;
33
- export declare function assertT6ID(id: string): asserts id is T6ID;
34
- export declare function asT1ID(id: string): T1ID;
35
- export declare function asT2ID(id: string): T2ID;
36
- export declare function asT3ID(id: string): T3ID;
37
- export declare function asT4ID(id: string): T4ID;
38
- export declare function asT5ID(id: string): T5ID;
39
- export declare function asT6ID(id: string): T6ID;
40
- export declare function asTID<T extends TID>(id: string): T;
41
- export declare function isCommentId(id: string): boolean;
42
- export declare function isAccountId(id: string): boolean;
43
- export declare function isLinkId(id: string): boolean;
44
- export declare function isMessageId(id: string): boolean;
45
- export declare function isSubredditId(id: string): boolean;
46
- export declare function isAwardId(id: string): boolean;
20
+ export type T6 = `${T_PREFIX.AWARD}${string}`;
21
+ export type Tid = T1 | T2 | T3 | T4 | T5 | T6;
22
+ export declare function isT1(id: string): id is T1;
23
+ export declare function isT2(id: string): id is T2;
24
+ export declare function isT3(id: string): id is T3;
25
+ export declare function isT4(id: string): id is T4;
26
+ export declare function isT5(id: string): id is T5;
27
+ export declare function isT6(id: string): id is T6;
28
+ export declare function assertT1(id: string): asserts id is T1;
29
+ export declare function assertT2(id: string): asserts id is T2;
30
+ export declare function assertT3(id: string): asserts id is T3;
31
+ export declare function assertT4(id: string): asserts id is T4;
32
+ export declare function assertT5(id: string): asserts id is T5;
33
+ export declare function assertT6(id: string): asserts id is T6;
34
+ export declare function T1(id: string): T1;
35
+ export declare function T2(id: string): T2;
36
+ export declare function T3(id: string): T3;
37
+ export declare function T4(id: string): T4;
38
+ export declare function T5(id: string): T5;
39
+ export declare function T6(id: string): T6;
40
+ export declare function asTid<T extends Tid>(id: string): T;
47
41
  //# sourceMappingURL=tid.d.ts.map
package/tid.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tid.d.ts","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":"AAGA,oBAAY,QAAQ;IAClB,OAAO,QAAQ;IACf,OAAO,QAAQ;IACf,IAAI,QAAQ,CAAE,eAAe;IAC7B,OAAO,QAAQ;IACf,SAAS,QAAQ;IACjB,KAAK,QAAQ;CACd;AAGD,yBAAyB;AACzB,MAAM,MAAM,IAAI,GAAG,GAAG,QAAQ,CAAC,OAAO,GAAG,MAAM,EAAE,CAAC;AAClD,wBAAwB;AACxB,MAAM,MAAM,IAAI,GAAG,GAAG,QAAQ,CAAC,OAAO,GAAG,MAAM,EAAE,CAAC;AAClD,wCAAwC;AACxC,MAAM,MAAM,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AAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,EAAE,CAErD;AACD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,EAAE,CAErD;AACD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,EAAE,CAErD;AACD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,EAAE,CAErD;AACD,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,IAAI,EAAE,CAErD;AAGD,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,CAGjC;AACD,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,CAGjC;AACD,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,CAGjC;AACD,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,CAGjC;AACD,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,CAGjC;AACD,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,CAGjC;AAED,wBAAgB,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,CAsBlD"}
package/tid.js CHANGED
@@ -10,105 +10,86 @@ export var T_PREFIX;
10
10
  T_PREFIX["AWARD"] = "t6_";
11
11
  })(T_PREFIX || (T_PREFIX = {}));
12
12
  // type guards
13
- export function isT1ID(id) {
13
+ export function isT1(id) {
14
14
  return id.startsWith(T_PREFIX.COMMENT);
15
15
  }
16
- export function isT2ID(id) {
16
+ export function isT2(id) {
17
17
  return id.startsWith(T_PREFIX.ACCOUNT);
18
18
  }
19
- export function isT3ID(id) {
19
+ export function isT3(id) {
20
20
  return id.startsWith(T_PREFIX.LINK);
21
21
  }
22
- export function isT4ID(id) {
22
+ export function isT4(id) {
23
23
  return id.startsWith(T_PREFIX.MESSAGE);
24
24
  }
25
- export function isT5ID(id) {
25
+ export function isT5(id) {
26
26
  return id.startsWith(T_PREFIX.SUBREDDIT);
27
27
  }
28
- export function isT6ID(id) {
28
+ export function isT6(id) {
29
29
  return id.startsWith(T_PREFIX.AWARD);
30
30
  }
31
31
  // assertion functions
32
- export function assertT1ID(id) {
33
- assert(isT1ID(id), `Expected comment id to start with ${T_PREFIX.COMMENT}, got ${id}}`);
32
+ export function assertT1(id) {
33
+ assert(isT1(id), `Expected comment id to start with ${T_PREFIX.COMMENT}, got ${id}}`);
34
34
  }
35
- export function assertT2ID(id) {
36
- assert(isT2ID(id), `Expected account id to start with ${T_PREFIX.ACCOUNT}, got ${id}}`);
35
+ export function assertT2(id) {
36
+ assert(isT2(id), `Expected account id to start with ${T_PREFIX.ACCOUNT}, got ${id}}`);
37
37
  }
38
- export function assertT3ID(id) {
39
- assert(isT3ID(id), `Expected link id to start with ${T_PREFIX.LINK}, got ${id}}`);
38
+ export function assertT3(id) {
39
+ assert(isT3(id), `Expected link id to start with ${T_PREFIX.LINK}, got ${id}}`);
40
40
  }
41
- export function assertT4ID(id) {
42
- assert(isT4ID(id), `Expected message id to start with ${T_PREFIX.MESSAGE}, got ${id}}`);
41
+ export function assertT4(id) {
42
+ assert(isT4(id), `Expected message id to start with ${T_PREFIX.MESSAGE}, got ${id}}`);
43
43
  }
44
- export function assertT5ID(id) {
45
- assert(isT5ID(id), `Expected subreddit id to start with ${T_PREFIX.SUBREDDIT}, got ${id}}`);
44
+ export function assertT5(id) {
45
+ assert(isT5(id), `Expected subreddit id to start with ${T_PREFIX.SUBREDDIT}, got ${id}}`);
46
46
  }
47
- export function assertT6ID(id) {
48
- assert(isT6ID(id), `Expected award id to start with ${T_PREFIX.AWARD}, got ${id}}`);
47
+ export function assertT6(id) {
48
+ assert(isT6(id), `Expected award id to start with ${T_PREFIX.AWARD}, got ${id}}`);
49
49
  }
50
50
  // factory functions
51
- export function asT1ID(id) {
52
- assertT1ID(id);
51
+ export function T1(id) {
52
+ assertT1(id);
53
53
  return id;
54
54
  }
55
- export function asT2ID(id) {
56
- assertT2ID(id);
55
+ export function T2(id) {
56
+ assertT2(id);
57
57
  return id;
58
58
  }
59
- export function asT3ID(id) {
60
- assertT3ID(id);
59
+ export function T3(id) {
60
+ assertT3(id);
61
61
  return id;
62
62
  }
63
- export function asT4ID(id) {
64
- assertT4ID(id);
63
+ export function T4(id) {
64
+ assertT4(id);
65
65
  return id;
66
66
  }
67
- export function asT5ID(id) {
68
- assertT5ID(id);
67
+ export function T5(id) {
68
+ assertT5(id);
69
69
  return id;
70
70
  }
71
- export function asT6ID(id) {
72
- assertT6ID(id);
71
+ export function T6(id) {
72
+ assertT6(id);
73
73
  return id;
74
74
  }
75
- export function asTID(id) {
76
- if (isT1ID(id)) {
77
- return asT1ID(id);
75
+ export function asTid(id) {
76
+ if (isT1(id)) {
77
+ return T1(id);
78
78
  }
79
- if (isT2ID(id)) {
80
- return asT2ID(id);
79
+ if (isT2(id)) {
80
+ return T2(id);
81
81
  }
82
- if (isT3ID(id)) {
83
- return asT3ID(id);
82
+ if (isT3(id)) {
83
+ return T3(id);
84
84
  }
85
- if (isT4ID(id)) {
86
- return asT4ID(id);
85
+ if (isT4(id)) {
86
+ return T4(id);
87
87
  }
88
- if (isT5ID(id)) {
89
- return asT5ID(id);
88
+ if (isT5(id)) {
89
+ return T5(id);
90
90
  }
91
- if (isT6ID(id)) {
92
- return asT6ID(id);
91
+ if (isT6(id)) {
92
+ return T6(id);
93
93
  }
94
94
  throw new Error(`Expected thing id to start with ${Object.values(T_PREFIX).join(', ')} got ${id}}`);
95
95
  }
96
- // convenience functions
97
- export function isCommentId(id) {
98
- return isT1ID(id);
99
- }
100
- export function isAccountId(id) {
101
- return isT2ID(id);
102
- }
103
- export function isLinkId(id) {
104
- return isT3ID(id);
105
- }
106
- export function isMessageId(id) {
107
- return isT4ID(id);
108
- }
109
- export function isSubredditId(id) {
110
- return isT5ID(id);
111
- }
112
- export function isAwardId(id) {
113
- return isT6ID(id);
114
- }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The `@devvit/client` version query parameter name the web view's document
3
+ * script tag:
4
+ *
5
+ * <script src="https://webview.devvit.net/scripts/devvit.v1.min.js?clientVersion=1.2.3"></script>
6
+ *
7
+ * The value is the version of `@devvit/client` bundled with the app.
8
+ * `@devvit/client` may have runtime dependencies on
9
+ * `@devvit/web-view-scripts` (`devvit.v1.min.js`) which is not bundled. The
10
+ * client version can be used to specialize behavior to match the static
11
+ * expectations of the `@devvit/client` version.
12
+ */
13
+ export declare const clientVersionQueryParam: string;
14
+ //# sourceMappingURL=web-view-scripts-constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-view-scripts-constants.d.ts","sourceRoot":"","sources":["../src/web-view-scripts-constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAwB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The `@devvit/client` version query parameter name the web view's document
3
+ * script tag:
4
+ *
5
+ * <script src="https://webview.devvit.net/scripts/devvit.v1.min.js?clientVersion=1.2.3"></script>
6
+ *
7
+ * The value is the version of `@devvit/client` bundled with the app.
8
+ * `@devvit/client` may have runtime dependencies on
9
+ * `@devvit/web-view-scripts` (`devvit.v1.min.js`) which is not bundled. The
10
+ * client version can be used to specialize behavior to match the static
11
+ * expectations of the `@devvit/client` version.
12
+ */
13
+ export const clientVersionQueryParam = 'clientVersion';
@@ -1,11 +0,0 @@
1
- import type { FormField } from './types.js';
2
- /**
3
- * Make sure that the form fields have unique names.
4
- *
5
- * This is a carbon copy of the assertValidFormFields function in the public-api package
6
- * We copy it here so that webbit-client does not need to depend on public-api
7
- * Any changes to this function should be reflected in the public-api version
8
- */
9
- export declare function assertValidFormFields(fields: readonly FormField[], seenNames?: Set<string>): void;
10
- export declare function assertAppSecretsOnly(fields: readonly FormField[]): void;
11
- //# sourceMappingURL=assertValidFormFields.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assertValidFormFields.d.ts","sourceRoot":"","sources":["../../src/forms/assertValidFormFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,YAAY,CAAC;AAE1D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,SAAS,GAAE,GAAG,CAAC,MAAM,CAAa,GACjC,IAAI,CAiBN;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CAMvE"}
@@ -1,29 +0,0 @@
1
- /**
2
- * Make sure that the form fields have unique names.
3
- *
4
- * This is a carbon copy of the assertValidFormFields function in the public-api package
5
- * We copy it here so that webbit-client does not need to depend on public-api
6
- * Any changes to this function should be reflected in the public-api version
7
- */
8
- export function assertValidFormFields(fields, seenNames = new Set()) {
9
- for (const field of fields) {
10
- if (field.type === 'group') {
11
- assertValidFormFields(field.fields, seenNames);
12
- continue;
13
- }
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- const fieldName = field.name;
16
- if (seenNames.has(fieldName)) {
17
- throw new Error(`Duplicate field name: ${fieldName}`);
18
- }
19
- seenNames.add(fieldName);
20
- }
21
- assertAppSecretsOnly(fields);
22
- }
23
- export function assertAppSecretsOnly(fields) {
24
- for (const field of fields) {
25
- if (field.type === 'string' && field.isSecret && field.scope !== 'app') {
26
- throw `Invalid setting: only app settings can be secrets. Add "scope: SettingScope.App" to field "${field.name}"`;
27
- }
28
- }
29
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"assertValidFormFields.test.d.ts","sourceRoot":"","sources":["../../src/forms/assertValidFormFields.test.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- import { type FormFieldValue } from '@devvit/protos';
2
- import type { FormValues } from './types.js';
3
- export declare function getFormValues(results: {
4
- [key: string]: FormFieldValue;
5
- }): FormValues;
6
- //# sourceMappingURL=getFormValues.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFormValues.d.ts","sourceRoot":"","sources":["../../src/forms/getFormValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA2B7C,wBAAgB,aAAa,CAAC,OAAO,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,GAAG,UAAU,CAMpF"}
@@ -1,31 +0,0 @@
1
- import { FormFieldType } from '@devvit/protos';
2
- function flattenFormFieldValue(value) {
3
- switch (value.fieldType) {
4
- case FormFieldType.STRING:
5
- return value.stringValue;
6
- case FormFieldType.IMAGE:
7
- // the string value is the URL
8
- return value.stringValue;
9
- case FormFieldType.PARAGRAPH:
10
- return value.stringValue;
11
- case FormFieldType.NUMBER:
12
- return value.numberValue;
13
- case FormFieldType.BOOLEAN:
14
- return value.boolValue;
15
- case FormFieldType.SELECTION:
16
- return value.selectionValue?.values ?? [];
17
- default:
18
- return undefined;
19
- }
20
- }
21
- // This is a carbon copy of the transformFormFields function in the public-api package
22
- // We copy it here so that webbit-client does not need to depend on public-api
23
- // Any changes to this function should be reflected in the public-api version
24
- export function getFormValues(results) {
25
- return Object.keys(results).reduce((acc, key) => {
26
- const val = flattenFormFieldValue(results[key]);
27
- if (val !== undefined)
28
- acc[key] = val;
29
- return acc;
30
- }, {});
31
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFormValues.test.d.ts","sourceRoot":"","sources":["../../src/forms/getFormValues.test.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- import { FormField as FormFieldProto } from '@devvit/protos';
2
- import type { FormField } from './types.js';
3
- export declare function transformFormFields(fields: readonly FormField[]): FormFieldProto[];
4
- //# sourceMappingURL=transformForm.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transformForm.d.ts","sourceRoot":"","sources":["../../src/forms/transformForm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,cAAc,EAAiB,MAAM,gBAAgB,CAAC;AAE5E,OAAO,KAAK,EAEV,SAAS,EAOV,MAAM,YAAY,CAAC;AAKpB,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,GAAG,cAAc,EAAE,CAqBlF"}