@devvit/shared-types 0.11.0-next-2024-07-11-178fc80d6.0 → 0.11.0-next-2024-07-11-e9f4bb9f6.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/shared-types",
3
- "version": "0.11.0-next-2024-07-11-178fc80d6.0",
3
+ "version": "0.11.0-next-2024-07-11-e9f4bb9f6.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,12 +9,13 @@
9
9
  "type": "module",
10
10
  "main": "./index.js",
11
11
  "scripts": {
12
- "build": "tsc",
12
+ "build": "tsc && yarn postbuild:copy-payments-schema",
13
13
  "clean": "rm -rf .turbo coverage dist",
14
14
  "clobber": "yarn clean && rm -rf node_modules",
15
15
  "dev": "tsc -w",
16
16
  "lint": "redlint .",
17
17
  "lint:fix": "yarn lint --fix",
18
+ "postbuild:copy-payments-schema": "cp -a -f ./src/payments/products.schema.json ./dist/payments",
18
19
  "prepublishOnly": "publish-package-json",
19
20
  "test": "yarn test:unit && yarn test:types",
20
21
  "test:types": "tsc --noEmit",
@@ -23,12 +24,13 @@
23
24
  },
24
25
  "types": "./index.d.ts",
25
26
  "dependencies": {
26
- "@devvit/protos": "0.11.0-next-2024-07-11-178fc80d6.0"
27
+ "@devvit/protos": "0.11.0-next-2024-07-11-e9f4bb9f6.0",
28
+ "jsonschema": "1.4.1"
27
29
  },
28
30
  "devDependencies": {
29
- "@devvit/eslint-config": "0.11.0-next-2024-07-11-178fc80d6.0",
30
- "@devvit/repo-tools": "0.11.0-next-2024-07-11-178fc80d6.0",
31
- "@devvit/tsconfig": "0.11.0-next-2024-07-11-178fc80d6.0",
31
+ "@devvit/eslint-config": "0.11.0-next-2024-07-11-e9f4bb9f6.0",
32
+ "@devvit/repo-tools": "0.11.0-next-2024-07-11-e9f4bb9f6.0",
33
+ "@devvit/tsconfig": "0.11.0-next-2024-07-11-e9f4bb9f6.0",
32
34
  "@types/redis-mock": "0.17.1",
33
35
  "eslint": "8.9.0",
34
36
  "lit": "2.2.8",
@@ -41,5 +43,5 @@
41
43
  "directory": "dist"
42
44
  },
43
45
  "source": "./src/index.ts",
44
- "gitHead": "0f366f5ec72eb7e0abb8cd2b26e66369c5570f57"
46
+ "gitHead": "3a5151a046edd96647784eeefd3796033cf88464"
45
47
  }
