@100pay-hq/100pay.js 1.1.2 → 1.2.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/dist/index.cjs +168 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +53 -0
- package/dist/index.d.ts +33 -5
- package/dist/index.js +128 -69
- package/dist/index.js.map +1 -1
- package/package.json +15 -7
- package/dist/__tests__/index.test.d.ts +0 -2
- package/dist/__tests__/index.test.d.ts.map +0 -1
- package/dist/__tests__/index.test.js +0 -79
- package/dist/__tests__/index.test.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Pay100: () => Pay100,
|
|
34
|
+
PaymentVerificationError: () => PaymentVerificationError
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
38
|
+
var crypto = __toESM(require("crypto"), 1);
|
|
39
|
+
var BASE_URL = process.env.BASE_URL || "https://api.100pay.co";
|
|
40
|
+
var PaymentVerificationError = class extends Error {
|
|
41
|
+
constructor(message) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = "PaymentVerificationError";
|
|
44
|
+
this.status = "error";
|
|
45
|
+
this.data = {};
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var Pay100 = class {
|
|
49
|
+
constructor({ publicKey, secretKey, baseUrl = BASE_URL }) {
|
|
50
|
+
/**
|
|
51
|
+
* Verify a transaction
|
|
52
|
+
* @param transactionId Transaction ID to verify
|
|
53
|
+
* @returns Promise resolving to verification result
|
|
54
|
+
*/
|
|
55
|
+
this.verify = async (transactionId) => {
|
|
56
|
+
try {
|
|
57
|
+
const payload = { transactionId };
|
|
58
|
+
const response = await (0, import_axios.default)({
|
|
59
|
+
method: "POST",
|
|
60
|
+
url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,
|
|
61
|
+
headers: this.getHeaders(payload),
|
|
62
|
+
data: payload
|
|
63
|
+
});
|
|
64
|
+
if (!response.data) {
|
|
65
|
+
return {
|
|
66
|
+
status: "error",
|
|
67
|
+
data: {},
|
|
68
|
+
message: "Something went wrong, be sure you supplied a valid payment id."
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (typeof response.data === "string") {
|
|
72
|
+
if (response.data === "Access Denied, Invalid KEY supplied") {
|
|
73
|
+
return {
|
|
74
|
+
status: "error",
|
|
75
|
+
data: {},
|
|
76
|
+
message: "Access Denied, Invalid KEY supplied"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (response.data === "invalid payment id supplied") {
|
|
80
|
+
return {
|
|
81
|
+
status: "error",
|
|
82
|
+
data: {}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const responseData = response.data;
|
|
87
|
+
const transactionData = responseData && typeof responseData === "object" ? responseData : {};
|
|
88
|
+
return {
|
|
89
|
+
status: "success",
|
|
90
|
+
data: transactionData
|
|
91
|
+
};
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
94
|
+
const axiosError = error;
|
|
95
|
+
throw new PaymentVerificationError(
|
|
96
|
+
axiosError.message || "Something went wrong, be sure you supplied a valid payment id."
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
throw new PaymentVerificationError(
|
|
100
|
+
error instanceof Error ? error.message : "An unknown error occurred"
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
this.publicKey = publicKey;
|
|
105
|
+
this.secretKey = secretKey;
|
|
106
|
+
this.baseUrl = baseUrl;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Creates a request signature for secure server-to-server communication
|
|
110
|
+
* @param payload Request payload to sign
|
|
111
|
+
* @returns Object containing timestamp and signature
|
|
112
|
+
*/
|
|
113
|
+
createSignature(payload) {
|
|
114
|
+
const timestamp = Date.now().toString();
|
|
115
|
+
const signature = crypto.createHmac("sha256", this.secretKey).update(timestamp + JSON.stringify(payload)).digest("hex");
|
|
116
|
+
return { timestamp, signature };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Create common headers for API requests
|
|
120
|
+
* @param additionalHeaders Additional headers to include
|
|
121
|
+
* @param payload Payload to sign (if signature is needed)
|
|
122
|
+
* @returns Headers object
|
|
123
|
+
*/
|
|
124
|
+
getHeaders(payload = {}) {
|
|
125
|
+
const { timestamp, signature } = this.createSignature(payload);
|
|
126
|
+
return {
|
|
127
|
+
"api-key": this.publicKey,
|
|
128
|
+
"x-secret-key": this.secretKey,
|
|
129
|
+
"x-timestamp": timestamp,
|
|
130
|
+
"x-signature": signature,
|
|
131
|
+
"Content-Type": "application/json"
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Generic method to make authenticated API calls
|
|
136
|
+
* @param method HTTP method
|
|
137
|
+
* @param endpoint API endpoint
|
|
138
|
+
* @param data Request payload
|
|
139
|
+
* @returns Promise resolving to API response
|
|
140
|
+
*/
|
|
141
|
+
async request(method, endpoint, data = {}) {
|
|
142
|
+
try {
|
|
143
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
144
|
+
const headers = this.getHeaders(data);
|
|
145
|
+
const response = await (0, import_axios.default)({
|
|
146
|
+
method,
|
|
147
|
+
url,
|
|
148
|
+
headers,
|
|
149
|
+
data: method !== "GET" ? data : void 0,
|
|
150
|
+
params: method === "GET" ? data : void 0
|
|
151
|
+
});
|
|
152
|
+
return response.data;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (import_axios.default.isAxiosError(error)) {
|
|
155
|
+
const axiosError = error;
|
|
156
|
+
const errorMessage = axiosError.response?.data && typeof axiosError.response.data === "object" && "message" in axiosError.response.data ? String(axiosError.response.data.message) : axiosError.message;
|
|
157
|
+
throw new Error(`API Request Failed: ${errorMessage}`);
|
|
158
|
+
}
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
164
|
+
0 && (module.exports = {
|
|
165
|
+
Pay100,
|
|
166
|
+
PaymentVerificationError
|
|
167
|
+
});
|
|
168
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\n\n// Interface for constructor parameters\ninterface IPay100Config {\n publicKey: string;\n secretKey: string;\n baseUrl?: string;\n}\n\n// Interface for transaction data from API\ninterface ITransactionData {\n [key: string]: unknown; // For flexibility, since we don't know the exact structure\n}\n\n// Interface for raw API response\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n// Interface for API success response\ninterface IVerifyResponse {\n status: \"success\" | \"error\";\n data: ITransactionData | Record<string, never>;\n message?: string;\n}\n\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n// Error type for payment verification\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\nexport class Pay100 {\n private publicKey: string;\n private secretKey: string;\n private baseUrl: string;\n\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a request signature for secure server-to-server communication\n * @param payload Request payload to sign\n * @returns Object containing timestamp and signature\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", this.secretKey)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Create common headers for API requests\n * @param additionalHeaders Additional headers to include\n * @param payload Payload to sign (if signature is needed)\n * @returns Headers object\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate signature based on payload\n const { timestamp, signature } = this.createSignature(payload);\n\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verify a transaction\n * @param transactionId Transaction ID to verify\n * @returns Promise resolving to verification result\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n /**\n * Generic method to make authenticated API calls\n * @param method HTTP method\n * @param endpoint API endpoint\n * @param data Request payload\n * @returns Promise resolving to API response\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n return response.data as T;\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n const errorMessage =\n axiosError.response?.data &&\n typeof axiosError.response.data === \"object\" &&\n \"message\" in axiosError.response.data\n ? String(axiosError.response.data.message)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiD;AACjD,aAAwB;AA6BxB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAGlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,CAAC;AAAA,EACf;AACF;AAEO,IAAM,SAAN,MAAa;AAAA,EAKlB,YAAY,EAAE,WAAW,WAAW,UAAU,SAAS,GAAkB;AAoDzE;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAS,OAAO,kBAAoD;AAClE,UAAI;AACF,cAAM,UAAU,EAAE,cAAc;AAEhC,cAAM,WAA2C,UAAM,aAAAA,SAAM;AAAA,UAC3D,QAAQ;AAAA,UACR,KAAK,GAAG,KAAK,OAAO,8BAA8B,aAAa;AAAA,UAC/D,SAAS,KAAK,WAAW,OAAO;AAAA,UAChC,MAAM;AAAA,QACR,CAAC;AAGD,YAAI,CAAC,SAAS,MAAM;AAClB,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,MAAM,CAAC;AAAA,YACP,SACE;AAAA,UACJ;AAAA,QACF;AAGA,YAAI,OAAO,SAAS,SAAS,UA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A;AAAA;AAAA;AAAA;AAAA;AAAA,EAoFA,MAAM,QACJ,QACA,UACA,OAAgC,CAAC,GACrB;AACZ,QAAI;AACF,YAAM,MAAM,GAAG,KAAK,OAAO,GAAG,QAAQ;AACtC,YAAM,UAAU,KAAK,WAAW,IAAI;AAEpC,YAAM,WAAW,UAAM,aAAAA,SAAM;AAAA,QAC3B;AAAA,QACA;AAAA,QACA;AAAA,QACA,MAAM,WAAW,QAAQ,OAAO;AAAA,QAChC,QAAQ,WAAW,QAAQ,OAAO;AAAA,MACpC,CAAC;AAED,aAAO,SAAS;AAAA,IAClB,SAAS,OAAO;AACd,UAAI,aAAAA,QAAM,aAAa,KAAK,GAAG;AAC7B,cAAM,aAAa;AACnB,cAAM,eACJ,WAAW,UAAU,QACrB,OAAO,WAAW,SAAS,SAAS,YACpC,aAAa,WAAW,SAAS,OAC7B,OAAO,WAAW,SAAS,KAAK,OAAO,IACvC,WAAW;AAEjB,cAAM,IAAI,MAAM,uBAAuB,YAAY,EAAE;AAAA,MACvD;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":["axios"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
interface IPay100Config {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
secretKey: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
interface ITransactionData {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface IVerifyResponse {
|
|
10
|
+
status: "success" | "error";
|
|
11
|
+
data: ITransactionData | Record<string, never>;
|
|
12
|
+
message?: string;
|
|
13
|
+
}
|
|
14
|
+
declare class PaymentVerificationError extends Error {
|
|
15
|
+
status: string;
|
|
16
|
+
data: Record<string, never>;
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
declare class Pay100 {
|
|
20
|
+
private publicKey;
|
|
21
|
+
private secretKey;
|
|
22
|
+
private baseUrl;
|
|
23
|
+
constructor({ publicKey, secretKey, baseUrl }: IPay100Config);
|
|
24
|
+
/**
|
|
25
|
+
* Creates a request signature for secure server-to-server communication
|
|
26
|
+
* @param payload Request payload to sign
|
|
27
|
+
* @returns Object containing timestamp and signature
|
|
28
|
+
*/
|
|
29
|
+
private createSignature;
|
|
30
|
+
/**
|
|
31
|
+
* Create common headers for API requests
|
|
32
|
+
* @param additionalHeaders Additional headers to include
|
|
33
|
+
* @param payload Payload to sign (if signature is needed)
|
|
34
|
+
* @returns Headers object
|
|
35
|
+
*/
|
|
36
|
+
private getHeaders;
|
|
37
|
+
/**
|
|
38
|
+
* Verify a transaction
|
|
39
|
+
* @param transactionId Transaction ID to verify
|
|
40
|
+
* @returns Promise resolving to verification result
|
|
41
|
+
*/
|
|
42
|
+
verify: (transactionId: string) => Promise<IVerifyResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* Generic method to make authenticated API calls
|
|
45
|
+
* @param method HTTP method
|
|
46
|
+
* @param endpoint API endpoint
|
|
47
|
+
* @param data Request payload
|
|
48
|
+
* @returns Promise resolving to API response
|
|
49
|
+
*/
|
|
50
|
+
request<T>(method: "GET" | "POST" | "PUT" | "DELETE", endpoint: string, data?: Record<string, unknown>): Promise<T>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { Pay100, PaymentVerificationError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
interface IPay100Config {
|
|
2
2
|
publicKey: string;
|
|
3
3
|
secretKey: string;
|
|
4
|
+
baseUrl?: string;
|
|
4
5
|
}
|
|
5
6
|
interface ITransactionData {
|
|
6
7
|
[key: string]: unknown;
|
|
@@ -10,16 +11,43 @@ interface IVerifyResponse {
|
|
|
10
11
|
data: ITransactionData | Record<string, never>;
|
|
11
12
|
message?: string;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
declare class PaymentVerificationError extends Error {
|
|
14
15
|
status: string;
|
|
15
16
|
data: Record<string, never>;
|
|
16
17
|
constructor(message: string);
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
declare class Pay100 {
|
|
19
20
|
private publicKey;
|
|
20
21
|
private secretKey;
|
|
21
|
-
|
|
22
|
+
private baseUrl;
|
|
23
|
+
constructor({ publicKey, secretKey, baseUrl }: IPay100Config);
|
|
24
|
+
/**
|
|
25
|
+
* Creates a request signature for secure server-to-server communication
|
|
26
|
+
* @param payload Request payload to sign
|
|
27
|
+
* @returns Object containing timestamp and signature
|
|
28
|
+
*/
|
|
29
|
+
private createSignature;
|
|
30
|
+
/**
|
|
31
|
+
* Create common headers for API requests
|
|
32
|
+
* @param additionalHeaders Additional headers to include
|
|
33
|
+
* @param payload Payload to sign (if signature is needed)
|
|
34
|
+
* @returns Headers object
|
|
35
|
+
*/
|
|
36
|
+
private getHeaders;
|
|
37
|
+
/**
|
|
38
|
+
* Verify a transaction
|
|
39
|
+
* @param transactionId Transaction ID to verify
|
|
40
|
+
* @returns Promise resolving to verification result
|
|
41
|
+
*/
|
|
22
42
|
verify: (transactionId: string) => Promise<IVerifyResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* Generic method to make authenticated API calls
|
|
45
|
+
* @param method HTTP method
|
|
46
|
+
* @param endpoint API endpoint
|
|
47
|
+
* @param data Request payload
|
|
48
|
+
* @returns Promise resolving to API response
|
|
49
|
+
*/
|
|
50
|
+
request<T>(method: "GET" | "POST" | "PUT" | "DELETE", endpoint: string, data?: Record<string, unknown>): Promise<T>;
|
|
23
51
|
}
|
|
24
|
-
|
|
25
|
-
|
|
52
|
+
|
|
53
|
+
export { Pay100, PaymentVerificationError };
|
package/dist/index.js
CHANGED
|
@@ -1,73 +1,132 @@
|
|
|
1
|
+
// src/index.ts
|
|
1
2
|
import axios from "axios";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
data: transactionData,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
// Handle Axios errors
|
|
60
|
-
if (axios.isAxiosError(error)) {
|
|
61
|
-
const axiosError = error;
|
|
62
|
-
throw new PaymentVerificationError(axiosError.message ||
|
|
63
|
-
"Something went wrong, be sure you supplied a valid payment id.");
|
|
64
|
-
}
|
|
65
|
-
// Handle other errors
|
|
66
|
-
throw new PaymentVerificationError(error instanceof Error ? error.message : "An unknown error occurred");
|
|
67
|
-
}
|
|
3
|
+
import * as crypto from "crypto";
|
|
4
|
+
var BASE_URL = process.env.BASE_URL || "https://api.100pay.co";
|
|
5
|
+
var PaymentVerificationError = class extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "PaymentVerificationError";
|
|
9
|
+
this.status = "error";
|
|
10
|
+
this.data = {};
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var Pay100 = class {
|
|
14
|
+
constructor({ publicKey, secretKey, baseUrl = BASE_URL }) {
|
|
15
|
+
/**
|
|
16
|
+
* Verify a transaction
|
|
17
|
+
* @param transactionId Transaction ID to verify
|
|
18
|
+
* @returns Promise resolving to verification result
|
|
19
|
+
*/
|
|
20
|
+
this.verify = async (transactionId) => {
|
|
21
|
+
try {
|
|
22
|
+
const payload = { transactionId };
|
|
23
|
+
const response = await axios({
|
|
24
|
+
method: "POST",
|
|
25
|
+
url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,
|
|
26
|
+
headers: this.getHeaders(payload),
|
|
27
|
+
data: payload
|
|
28
|
+
});
|
|
29
|
+
if (!response.data) {
|
|
30
|
+
return {
|
|
31
|
+
status: "error",
|
|
32
|
+
data: {},
|
|
33
|
+
message: "Something went wrong, be sure you supplied a valid payment id."
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (typeof response.data === "string") {
|
|
37
|
+
if (response.data === "Access Denied, Invalid KEY supplied") {
|
|
38
|
+
return {
|
|
39
|
+
status: "error",
|
|
40
|
+
data: {},
|
|
41
|
+
message: "Access Denied, Invalid KEY supplied"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (response.data === "invalid payment id supplied") {
|
|
45
|
+
return {
|
|
46
|
+
status: "error",
|
|
47
|
+
data: {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const responseData = response.data;
|
|
52
|
+
const transactionData = responseData && typeof responseData === "object" ? responseData : {};
|
|
53
|
+
return {
|
|
54
|
+
status: "success",
|
|
55
|
+
data: transactionData
|
|
68
56
|
};
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (axios.isAxiosError(error)) {
|
|
59
|
+
const axiosError = error;
|
|
60
|
+
throw new PaymentVerificationError(
|
|
61
|
+
axiosError.message || "Something went wrong, be sure you supplied a valid payment id."
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
throw new PaymentVerificationError(
|
|
65
|
+
error instanceof Error ? error.message : "An unknown error occurred"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this.publicKey = publicKey;
|
|
70
|
+
this.secretKey = secretKey;
|
|
71
|
+
this.baseUrl = baseUrl;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a request signature for secure server-to-server communication
|
|
75
|
+
* @param payload Request payload to sign
|
|
76
|
+
* @returns Object containing timestamp and signature
|
|
77
|
+
*/
|
|
78
|
+
createSignature(payload) {
|
|
79
|
+
const timestamp = Date.now().toString();
|
|
80
|
+
const signature = crypto.createHmac("sha256", this.secretKey).update(timestamp + JSON.stringify(payload)).digest("hex");
|
|
81
|
+
return { timestamp, signature };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create common headers for API requests
|
|
85
|
+
* @param additionalHeaders Additional headers to include
|
|
86
|
+
* @param payload Payload to sign (if signature is needed)
|
|
87
|
+
* @returns Headers object
|
|
88
|
+
*/
|
|
89
|
+
getHeaders(payload = {}) {
|
|
90
|
+
const { timestamp, signature } = this.createSignature(payload);
|
|
91
|
+
return {
|
|
92
|
+
"api-key": this.publicKey,
|
|
93
|
+
"x-secret-key": this.secretKey,
|
|
94
|
+
"x-timestamp": timestamp,
|
|
95
|
+
"x-signature": signature,
|
|
96
|
+
"Content-Type": "application/json"
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generic method to make authenticated API calls
|
|
101
|
+
* @param method HTTP method
|
|
102
|
+
* @param endpoint API endpoint
|
|
103
|
+
* @param data Request payload
|
|
104
|
+
* @returns Promise resolving to API response
|
|
105
|
+
*/
|
|
106
|
+
async request(method, endpoint, data = {}) {
|
|
107
|
+
try {
|
|
108
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
109
|
+
const headers = this.getHeaders(data);
|
|
110
|
+
const response = await axios({
|
|
111
|
+
method,
|
|
112
|
+
url,
|
|
113
|
+
headers,
|
|
114
|
+
data: method !== "GET" ? data : void 0,
|
|
115
|
+
params: method === "GET" ? data : void 0
|
|
116
|
+
});
|
|
117
|
+
return response.data;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (axios.isAxiosError(error)) {
|
|
120
|
+
const axiosError = error;
|
|
121
|
+
const errorMessage = axiosError.response?.data && typeof axiosError.response.data === "object" && "message" in axiosError.response.data ? String(axiosError.response.data.message) : axiosError.message;
|
|
122
|
+
throw new Error(`API Request Failed: ${errorMessage}`);
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
71
125
|
}
|
|
72
|
-
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
export {
|
|
129
|
+
Pay100,
|
|
130
|
+
PaymentVerificationError
|
|
131
|
+
};
|
|
73
132
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios, { AxiosError, AxiosResponse } from \"axios\";\nimport * as crypto from \"crypto\";\n\n// Interface for constructor parameters\ninterface IPay100Config {\n publicKey: string;\n secretKey: string;\n baseUrl?: string;\n}\n\n// Interface for transaction data from API\ninterface ITransactionData {\n [key: string]: unknown; // For flexibility, since we don't know the exact structure\n}\n\n// Interface for raw API response\ninterface IRawApiResponse {\n status?: string;\n message?: string;\n data?: unknown;\n [key: string]: unknown;\n}\n\n// Interface for API success response\ninterface IVerifyResponse {\n status: \"success\" | \"error\";\n data: ITransactionData | Record<string, never>;\n message?: string;\n}\n\nconst BASE_URL = process.env.BASE_URL || \"https://api.100pay.co\";\n\n// Error type for payment verification\nexport class PaymentVerificationError extends Error {\n status: string;\n data: Record<string, never>;\n\n constructor(message: string) {\n super(message);\n this.name = \"PaymentVerificationError\";\n this.status = \"error\";\n this.data = {};\n }\n}\n\nexport class Pay100 {\n private publicKey: string;\n private secretKey: string;\n private baseUrl: string;\n\n constructor({ publicKey, secretKey, baseUrl = BASE_URL }: IPay100Config) {\n this.publicKey = publicKey;\n this.secretKey = secretKey;\n this.baseUrl = baseUrl;\n }\n\n /**\n * Creates a request signature for secure server-to-server communication\n * @param payload Request payload to sign\n * @returns Object containing timestamp and signature\n */\n private createSignature(payload: Record<string, unknown>): {\n timestamp: string;\n signature: string;\n } {\n const timestamp = Date.now().toString();\n\n // Create signature using HMAC SHA-256\n const signature = crypto\n .createHmac(\"sha256\", this.secretKey)\n .update(timestamp + JSON.stringify(payload))\n .digest(\"hex\");\n\n return { timestamp, signature };\n }\n\n /**\n * Create common headers for API requests\n * @param additionalHeaders Additional headers to include\n * @param payload Payload to sign (if signature is needed)\n * @returns Headers object\n */\n private getHeaders(\n payload: Record<string, unknown> = {}\n ): Record<string, string> {\n // Generate signature based on payload\n const { timestamp, signature } = this.createSignature(payload);\n\n return {\n \"api-key\": this.publicKey,\n \"x-secret-key\": this.secretKey,\n \"x-timestamp\": timestamp,\n \"x-signature\": signature,\n \"Content-Type\": \"application/json\",\n };\n }\n\n /**\n * Verify a transaction\n * @param transactionId Transaction ID to verify\n * @returns Promise resolving to verification result\n */\n verify = async (transactionId: string): Promise<IVerifyResponse> => {\n try {\n const payload = { transactionId };\n\n const response: AxiosResponse<IRawApiResponse> = await axios({\n method: \"POST\",\n url: `${this.baseUrl}/api/v1/pay/crypto/payment/${transactionId}`,\n headers: this.getHeaders(payload),\n data: payload,\n });\n\n // Handle empty response\n if (!response.data) {\n return {\n status: \"error\",\n data: {},\n message:\n \"Something went wrong, be sure you supplied a valid payment id.\",\n };\n }\n\n // Handle string responses which indicate errors\n if (typeof response.data === \"string\") {\n if (response.data === \"Access Denied, Invalid KEY supplied\") {\n return {\n status: \"error\",\n data: {},\n message: \"Access Denied, Invalid KEY supplied\",\n };\n }\n\n if (response.data === \"invalid payment id supplied\") {\n return {\n status: \"error\",\n data: {},\n };\n }\n }\n\n // Validate and transform response data to ensure type safety\n const responseData = response.data;\n\n // Ensure the response data is an object that can be safely cast to ITransactionData\n const transactionData: ITransactionData =\n responseData && typeof responseData === \"object\"\n ? (responseData as ITransactionData)\n : {};\n\n // Return successful response with properly typed data\n return {\n status: \"success\",\n data: transactionData,\n };\n } catch (error) {\n // Handle Axios errors\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n throw new PaymentVerificationError(\n axiosError.message ||\n \"Something went wrong, be sure you supplied a valid payment id.\"\n );\n }\n\n // Handle other errors\n throw new PaymentVerificationError(\n error instanceof Error ? error.message : \"An unknown error occurred\"\n );\n }\n };\n\n /**\n * Generic method to make authenticated API calls\n * @param method HTTP method\n * @param endpoint API endpoint\n * @param data Request payload\n * @returns Promise resolving to API response\n */\n async request<T>(\n method: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\",\n endpoint: string,\n data: Record<string, unknown> = {}\n ): Promise<T> {\n try {\n const url = `${this.baseUrl}${endpoint}`;\n const headers = this.getHeaders(data);\n\n const response = await axios({\n method,\n url,\n headers,\n data: method !== \"GET\" ? data : undefined,\n params: method === \"GET\" ? data : undefined,\n });\n\n return response.data as T;\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n const errorMessage =\n axiosError.response?.data &&\n typeof axiosError.response.data === \"object\" &&\n \"message\" in axiosError.response.data\n ? String(axiosError.response.data.message)\n : axiosError.message;\n\n throw new Error(`API Request Failed: ${errorMessage}`);\n }\n\n throw error;\n }\n }\n}\n"],"mappings":";AAAA,OAAO,WAA0C;AACjD,YAAY,YAAY;AA6BxB,IAAM,WAAW,QAAQ,IAAI,YAAY;AAGlC,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAIlD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,CAAC;AAAA,EACf;AACF;AAEO,IAAM,SAAN,MAAa;AAAA,EAKlB,YAAY,EAAE,WAAW,WAAW,UAAU,SAAS,GAAkB;AAoDzE;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAS,OAAO,kBAAoD;AAClE,UAAI;AACF,cAAM,UAAU,EAAE,cAAc;AAEhC,cAAM,WAA2C,MAAM,MAAM;AAAA,UAC3D,QAAQ;A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;AAAA;AAAA;AAAA;AAAA,EAQQ,WACN,UAAmC,CAAC,GACZ;AAExB,UAAM,EAAE,WAAW,UAAU,IAAI,KAAK,gBAAgB,OAAO;AAE7D,WAAO;AAAA,MACL,WAAW,KAAK;AAAA,MAChB,gBAAgB,KAAK;AAAA,MACrB,eAAe;AAAA,MACf,eAAe;AAAA,MACf,gBAAgB;AAAA,IAClB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoFA,MAAM,QACJ,QACA,UACA,OAAgC,CAAC,GACrB;AACZ,QAAI;AACF,YAAM,MAAM,GAAG,KAAK,OAAO,GAAG,QAAQ;AACtC,YAAM,UAAU,KAAK,WAAW,IAAI;AAEpC,YAAM,WAAW,MAAM,MAAM;AAAA,QAC3B;AAAA,QACA;AAAA,QACA;AAAA,QACA,MAAM,WAAW,QAAQ,OAAO;AAAA,QAChC,QAAQ,WAAW,QAAQ,OAAO;AAAA,MACpC,CAAC;AAED,aAAO,SAAS;AAAA,IAClB,SAAS,OAAO;AACd,UAAI,MAAM,aAAa,KAAK,GAAG;AAC7B,cAAM,aAAa;AACnB,cAAM,eACJ,WAAW,UAAU,QACrB,OAAO,WAAW,SAAS,SAAS,YACpC,aAAa,WAAW,SAAS,OAC7B,OAAO,WAAW,SAAS,KAAK,OAAO,IACvC,WAAW;AAEjB,cAAM,IAAI,MAAM,uBAAuB,YAAY,EAAE;AAAA,MACvD;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@100pay-hq/100pay.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "100Pay.js is the official Nodejs API wrapper SDK that lets you easily verify crypto payments, run bulk payout, transfer assets and many more.",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
5
|
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
"*": {
|
|
17
|
+
"*": [
|
|
18
|
+
"dist/index.d.ts"
|
|
19
|
+
]
|
|
12
20
|
}
|
|
13
21
|
},
|
|
14
22
|
"files": [
|
|
@@ -17,11 +25,11 @@
|
|
|
17
25
|
"README.md"
|
|
18
26
|
],
|
|
19
27
|
"scripts": {
|
|
28
|
+
"build": "tsup",
|
|
29
|
+
"build:clean": "rm -rf dist && tsup",
|
|
20
30
|
"test": "jest",
|
|
21
31
|
"test:watch": "jest --watch",
|
|
22
32
|
"test:coverage": "jest --coverage",
|
|
23
|
-
"build": "tsc",
|
|
24
|
-
"build:clean": "rm -rf dist && tsc",
|
|
25
33
|
"type-check": "tsc --noEmit",
|
|
26
34
|
"lint": "eslint . --ext .ts",
|
|
27
35
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { Pay100, PaymentVerificationError } from "../index";
|
|
3
|
-
jest.mock("axios");
|
|
4
|
-
describe("Pay100", () => {
|
|
5
|
-
const config = {
|
|
6
|
-
publicKey: "test_public_key",
|
|
7
|
-
secretKey: "test_secret_key",
|
|
8
|
-
};
|
|
9
|
-
let pay100;
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
pay100 = new Pay100(config);
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
});
|
|
14
|
-
describe("verify", () => {
|
|
15
|
-
it("should successfully verify a transaction", async () => {
|
|
16
|
-
const mockResponse = {
|
|
17
|
-
status: "completed",
|
|
18
|
-
amount: "100",
|
|
19
|
-
currency: "USDT",
|
|
20
|
-
};
|
|
21
|
-
axios.mockResolvedValueOnce({
|
|
22
|
-
data: mockResponse,
|
|
23
|
-
});
|
|
24
|
-
const result = await pay100.verify("valid_transaction_id");
|
|
25
|
-
expect(result).toEqual({
|
|
26
|
-
status: "success",
|
|
27
|
-
data: mockResponse,
|
|
28
|
-
});
|
|
29
|
-
expect(axios).toHaveBeenCalledWith({
|
|
30
|
-
method: "POST",
|
|
31
|
-
url: "https://api.100pay.co/api/v1/pay/crypto/payment/valid_transaction_id",
|
|
32
|
-
headers: {
|
|
33
|
-
"api-key": config.publicKey,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
it("should handle empty response data", async () => {
|
|
38
|
-
axios.mockResolvedValueOnce({
|
|
39
|
-
data: null,
|
|
40
|
-
});
|
|
41
|
-
const result = await pay100.verify("transaction_id");
|
|
42
|
-
expect(result).toEqual({
|
|
43
|
-
status: "error",
|
|
44
|
-
data: {},
|
|
45
|
-
message: "Something went wrong, be sure you supplied a valid payment id.",
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
it("should handle invalid API key error", async () => {
|
|
49
|
-
axios.mockResolvedValueOnce({
|
|
50
|
-
data: "Access Denied, Invalid KEY supplied",
|
|
51
|
-
});
|
|
52
|
-
const result = await pay100.verify("transaction_id");
|
|
53
|
-
expect(result).toEqual({
|
|
54
|
-
status: "error",
|
|
55
|
-
data: {},
|
|
56
|
-
message: "Access Denied, Invalid KEY supplied",
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
it("should handle invalid payment ID error", async () => {
|
|
60
|
-
axios.mockResolvedValueOnce({
|
|
61
|
-
data: "invalid payment id supplied",
|
|
62
|
-
});
|
|
63
|
-
const result = await pay100.verify("invalid_id");
|
|
64
|
-
expect(result).toEqual({
|
|
65
|
-
status: "error",
|
|
66
|
-
data: {},
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
it("should handle network errors", async () => {
|
|
70
|
-
const networkError = new Error("Network Error");
|
|
71
|
-
Object.defineProperty(networkError, "isAxiosError", { value: true });
|
|
72
|
-
axios.mockRejectedValueOnce(networkError);
|
|
73
|
-
await expect(pay100.verify("transaction_id")).rejects.toThrow(
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
|
|
75
|
-
new PaymentVerificationError("Network Error"));
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/__tests__/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAE5D,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,iBAAiB;QAC5B,SAAS,EAAE,iBAAiB;KAC7B,CAAC;IAEF,IAAI,MAAc,CAAC;IAEnB,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;YACxD,MAAM,YAAY,GAAG;gBACnB,MAAM,EAAE,WAAW;gBACnB,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,MAAM;aACjB,CAAC;YAGA,KACD,CAA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