opticedge-cloud-utils 1.0.42 → 1.0.44

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.
@@ -5,6 +5,12 @@ export declare enum CardApprovalStatus {
5
5
  Approved = 1,
6
6
  Approving = 999
7
7
  }
8
+ export declare enum CardGradingType {
9
+ COLLECTION = 1,
10
+ ADDED = 2,
11
+ SOLD = 3,
12
+ CARD_CENTERING = 6
13
+ }
8
14
  export type MarketReport = {
9
15
  data: string;
10
16
  title: string;
@@ -67,6 +73,6 @@ export type Card = {
67
73
  tcgLargeImageUrl: string;
68
74
  tcgSmallImageUrl: string;
69
75
  type: number;
70
- typeOfGrading: number;
76
+ typeOfGrading: CardGradingType;
71
77
  userId: string;
72
78
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CardApprovalStatus = void 0;
3
+ exports.CardGradingType = exports.CardApprovalStatus = void 0;
4
4
  var CardApprovalStatus;
5
5
  (function (CardApprovalStatus) {
6
6
  CardApprovalStatus[CardApprovalStatus["Rescan"] = -2] = "Rescan";
@@ -9,3 +9,10 @@ var CardApprovalStatus;
9
9
  CardApprovalStatus[CardApprovalStatus["Approved"] = 1] = "Approved";
10
10
  CardApprovalStatus[CardApprovalStatus["Approving"] = 999] = "Approving";
11
11
  })(CardApprovalStatus || (exports.CardApprovalStatus = CardApprovalStatus = {}));
12
+ var CardGradingType;
13
+ (function (CardGradingType) {
14
+ CardGradingType[CardGradingType["COLLECTION"] = 1] = "COLLECTION";
15
+ CardGradingType[CardGradingType["ADDED"] = 2] = "ADDED";
16
+ CardGradingType[CardGradingType["SOLD"] = 3] = "SOLD";
17
+ CardGradingType[CardGradingType["CARD_CENTERING"] = 6] = "CARD_CENTERING";
18
+ })(CardGradingType || (exports.CardGradingType = CardGradingType = {}));
@@ -121,7 +121,7 @@ export type PokemonTCGCard = {
121
121
  };
122
122
  pricecharting?: {
123
123
  id: number;
124
- price: PriceChartingPrice;
124
+ prices: PriceChartingPrice;
125
125
  updatedAt: string;
126
126
  deleted?: boolean;
127
127
  };
@@ -0,0 +1 @@
1
+ export declare function isValidWebhookSignature(secret: string, body: string, signature: string): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isValidWebhookSignature = isValidWebhookSignature;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ function isValidWebhookSignature(secret, body, signature) {
9
+ const computedSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
10
+ return computedSignature === signature;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const thirdweb_1 = require("./thirdweb");
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ describe('isValidWebhookSignature', () => {
9
+ const secret = 'test_secret';
10
+ const body = '{"message":"hello"}';
11
+ it('returns true for a valid signature', () => {
12
+ const validSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
13
+ expect((0, thirdweb_1.isValidWebhookSignature)(secret, body, validSignature)).toBe(true);
14
+ });
15
+ it('returns false for an invalid signature', () => {
16
+ const invalidSignature = 'invalidsignature123';
17
+ expect((0, thirdweb_1.isValidWebhookSignature)(secret, body, invalidSignature)).toBe(false);
18
+ });
19
+ it('returns false if body or secret is tampered', () => {
20
+ const originalSignature = crypto_1.default.createHmac('sha256', secret).update(body).digest('hex');
21
+ // wrong body
22
+ expect((0, thirdweb_1.isValidWebhookSignature)(secret, '{"message":"tampered"}', originalSignature)).toBe(false);
23
+ // wrong secret
24
+ expect((0, thirdweb_1.isValidWebhookSignature)('wrong_secret', body, originalSignature)).toBe(false);
25
+ });
26
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opticedge-cloud-utils",
3
- "version": "1.0.42",
3
+ "version": "1.0.44",
4
4
  "description": "Common utilities for cloud functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/types/card.ts CHANGED
@@ -6,6 +6,13 @@ export enum CardApprovalStatus {
6
6
  Approving = 999
7
7
  }
8
8
 
9
+ export enum CardGradingType {
10
+ COLLECTION = 1,
11
+ ADDED = 2,
12
+ SOLD = 3,
13
+ CARD_CENTERING = 6,
14
+ }
15
+
9
16
  export type MarketReport = {
10
17
  data: string
11
18
  title: string
@@ -69,6 +76,6 @@ export type Card = {
69
76
  tcgLargeImageUrl: string
70
77
  tcgSmallImageUrl: string
71
78
  type: number
72
- typeOfGrading: number
79
+ typeOfGrading: CardGradingType
73
80
  userId: string
74
81
  }
@@ -124,7 +124,7 @@ export type PokemonTCGCard = {
124
124
  }
125
125
  pricecharting?: {
126
126
  id: number
127
- price: PriceChartingPrice
127
+ prices: PriceChartingPrice
128
128
  updatedAt: string
129
129
  deleted?: boolean
130
130
  }