@@ -35,5 +35,5 @@ export type Order = {
35
35
  /**
36
36
  * Converts an Order protobuf message to an Order object.
37
37
  */
38
- export declare function fromProto(data: OrderProto): Order;
38
+ export declare function orderFromProto(data: OrderProto): Order;
39
39
  //# sourceMappingURL=Order.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../src/payments/Order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C;;GAEG;AACH,0BAAkB,WAAW;IAC3B,SAAS,cAAc;IACvB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,WAAW,GAAG,gBAAgB,CAiB3E;AAwBD;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,0CAA0C;IAC1C,MAAM,EAAE,WAAW,CAAC;IACpB,iCAAiC;IACjC,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IAC5B,sCAAsC;IACtC,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IAC5B,qCAAqC;IACrC,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,KAAK,CAQjD"}
1
+ {"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../src/payments/Order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C;;GAEG;AACH,0BAAkB,WAAW;IAC3B,SAAS,cAAc;IACvB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,WAAW,GAAG,gBAAgB,CAiB3E;AAwBD;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,0CAA0C;IAC1C,MAAM,EAAE,WAAW,CAAC;IACpB,iCAAiC;IACjC,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IAC5B,sCAAsC;IACtC,SAAS,EAAE,IAAI,GAAG,SAAS,CAAC;IAC5B,qCAAqC;IACrC,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,KAAK,CAQtD"}
package/payments/Order.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { OrderStatus as OrderStatusProto } from '@devvit/protos/payments.js';
2
- import { fromProto as productFromProto } from './Product.js';
2
+ import { productFromProto } from './Product.js';
3
3
  /**
4
4
  * The status of an order.
5
5
  */
@@ -58,7 +58,7 @@ function mapProtoToOrderStatus(status) {
58
58
  /**
59
59
  * Converts an Order protobuf message to an Order object.
60
60
  */
61
- export function fromProto(data) {
61
+ export function orderFromProto(data) {
62
62
  return {
63
63
  id: data.id,
64
64
  status: mapProtoToOrderStatus(data.status),
@@ -11,9 +11,12 @@ export type Product = {
11
11
  sku: SKU;
12
12
  price: number;
13
13
  metadata: Readonly<Record<string, string>>;
14
+ images?: {
15
+ icon: string;
16
+ };
14
17
  };
15
18
  /**
16
19
  * Converts an Product protobuf message to an Product object.
17
20
  */
18
- export declare function fromProto(data: ProductProto): Product;
21
+ export declare function productFromProto(data: ProductProto): Product;
19
22
  //# sourceMappingURL=Product.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Product.d.ts","sourceRoot":"","sources":["../../src/payments/Product.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,yDAAyD,CAAC;AAGvG;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAQrD"}
1
+ {"version":3,"file":"Product.d.ts","sourceRoot":"","sources":["../../src/payments/Product.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,yDAAyD,CAAC;AAGvG;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC;AAEzB;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3C,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAQ5D"}
@@ -2,7 +2,7 @@ import { assertNonNull } from '../NonNull.js';
2
2
  /**
3
3
  * Converts an Product protobuf message to an Product object.
4
4
  */
5
- export function fromProto(data) {
5
+ export function productFromProto(data) {
6
6
  // Validate the incoming data
7
7
  assertNonNull(data.price, 'Product price is null or undefined');
8
8
  return {
@@ -0,0 +1,3 @@
1
+ export * from './Order.js';
2
+ export * from './Product.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/payments/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './Order.js';
2
+ export * from './Product.js';
@@ -0,0 +1,7 @@
1
+ import type { Product } from './Product.js';
2
+ /**
3
+ * This function validates the `products.json` file of a devvit project and returns the parsed
4
+ * objects
5
+ */
6
+ export declare function validateProductsJson(json: unknown): Product[];
7
+ //# sourceMappingURL=productSchemaJSONValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productSchemaJSONValidator.d.ts","sourceRoot":"","sources":["../../src/payments/productSchemaJSONValidator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,EAAE,CAO7D"}
@@ -0,0 +1,13 @@
1
+ import jsonschema from 'jsonschema/lib/index.js';
2
+ import productSchema from './products.schema.json' assert { type: 'json' };
3
+ /**
4
+ * This function validates the `products.json` file of a devvit project and returns the parsed
5
+ * objects
6
+ */
7
+ export function validateProductsJson(json) {
8
+ const validationResult = jsonschema.validate(json, productSchema);
9
+ if (!validationResult.valid) {
10
+ throw new Error(validationResult.errors.map((e) => e.toString()).join('\n'));
11
+ }
12
+ return validationResult.instance.products ?? [];
13
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productSchemaJSONValidator.test.d.ts","sourceRoot":"","sources":["../../src/payments/productSchemaJSONValidator.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,72 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "id": "https://developers.reddit.com/payments/products.schema.json",
4
+ "title": "Devvit Payments - Product Schema",
5
+ "description": "Schema for Devvit products",
6
+ "type": "object",
7
+ "properties": {
8
+ "products": {
9
+ "type": "array",
10
+ "items": {
11
+ "type": "object",
12
+ "properties": {
13
+ "sku": {
14
+ "description": "The product sku used as a unique identifier",
15
+ "maxLength": 50,
16
+ "type": "string",
17
+ "pattern": "^[A-z0-9-_]+$"
18
+ },
19
+ "displayName": {
20
+ "description": "The product display name",
21
+ "maxLength": 50,
22
+ "type": "string",
23
+ "pattern": "^(?!\\s)[a-zA-Z0-9\\s]+(?<!\\s)$"
24
+ },
25
+ "description": {
26
+ "description": "The product description",
27
+ "type": "string",
28
+ "maxLength": 250
29
+ },
30
+ "price": {
31
+ "description": "The price of the product (unit: Reddit Gold)",
32
+ "type": "integer",
33
+ "minimum": 0
34
+ },
35
+ "images": {
36
+ "description": "The images associated with this product",
37
+ "type": "object",
38
+ "properties": {
39
+ "icon": {
40
+ "description": "The icon image URL (should be a path relative to /assets)",
41
+ "type": "string"
42
+ }
43
+ },
44
+ "patternProperties": {
45
+ "^.*$": {
46
+ "type": "string"
47
+ }
48
+ },
49
+ "additionalProperties": false,
50
+ "required": [
51
+ "icon"
52
+ ]
53
+ },
54
+ "metadata": {
55
+ "description": "Additional metadata associated with this product",
56
+ "type": "object",
57
+ "patternProperties": {
58
+ "^.*$": {
59
+ "type": "string"
60
+ }
61
+ }
62
+ }
63
+ },
64
+ "required": [
65
+ "sku",
66
+ "displayName",
67
+ "price"
68
+ ]
69
+ }
70
+ }
71
+ }
72
+ }