@dpayglobal/dpay-node-sdk 0.1.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.
@@ -0,0 +1,54 @@
1
+ import { ApiResponse, phpJsonEncode } from './chunk-SPQCX4N4.js';
2
+
3
+ // src/testing.ts
4
+ var MockHttpClient = class {
5
+ /** Every request the SDK made, in order. */
6
+ requests = [];
7
+ queued = [];
8
+ /** Queues a prepared response. */
9
+ queue(response) {
10
+ this.queued.push(response);
11
+ }
12
+ /** Queues a JSON response, encoded the same way the SDK encodes bodies. */
13
+ queueJson(status, body, headers = {}) {
14
+ this.queue(
15
+ new ApiResponse(status, { "content-type": "application/json", ...headers }, phpJsonEncode(body))
16
+ );
17
+ }
18
+ /** Queues a plain text response. */
19
+ queueText(status, body, headers = {}) {
20
+ this.queue(new ApiResponse(status, headers, body));
21
+ }
22
+ request(request) {
23
+ this.requests.push(request);
24
+ const response = this.queued.shift();
25
+ if (response === void 0) return Promise.reject(new Error("MockHttpClient queue is empty"));
26
+ return Promise.resolve(response);
27
+ }
28
+ /** The most recent request. Throws when nothing was recorded. */
29
+ get lastRequest() {
30
+ const request = this.requests.at(-1);
31
+ if (request === void 0) throw new Error("No requests recorded");
32
+ return request;
33
+ }
34
+ /** The most recent request body, decoded. Throws when it was not a JSON object. */
35
+ get lastRequestBody() {
36
+ const body = this.lastRequest.body;
37
+ let decoded = null;
38
+ if (body !== null) {
39
+ try {
40
+ decoded = JSON.parse(body);
41
+ } catch {
42
+ decoded = null;
43
+ }
44
+ }
45
+ if (typeof decoded !== "object" || decoded === null || Array.isArray(decoded)) {
46
+ throw new Error("Last request has no JSON object body");
47
+ }
48
+ return decoded;
49
+ }
50
+ };
51
+
52
+ export { MockHttpClient };
53
+ //# sourceMappingURL=testing.js.map
54
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/testing.ts"],"names":[],"mappings":";;;AAKO,IAAM,iBAAN,MA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K,WAAA,CAAY,IAAA;AAC9B,IAAA,IAAI,OAAA,GAAmB,IAAA;AACvB,IAAA,IAAI,SAAS,IAAA,EAAM;AACjB,MAAA,IAAI;AACF,QAAA,OAAA,GAAU,IAAA,CAAK,MAAM,IAAI,CAAA;AAAA,MAC3B,CAAA,CAAA,MAAQ;AACN,QAAA,OAAA,GAAU,IAAA;AAAA,MACZ;AAAA,IACF;AACA,IAAA,IAAI,OAAO,YAAY,QAAA,IAAY,OAAA,KAAY,QAAQ,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AAC7E,MAAA,MAAM,IAAI,MAAM,sCAAsC,CAAA;AAAA,IACxD;AACA,IAAA,OAAO,OAAA;AAAA,EACT;AACF","file":"testing.js","sourcesContent":["import { ApiResponse } from './http/types.js'\nimport type { ApiRequest, HttpClient } from './http/types.js'\nimport { phpJsonEncode } from './internal/php.js'\n\n/** In-memory transport for testing an integration without network access. */\nexport class MockHttpClient implements HttpClient {\n /** Every request the SDK made, in order. */\n readonly requests: ApiRequest[] = []\n private readonly queued: ApiResponse[] = []\n\n /** Queues a prepared response. */\n queue(response: ApiResponse): void {\n this.queued.push(response)\n }\n\n /** Queues a JSON response, encoded the same way the SDK encodes bodies. */\n queueJson(status: number, body: unknown, headers: Readonly<Record<string, string>> = {}): void {\n this.queue(\n new ApiResponse(status, { 'content-type': 'application/json', ...headers }, phpJsonEncode(body)),\n )\n }\n\n /** Queues a plain text response. */\n queueText(status: number, body: string, headers: Readonly<Record<string, string>> = {}): void {\n this.queue(new ApiResponse(status, headers, body))\n }\n\n request(request: ApiRequest): Promise<ApiResponse> {\n this.requests.push(request)\n const response = this.queued.shift()\n if (response === undefined) return Promise.reject(new Error('MockHttpClient queue is empty'))\n return Promise.resolve(response)\n }\n\n /** The most recent request. Throws when nothing was recorded. */\n get lastRequest(): ApiRequest {\n const request = this.requests.at(-1)\n if (request === undefined) throw new Error('No requests recorded')\n return request\n }\n\n /** The most recent request body, decoded. Throws when it was not a JSON object. */\n get lastRequestBody(): Record<string, unknown> {\n const body = this.lastRequest.body\n let decoded: unknown = null\n if (body !== null) {\n try {\n decoded = JSON.parse(body)\n } catch {\n decoded = null\n }\n }\n if (typeof decoded !== 'object' || decoded === null || Array.isArray(decoded)) {\n throw new Error('Last request has no JSON object body')\n }\n return decoded as Record<string, unknown>\n }\n}\n"]}
@@ -0,0 +1,48 @@
1
+ /** A single outbound HTTP request built by the SDK. */
2
+ interface ApiRequest {
3
+ readonly method: 'GET' | 'POST';
4
+ readonly url: string;
5
+ readonly headers: Readonly<Record<string, string>>;
6
+ readonly body: string | null;
7
+ readonly signal?: AbortSignal;
8
+ }
9
+ /** A raw HTTP response handed back to the SDK. */
10
+ declare class ApiResponse {
11
+ readonly status: number;
12
+ readonly headers: Readonly<Record<string, string>>;
13
+ readonly body: string;
14
+ constructor(status: number, headers: Readonly<Record<string, string>>, body: string);
15
+ /**
16
+ * Retrieve the response header value by name, performing a case-insensitive lookup.
17
+ * Returns `null` if the header was not present in the response.
18
+ */
19
+ getHeader(name: string): string | null;
20
+ /**
21
+ * Attempt to decode the response body as JSON, returning the parsed value if it is a
22
+ * plain object or array, or `null` if the body is not valid JSON or the parsed value
23
+ * is a primitive (string, number, boolean, null).
24
+ */
25
+ decodeJson(): unknown;
26
+ }
27
+ /**
28
+ * Transport contract. Replace the default implementation to add proxying,
29
+ * retries or request recording in tests.
30
+ *
31
+ * Critical invariant: the `request()` method must resolve to an `ApiResponse` for
32
+ * every response the server actually sent, including 4xx and 5xx status codes.
33
+ * It must reject with an error only when no response was obtained at all—that is,
34
+ * for a genuine transport failure such as a connection reset, timeout, or abort.
35
+ *
36
+ * If your implementation rejects on 4xx or 5xx responses, the SDK will be unable
37
+ * to map the status code to its typed error classes, and the SDK's error handling
38
+ * will break silently.
39
+ */
40
+ interface HttpClient {
41
+ /**
42
+ * Execute an HTTP request and return the server's response. Must resolve with
43
+ * an `ApiResponse` for every response, and reject only on transport failure.
44
+ */
45
+ request(request: ApiRequest): Promise<ApiResponse>;
46
+ }
47
+
48
+ export { ApiResponse as A, type HttpClient as H, type ApiRequest as a };
@@ -0,0 +1,48 @@
1
+ /** A single outbound HTTP request built by the SDK. */
2
+ interface ApiRequest {
3
+ readonly method: 'GET' | 'POST';
4
+ readonly url: string;
5
+ readonly headers: Readonly<Record<string, string>>;
6
+ readonly body: string | null;
7
+ readonly signal?: AbortSignal;
8
+ }
9
+ /** A raw HTTP response handed back to the SDK. */
10
+ declare class ApiResponse {
11
+ readonly status: number;
12
+ readonly headers: Readonly<Record<string, string>>;
13
+ readonly body: string;
14
+ constructor(status: number, headers: Readonly<Record<string, string>>, body: string);
15
+ /**
16
+ * Retrieve the response header value by name, performing a case-insensitive lookup.
17
+ * Returns `null` if the header was not present in the response.
18
+ */
19
+ getHeader(name: string): string | null;
20
+ /**
21
+ * Attempt to decode the response body as JSON, returning the parsed value if it is a
22
+ * plain object or array, or `null` if the body is not valid JSON or the parsed value
23
+ * is a primitive (string, number, boolean, null).
24
+ */
25
+ decodeJson(): unknown;
26
+ }
27
+ /**
28
+ * Transport contract. Replace the default implementation to add proxying,
29
+ * retries or request recording in tests.
30
+ *
31
+ * Critical invariant: the `request()` method must resolve to an `ApiResponse` for
32
+ * every response the server actually sent, including 4xx and 5xx status codes.
33
+ * It must reject with an error only when no response was obtained at all—that is,
34
+ * for a genuine transport failure such as a connection reset, timeout, or abort.
35
+ *
36
+ * If your implementation rejects on 4xx or 5xx responses, the SDK will be unable
37
+ * to map the status code to its typed error classes, and the SDK's error handling
38
+ * will break silently.
39
+ */
40
+ interface HttpClient {
41
+ /**
42
+ * Execute an HTTP request and return the server's response. Must resolve with
43
+ * an `ApiResponse` for every response, and reject only on transport failure.
44
+ */
45
+ request(request: ApiRequest): Promise<ApiResponse>;
46
+ }
47
+
48
+ export { ApiResponse as A, type HttpClient as H, type ApiRequest as a };
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@dpayglobal/dpay-node-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Official dpay.pl Node.js SDK",
5
+ "license": "Apache-2.0",
6
+ "author": "dpay <kontakt@dpay.pl>",
7
+ "homepage": "https://dpay.pl",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/dpayglobal/dpay-node-sdk.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/dpayglobal/dpay-node-sdk/issues"
14
+ },
15
+ "keywords": ["dpay", "payments", "blik", "cards", "sdk", "platnosci"],
16
+ "type": "module",
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
20
+ "sideEffects": false,
21
+ "exports": {
22
+ ".": {
23
+ "import": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/index.d.cts",
29
+ "default": "./dist/index.cjs"
30
+ }
31
+ },
32
+ "./testing": {
33
+ "import": {
34
+ "types": "./dist/testing.d.ts",
35
+ "default": "./dist/testing.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/testing.d.cts",
39
+ "default": "./dist/testing.cjs"
40
+ }
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "main": "./dist/index.cjs",
45
+ "module": "./dist/index.js",
46
+ "types": "./dist/index.d.ts",
47
+ "files": ["dist", "README.md", "CHANGELOG.md", "LICENSE"],
48
+ "dependencies": {},
49
+ "devDependencies": {
50
+ "@arethetypeswrong/cli": "^0.18.0",
51
+ "@biomejs/biome": "^1.9.0",
52
+ "@types/node": "^22.0.0",
53
+ "publint": "^0.3.0",
54
+ "tsup": "^8.3.0",
55
+ "typescript": "^5.6.0",
56
+ "vitest": "^2.1.0"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "typecheck": "tsc --noEmit",
61
+ "test": "vitest run",
62
+ "test:watch": "vitest",
63
+ "lint": "biome check .",
64
+ "format": "biome check --write .",
65
+ "package:check": "npm run build && publint && attw --pack . --profile node16",
66
+ "prepublishOnly": "npm run build"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public"
70
+ }
71
+ }