@devvit/shared-types 0.11.0-next-2024-07-11-9d8f8bdd4.0 → 0.11.0-next-2024-07-11-64bff079e.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +6 -6
- package/payments/Order.d.ts +39 -0
- package/payments/Order.d.ts.map +1 -0
- package/payments/Order.js +69 -0
- package/payments/Product.d.ts +19 -0
- package/payments/Product.d.ts.map +1 -0
- package/payments/Product.js +13 -0
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-
|
3
|
+
"version": "0.11.0-next-2024-07-11-64bff079e.0",
|
4
4
|
"license": "BSD-3-Clause",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -23,12 +23,12 @@
|
|
23
23
|
},
|
24
24
|
"types": "./index.d.ts",
|
25
25
|
"dependencies": {
|
26
|
-
"@devvit/protos": "0.11.0-next-2024-07-11-
|
26
|
+
"@devvit/protos": "0.11.0-next-2024-07-11-64bff079e.0"
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
|
-
"@devvit/eslint-config": "0.11.0-next-2024-07-11-
|
30
|
-
"@devvit/repo-tools": "0.11.0-next-2024-07-11-
|
31
|
-
"@devvit/tsconfig": "0.11.0-next-2024-07-11-
|
29
|
+
"@devvit/eslint-config": "0.11.0-next-2024-07-11-64bff079e.0",
|
30
|
+
"@devvit/repo-tools": "0.11.0-next-2024-07-11-64bff079e.0",
|
31
|
+
"@devvit/tsconfig": "0.11.0-next-2024-07-11-64bff079e.0",
|
32
32
|
"@types/redis-mock": "0.17.1",
|
33
33
|
"eslint": "8.9.0",
|
34
34
|
"lit": "2.2.8",
|
@@ -41,5 +41,5 @@
|
|
41
41
|
"directory": "dist"
|
42
42
|
},
|
43
43
|
"source": "./src/index.ts",
|
44
|
-
"gitHead": "
|
44
|
+
"gitHead": "e882b96046466a1b3938b94b0bb3eff1b2e230e7"
|
45
45
|
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import type { Order as OrderProto } from '@devvit/protos/payments.js';
|
2
|
+
import { OrderStatus as OrderStatusProto } from '@devvit/protos/payments.js';
|
3
|
+
import type { Product } from './Product.js';
|
4
|
+
/**
|
5
|
+
* The status of an order.
|
6
|
+
*/
|
7
|
+
export declare const enum OrderStatus {
|
8
|
+
UNDEFINED = "UNDEFINED",
|
9
|
+
NEW = "NEW",
|
10
|
+
CREATED = "CREATED",
|
11
|
+
PAID = "PAID",
|
12
|
+
DELIVERED = "DELIVERED",
|
13
|
+
CANCELED = "CANCELED",
|
14
|
+
REVERTED = "REVERTED"
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Maps an OrderStatus enum to the corresponding protobuf enum value.
|
18
|
+
*/
|
19
|
+
export declare function mapOrderStatusToProto(status: OrderStatus): OrderStatusProto;
|
20
|
+
/**
|
21
|
+
* An order for products purchased through Devvit by a Reddit user.
|
22
|
+
*/
|
23
|
+
export type Order = {
|
24
|
+
/** Unique identifer for the order */
|
25
|
+
id: string;
|
26
|
+
/** Where the order is in its lifecycle */
|
27
|
+
status: OrderStatus;
|
28
|
+
/** When the order was created */
|
29
|
+
createdAt: Date | undefined;
|
30
|
+
/** When the order was last updated */
|
31
|
+
updatedAt: Date | undefined;
|
32
|
+
/** The products that were ordered */
|
33
|
+
products: Product[];
|
34
|
+
};
|
35
|
+
/**
|
36
|
+
* Converts an Order protobuf message to an Order object.
|
37
|
+
*/
|
38
|
+
export declare function fromProto(data: OrderProto): Order;
|
39
|
+
//# sourceMappingURL=Order.d.ts.map
|
@@ -0,0 +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"}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { OrderStatus as OrderStatusProto } from '@devvit/protos/payments.js';
|
2
|
+
import { fromProto as productFromProto } from './Product.js';
|
3
|
+
/**
|
4
|
+
* The status of an order.
|
5
|
+
*/
|
6
|
+
export var OrderStatus;
|
7
|
+
(function (OrderStatus) {
|
8
|
+
OrderStatus["UNDEFINED"] = "UNDEFINED";
|
9
|
+
OrderStatus["NEW"] = "NEW";
|
10
|
+
OrderStatus["CREATED"] = "CREATED";
|
11
|
+
OrderStatus["PAID"] = "PAID";
|
12
|
+
OrderStatus["DELIVERED"] = "DELIVERED";
|
13
|
+
OrderStatus["CANCELED"] = "CANCELED";
|
14
|
+
OrderStatus["REVERTED"] = "REVERTED";
|
15
|
+
})(OrderStatus || (OrderStatus = {}));
|
16
|
+
/**
|
17
|
+
* Maps an OrderStatus enum to the corresponding protobuf enum value.
|
18
|
+
*/
|
19
|
+
export function mapOrderStatusToProto(status) {
|
20
|
+
switch (status) {
|
21
|
+
case OrderStatus.NEW:
|
22
|
+
return OrderStatusProto.ORDER_STATUS_NEW;
|
23
|
+
case OrderStatus.CREATED:
|
24
|
+
return OrderStatusProto.ORDER_STATUS_CREATED;
|
25
|
+
case OrderStatus.PAID:
|
26
|
+
return OrderStatusProto.ORDER_STATUS_PAID;
|
27
|
+
case OrderStatus.DELIVERED:
|
28
|
+
return OrderStatusProto.ORDER_STATUS_DELIVERED;
|
29
|
+
case OrderStatus.CANCELED:
|
30
|
+
return OrderStatusProto.ORDER_STATUS_CANCELED;
|
31
|
+
case OrderStatus.REVERTED:
|
32
|
+
return OrderStatusProto.ORDER_STATUS_REVERTED;
|
33
|
+
default:
|
34
|
+
throw new Error(`Unrecognized OrderStatus: ${status}`);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* Maps an OrderStatus protobuf enum value to the corresponding OrderStatus enum.
|
39
|
+
*/
|
40
|
+
function mapProtoToOrderStatus(status) {
|
41
|
+
switch (status) {
|
42
|
+
case OrderStatusProto.ORDER_STATUS_NEW:
|
43
|
+
return OrderStatus.NEW;
|
44
|
+
case OrderStatusProto.ORDER_STATUS_CREATED:
|
45
|
+
return OrderStatus.CREATED;
|
46
|
+
case OrderStatusProto.ORDER_STATUS_PAID:
|
47
|
+
return OrderStatus.PAID;
|
48
|
+
case OrderStatusProto.ORDER_STATUS_DELIVERED:
|
49
|
+
return OrderStatus.DELIVERED;
|
50
|
+
case OrderStatusProto.ORDER_STATUS_CANCELED:
|
51
|
+
return OrderStatus.CANCELED;
|
52
|
+
case OrderStatusProto.ORDER_STATUS_REVERTED:
|
53
|
+
return OrderStatus.REVERTED;
|
54
|
+
default:
|
55
|
+
throw new Error(`Unrecognized OrderStatus: ${status}`);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
/**
|
59
|
+
* Converts an Order protobuf message to an Order object.
|
60
|
+
*/
|
61
|
+
export function fromProto(data) {
|
62
|
+
return {
|
63
|
+
id: data.id,
|
64
|
+
status: mapProtoToOrderStatus(data.status),
|
65
|
+
createdAt: data.createdAt,
|
66
|
+
updatedAt: data.updatedAt,
|
67
|
+
products: data.products.map(productFromProto),
|
68
|
+
};
|
69
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type { Product as ProductProto } from '@devvit/protos/types/devvit/payments/v1alpha/product.js';
|
2
|
+
/**
|
3
|
+
* A unique identifier for a product.
|
4
|
+
*/
|
5
|
+
export type SKU = string;
|
6
|
+
/**
|
7
|
+
* A product that can be sold by Devvit developers
|
8
|
+
* and purchased by Reddit users.
|
9
|
+
*/
|
10
|
+
export type Product = {
|
11
|
+
sku: SKU;
|
12
|
+
price: number;
|
13
|
+
metadata: Readonly<Record<string, string>>;
|
14
|
+
};
|
15
|
+
/**
|
16
|
+
* Converts an Product protobuf message to an Product object.
|
17
|
+
*/
|
18
|
+
export declare function fromProto(data: ProductProto): Product;
|
19
|
+
//# sourceMappingURL=Product.d.ts.map
|
@@ -0,0 +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"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { assertNonNull } from '../NonNull.js';
|
2
|
+
/**
|
3
|
+
* Converts an Product protobuf message to an Product object.
|
4
|
+
*/
|
5
|
+
export function fromProto(data) {
|
6
|
+
// Validate the incoming data
|
7
|
+
assertNonNull(data.price, 'Product price is null or undefined');
|
8
|
+
return {
|
9
|
+
sku: data.sku,
|
10
|
+
price: data.price.amount, // In Reddit Gold
|
11
|
+
metadata: data.productMetadata,
|
12
|
+
};
|
13
|
+
}
|