@sebastienrousseau/crypto-api 0.0.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright © Sebastien Rousseau 2022. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,258 @@
1
+ <!-- SPDX-License-Identifier: Apache-2.0 OR MIT -->
2
+
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/sebastienrousseau/crypto-service/main/assets/crypto-api-logo.svg" alt="crypto-api logo" width="360" />
5
+ </p>
6
+
7
+ <h1 align="center">@sebastienrousseau/crypto-api</h1>
8
+
9
+ <p align="center">
10
+ Shared TypeScript types and utilities for the Crypto Service Suite, defining the canonical API surface.
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://github.com/sebastienrousseau/crypto-service/actions"><img src="https://img.shields.io/github/actions/workflow/status/sebastienrousseau/crypto-service/ci.yml?branch=main&style=for-the-badge&logo=github" alt="Build" /></a>
15
+ <a href="https://coveralls.io/github/sebastienrousseau/crypto-service?branch=main"><img src="https://img.shields.io/coveralls/github/sebastienrousseau/crypto-service?branch=main&style=for-the-badge" alt="Coverage" /></a>
16
+ <a href="https://www.npmjs.com/package/@sebastienrousseau/crypto-api"><img src="https://img.shields.io/npm/v/@sebastienrousseau/crypto-api.svg?style=for-the-badge&color=f14041&logo=npm" alt="Registry" /></a>
17
+ <a href="https://sebastienrousseau.github.io/crypto-service/"><img src="https://img.shields.io/badge/docs-TypeDoc-blue.svg?style=for-the-badge&labelColor=555555&logo=typescript" alt="Docs" /></a>
18
+ <a href="https://scorecard.dev/viewer/?uri=github.com/sebastienrousseau/crypto-service" title="ossf-scorecard"><img src="https://img.shields.io/badge/OpenSSF-Scorecard-blue?style=for-the-badge&logo=openssf" alt="OpenSSF Scorecard" /></a>
19
+ <a href="https://github.com/sebastienrousseau/crypto-service/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg?style=for-the-badge" alt="License: Apache-2.0 OR MIT" /></a>
20
+ <a href="https://github.com/sebastienrousseau/crypto-service/blob/main/docs/POLICIES.md"><img src="https://img.shields.io/badge/Node.js-%3E%3D22-93450a.svg?style=for-the-badge&logo=node.js" alt="Node.js 22 or newer" /></a>
21
+ </p>
22
+
23
+ ---
24
+
25
+ ## Contents
26
+
27
+ **Getting started**
28
+
29
+ - [Install](#install) — installation via pnpm, npm, or yarn
30
+ - [Requirements](#requirements) — runtime floor and environment prerequisites
31
+ - [Quick Start](#quick-start) — minimal working usage sample
32
+
33
+ **The Crypto Service ecosystem**
34
+
35
+ - [The Crypto Service ecosystem](#the-crypto-service-ecosystem) — full 14-package suite overview
36
+
37
+ **Package reference**
38
+
39
+ - [Reference & Usage](#overview) — features, configuration, and capabilities
40
+ - [Examples](#examples) — runnable sample code
41
+
42
+ **Operational**
43
+
44
+ - [Development](#development) — build, lint, format, and test targets
45
+ - [Security](#security) — vulnerability disclosure and cryptographic invariants
46
+ - [Documentation](#documentation) — TypeDoc API docs and ecosystem guides
47
+ - [Stability guarantees](#stability-guarantees) — SemVer axis and release policy
48
+ - [License](#license)
49
+
50
+ ---
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ pnpm add @sebastienrousseau/crypto-api
56
+ # or
57
+ npm install @sebastienrousseau/crypto-api
58
+ # or
59
+ yarn add @sebastienrousseau/crypto-api
60
+ ```
61
+
62
+ <p align="right"><a href="#contents">Back to Top</a></p>
63
+
64
+ ---
65
+
66
+ ## Requirements
67
+
68
+ - **Node.js**: `^22.0.0` or `>=24.0.0` (active and maintenance LTS releases)
69
+ - **Package Manager**: `pnpm >=9` (recommended) or `npm >=10`
70
+ - **TypeScript**: `>=5.0` (when compiling with TypeScript)
71
+
72
+ <p align="right"><a href="#contents">Back to Top</a></p>
73
+
74
+ ---
75
+
76
+ ## Quick Start
77
+
78
+ Import shared types and use them to build type-safe requests and
79
+ responses across `crypto-server` and `crypto-sdk`.
80
+
81
+ ```ts
82
+ import type {
83
+ AuthorizationToken,
84
+ AuthorizationInfo,
85
+ CollectionItem,
86
+ JsonDocument,
87
+ JsonRequest,
88
+ RequestHeader,
89
+ ResponseType,
90
+ } from "@sebastienrousseau/crypto-api/dist/@types/types";
91
+
92
+ // Type-safe request header
93
+ const header: RequestHeader = {
94
+ key: "Content-Type",
95
+ value: "application/json",
96
+ description: "Request content type",
97
+ };
98
+
99
+ // Build a typed JSON request
100
+ const request: JsonRequest = {
101
+ header: [header],
102
+ key: "encrypt",
103
+ value: "aes-256-gcm",
104
+ description: "Encrypt payload with AES-256-GCM",
105
+ };
106
+ ```
107
+
108
+ <p align="right"><a href="#contents">Back to Top</a></p>
109
+
110
+ ---
111
+
112
+ ## The Crypto Service ecosystem
113
+
114
+ Crypto Service provides a complete cryptography stack across 14 specialized packages:
115
+
116
+ | Package | Role | Description |
117
+ | :-------------------------------------------------------------------- | :-------------- | :------------------------------------------------------------------------------------------------------------------------------------- |
118
+ | **[`@sebastienrousseau/crypto-api`](../crypto-api)** _(this package)_ | **API Schemas** | **Shared TypeScript types and utilities for the Crypto Service Suite, defining the canonical API surface.** |
119
+ | [`@sebastienrousseau/crypto-cli`](../crypto-cli) | Terminal CLI | An interactive command-line interface for cryptographic operations, supporting both legacy OpenPGP and modern post-quantum algorithms. |
120
+ | [`@sebastienrousseau/crypto-edge`](../crypto-edge) | Edge Runtime | Edge-runtime cryptographic operations using the Web Crypto API, optimized for Cloudflare Workers, Vercel Edge, and Deno. |
121
+ | [`@sebastienrousseau/crypto-kms`](../crypto-kms) | Cloud KMS | Unified Key Management Service interface for AWS KMS, GCP Cloud KMS, Azure Key Vault, and HashiCorp Vault. |
122
+ | [`@sebastienrousseau/crypto-lib`](../crypto-lib) | Core Library | A modern cryptographic library for TypeScript, with post-quantum support, zero unsafe dependencies, and 100% test coverage. |
123
+ | [`@sebastienrousseau/crypto-middleware`](../crypto-middleware) | Middleware | Framework-agnostic cryptographic middleware for Express, Fastify, and Koa applications. |
124
+ | [`@sebastienrousseau/crypto-prisma`](../crypto-prisma) | ORM Adapter | Transparent field-level encryption extension for Prisma Client, using XChaCha20-Poly1305. |
125
+ | [`@sebastienrousseau/crypto-react`](../crypto-react) | React Hooks | React hooks and context provider for client-side cryptographic operations with zero boilerplate. |
126
+ | [`@sebastienrousseau/crypto-sdk`](../crypto-sdk) | Client SDK | A zero-dependency, typed HTTP client for the Crypto Service REST API, with full post-quantum support. |
127
+ | [`@sebastienrousseau/crypto-server`](../crypto-server) | HTTP API | A hardened Fastify REST API for cryptographic operations, with rate limiting, OpenAPI schemas, and post-quantum endpoints. |
128
+ | [`@sebastienrousseau/crypto-testing`](../crypto-testing) | Test Support | Deterministic keys, fast mocks, and test fixtures for crypto-lib |
129
+ | [`@sebastienrousseau/crypto-typeorm`](../crypto-typeorm) | ORM Adapter | TypeORM column-level encryption with a single decorator, powered by crypto-lib. |
130
+ | [`@sebastienrousseau/crypto-vue`](../crypto-vue) | Vue Composables | Vue 3 composables for client-side cryptography |
131
+ | [`@sebastienrousseau/crypto-wasm`](../crypto-wasm) | Acceleration | WebAssembly performance accelerator for crypto-lib |
132
+
133
+ <p align="right"><a href="#contents">Back to Top</a></p>
134
+
135
+ ---
136
+
137
+ ## Overview
138
+
139
+ crypto-api provides the shared TypeScript type definitions and
140
+ utility functions used across the Crypto Service Suite. It defines
141
+ the canonical API surface -- request headers, response types,
142
+ authorization tokens, and collection items -- that `crypto-server`,
143
+ `crypto-sdk`, and other packages depend on. Utility functions convert
144
+ Postman-style JSON collections into Markdown documentation.
145
+
146
+ <p align="right"><a href="#contents">Back to Top</a></p>
147
+
148
+ ## Features
149
+
150
+ ### Exported Types
151
+
152
+ All types are exported from `src/@types/types.ts`.
153
+
154
+ | Type | Description |
155
+ | :------------------- | :------------------------------------------------------------------------------ |
156
+ | `AuthorizationToken` | A single authorization token with `key`, `type`, and `value` fields |
157
+ | `AuthorizationInfo` | Full authorization payload including bearer tokens and metadata |
158
+ | `CollectionItem` | A Postman-style collection item -- either a folder with children or an endpoint |
159
+ | `JsonDocument` | Top-level document with `info` metadata and an array of `CollectionItem`s |
160
+ | `MethodType` | A named method with optional `request` and `response` details |
161
+ | `JsonRequest` | An API request shape with headers, key/value pair, and description |
162
+ | `RequestHeader` | A single request header with `key`, `value`, and `description` |
163
+ | `ResponseType` | A response entry with HTTP `code`, `status`, and `body` |
164
+
165
+ ### Utilities
166
+
167
+ Utility functions are exported from `src/utils/index.ts`. They
168
+ convert Postman-style JSON collections into Markdown documentation.
169
+
170
+ | Function | Description |
171
+ | :------------------ | :-------------------------------------------------- |
172
+ | `createMarkdown` | Converts a full JSON document to Markdown |
173
+ | `readAuthorization` | Renders authorization info as a Markdown table |
174
+ | `readRequest` | Renders request headers as a Markdown table |
175
+ | `readQueryParams` | Renders query parameters as a Markdown table |
176
+ | `readFormDataBody` | Renders raw or form-data request bodies in Markdown |
177
+ | `readResponse` | Renders response codes and an example response body |
178
+ | `readMethods` | Renders a single API method with all its sections |
179
+ | `readItems` | Recursively renders a collection tree to Markdown |
180
+ | `response` | Writes generated Markdown to a file on disk |
181
+
182
+ <p align="right"><a href="#contents">Back to Top</a></p>
183
+
184
+ ## Examples
185
+
186
+ All examples are self-contained TypeScript files in the `examples/`
187
+ directory. Run any example with:
188
+
189
+ ```bash
190
+ npx ts-node examples/<name>.ts
191
+ ```
192
+
193
+ | Category | Example | Purpose |
194
+ | :--------- | :-------------------------------------- | :------------------------------------- |
195
+ | Types | [types.ts](examples/types.ts) | Using API types for type-safe requests |
196
+ | Utilities | [utilities.ts](examples/utilities.ts) | Using exported utility functions |
197
+ | Validation | [validation.ts](examples/validation.ts) | Validating API payloads against types |
198
+
199
+ <p align="right"><a href="#contents">Back to Top</a></p>
200
+
201
+ <p align="right"><a href="#contents">Back to Top</a></p>
202
+
203
+ ---
204
+
205
+ ## Development
206
+
207
+ ```bash
208
+ pnpm --filter @sebastienrousseau/crypto-api run build
209
+ pnpm --filter @sebastienrousseau/crypto-api run test
210
+ pnpm --filter @sebastienrousseau/crypto-api run lint
211
+ pnpm --filter @sebastienrousseau/crypto-api run format
212
+ ```
213
+
214
+ All 18 packages in the Crypto Service workspace maintain a **100% coverage floor** across statements, branches, functions, and lines.
215
+
216
+ <p align="right"><a href="#contents">Back to Top</a></p>
217
+
218
+ ---
219
+
220
+ ## Security
221
+
222
+ Report vulnerabilities privately via [GitHub Security Advisories](https://github.com/sebastienrousseau/crypto-service/security/advisories) or according to [`SECURITY.md`](../../SECURITY.md). Never report security issues publicly.
223
+
224
+ Cryptographic operations use the `@noble/*` libraries, Node.js `crypto` and OpenPGP.js. `@noble/post-quantum` has not been independently audited and does not guarantee constant-time execution, and no module in this suite is FIPS 140-3 validated. Key zeroization is limited: JavaScript strings and garbage-collected buffers cannot be reliably wiped. See [`SECURITY.md`](../../SECURITY.md).
225
+
226
+ <p align="right"><a href="#contents">Back to Top</a></p>
227
+
228
+ ---
229
+
230
+ ## Documentation
231
+
232
+ - [Full Suite Documentation](https://sebastienrousseau.github.io/crypto-service/)
233
+ - [API Reference (TypeDoc)](https://sebastienrousseau.github.io/crypto-service/)
234
+ - [Developer Guide](../../DEVELOPMENT.md)
235
+ - [Security Policy](../../SECURITY.md)
236
+ - [Architecture & Design](../../ARCHITECTURE.md)
237
+
238
+ <p align="right"><a href="#contents">Back to Top</a></p>
239
+
240
+ ---
241
+
242
+ ## Stability guarantees
243
+
244
+ Versions advance strictly one step at a time on the `0.0.x` line (`v0.0.1` → `v0.0.2` → `v0.0.3` ... → `v0.0.999` → `v0.1.0`). Work for every release iteration begins on a dedicated `feat/v<version>` branch.
245
+
246
+ All 18 packages in the workspace move in lockstep. Public API signatures, cipher output formats, and serialization schemas are strictly versioned. Breaking changes to serialized formats or algorithm defaults are considered major breaking changes. Minimum toolchain upgrades (e.g. Node.js LTS floor) are governed by [POLICIES.md](../../docs/POLICIES.md).
247
+
248
+ <p align="right"><a href="#contents">Back to Top</a></p>
249
+
250
+ ---
251
+
252
+ ## License
253
+
254
+ Dual-licensed under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) or [MIT](https://opensource.org/licenses/MIT), at your option.
255
+
256
+ Copyright (c) 2022-2026 Sebastien Rousseau and The Crypto Service Suite contributors.
257
+
258
+ <p align="right"><a href="#contents">Back to Top</a></p>
@@ -0,0 +1,46 @@
1
+ export type AuthorizationToken = {
2
+ key: string;
3
+ type: string;
4
+ value: string;
5
+ };
6
+ export type AuthorizationInfo = {
7
+ bearer: AuthorizationToken[];
8
+ key: string;
9
+ type: string;
10
+ value: string;
11
+ };
12
+ export type CollectionItem = {
13
+ name: string;
14
+ item?: CollectionItem[];
15
+ request?: JsonRequest;
16
+ response?: ResponseType[];
17
+ };
18
+ export type JsonDocument = {
19
+ info: {
20
+ description: string;
21
+ name: string;
22
+ };
23
+ item: CollectionItem[];
24
+ };
25
+ export type MethodType = {
26
+ request?: JsonRequest;
27
+ name: string;
28
+ response?: ResponseType[];
29
+ };
30
+ export type JsonRequest = {
31
+ header: RequestHeader[];
32
+ key: string;
33
+ value: string;
34
+ description: string;
35
+ };
36
+ export type RequestHeader = {
37
+ key: string;
38
+ value: string;
39
+ description: string;
40
+ };
41
+ export type ResponseType = {
42
+ code: number;
43
+ status: string;
44
+ body: string;
45
+ };
46
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/@types/types.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,kBAAkB,GAAG;IAE/B,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IAEb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAKF,MAAM,MAAM,iBAAiB,GAAG;IAE9B,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAE7B,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IAEb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAMF,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,CAAC,EAAE,cAAc,EAAE,CAAC;IAExB,OAAO,CAAC,EAAE,WAAW,CAAC;IAEtB,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;CAC3B,CAAC;AAKF,MAAM,MAAM,YAAY,GAAG;IAEzB,IAAI,EAAE;QAEJ,WAAW,EAAE,MAAM,CAAC;QAEpB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IAEF,IAAI,EAAE,cAAc,EAAE,CAAC;CACxB,CAAC;AAKF,MAAM,MAAM,UAAU,GAAG;IAEvB,OAAO,CAAC,EAAE,WAAW,CAAC;IAEtB,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;CAC3B,CAAC;AAKF,MAAM,MAAM,WAAW,GAAG;IAExB,MAAM,EAAE,aAAa,EAAE,CAAC;IAExB,GAAG,EAAE,MAAM,CAAC;IAEZ,KAAK,EAAE,MAAM,CAAC;IAEd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAKF,MAAM,MAAM,aAAa,GAAG;IAE1B,GAAG,EAAE,MAAM,CAAC;IAEZ,KAAK,EAAE,MAAM,CAAC;IAEd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAKF,MAAM,MAAM,YAAY,GAAG;IAEzB,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,2 @@
1
+ export declare function init(): Promise<void>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAqE1C"}
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.init = init;
37
+ const minimist = require("minimist");
38
+ const fs = __importStar(require("fs/promises"));
39
+ const utils_1 = require("./utils");
40
+ async function init() {
41
+ try {
42
+ const args = minimist(process.argv.slice(2));
43
+ const [filePath, outputFileName] = args["_"];
44
+ if (!filePath) {
45
+ console.log("Path of JSON file is required.");
46
+ return;
47
+ }
48
+ console.log(`Reading file ${filePath}`);
49
+ try {
50
+ await fs.access(filePath);
51
+ }
52
+ catch {
53
+ console.log("Path is not valid or the file does not exist.");
54
+ return;
55
+ }
56
+ console.log("Generating markdown file ...");
57
+ const rawData = await fs.readFile(filePath);
58
+ const json = JSON.parse(rawData.toString());
59
+ let markdown = (0, utils_1.createMarkdown)(json);
60
+ markdown +=
61
+ "[divider]: https://raw.githubusercontent.com/sebastienrousseau/crypto-service/main/assets/divider.svg\n";
62
+ if (outputFileName) {
63
+ const fileName = outputFileName.split(".")[0];
64
+ (0, utils_1.response)(markdown, fileName);
65
+ }
66
+ else {
67
+ console.log("Output file name is required.");
68
+ }
69
+ }
70
+ catch (error) {
71
+ if (error instanceof Error) {
72
+ console.error("An error occurred:", error.message);
73
+ }
74
+ else {
75
+ console.error("An unknown error occurred:", error);
76
+ }
77
+ }
78
+ }
79
+ init();
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,52 @@
1
+ import { AuthorizationInfo, JsonDocument, JsonRequest, ResponseType } from "../@types/types";
2
+ export interface UrlWithQuery {
3
+ query?: Array<{
4
+ key: string;
5
+ value: string;
6
+ }>;
7
+ }
8
+ export interface BodyFormField {
9
+ key: string;
10
+ type: string;
11
+ src?: string;
12
+ value?: string;
13
+ }
14
+ export interface BodyShape {
15
+ mode?: string;
16
+ raw?: string;
17
+ formdata?: BodyFormField[];
18
+ }
19
+ export interface MethodLike {
20
+ name: string;
21
+ request?: JsonRequest & {
22
+ method?: string;
23
+ description?: string;
24
+ url?: UrlWithQuery | string;
25
+ body?: BodyShape;
26
+ auth?: AuthorizationInfo;
27
+ };
28
+ response?: ResponseType[];
29
+ }
30
+ export interface ItemShape {
31
+ name: string;
32
+ item?: ItemShape[];
33
+ request?: MethodLike["request"];
34
+ response?: MethodLike["response"];
35
+ }
36
+ export declare const cell: (value: unknown) => string;
37
+ export declare const createMarkdown: (data: JsonDocument) => string;
38
+ export declare const readAuthorization: (data: AuthorizationInfo | undefined) => string;
39
+ export declare const readRequest: (data: JsonRequest | undefined) => string;
40
+ export declare const readQueryParams: (url: UrlWithQuery | string | null | undefined) => string;
41
+ export declare const readFormDataBody: (body: BodyShape | null | undefined) => string;
42
+ export declare const readResponse: (responses: ResponseType[] | undefined) => string;
43
+ export declare const readMethods: (method: MethodLike) => string;
44
+ export declare const readItems: (items: ItemShape[], folderDeep?: number) => string;
45
+ export declare const docsDir: () => string;
46
+ export declare const response: (content: string, fileName: string) => Promise<void>;
47
+ declare const utils: {
48
+ createMarkdown: typeof createMarkdown;
49
+ response: typeof response;
50
+ };
51
+ export default utils;
52
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,YAAY,EACb,MAAM,iBAAiB,CAAC;AAYzB,MAAM,WAAW,YAAY;IAE3B,KAAK,CAAC,EAAE,KAAK,CAAC;QAEZ,GAAG,EAAE,MAAM,CAAC;QAEZ,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ;AAUD,MAAM,WAAW,aAAa;IAE5B,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAUD,MAAM,WAAW,SAAS;IAExB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5B;AAUD,MAAM,WAAW,UAAU;IAEzB,IAAI,EAAE,MAAM,CAAC;IAEb,OAAO,CAAC,EAAE,WAAW,GAAG;QAEtB,MAAM,CAAC,EAAE,MAAM,CAAC;QAEhB,WAAW,CAAC,EAAE,MAAM,CAAC;QAErB,GAAG,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;QAE5B,IAAI,CAAC,EAAE,SAAS,CAAC;QAEjB,IAAI,CAAC,EAAE,iBAAiB,CAAC;KAC1B,CAAC;IAEF,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;CAC3B;AAUD,MAAM,WAAW,SAAS;IAExB,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC;IAEnB,OAAO,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IAEhC,QAAQ,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CACnC;AAOD,eAAO,MAAM,IAAI,GAAI,OAAO,OAAO,KAAG,MAIZ,CAAC;AAK3B,eAAO,MAAM,cAAc,GAAI,MAAM,YAAY,KAAG,MAUnD,CAAC;AAKF,eAAO,MAAM,iBAAiB,GAC5B,MAAM,iBAAiB,GAAG,SAAS,KAClC,MAYF,CAAC;AAKF,eAAO,MAAM,WAAW,GAAI,MAAM,WAAW,GAAG,SAAS,KAAG,MAc3D,CAAC;AAKF,eAAO,MAAM,eAAe,GAC1B,KAAK,YAAY,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,KAC5C,MAYF,CAAC;AAeF,eAAO,MAAM,gBAAgB,GAC3B,MAAM,SAAS,GAAG,IAAI,GAAG,SAAS,KACjC,MAsBF,CAAC;AAKF,eAAO,MAAM,YAAY,GAAI,WAAW,YAAY,EAAE,GAAG,SAAS,KAAG,MAgBpE,CAAC;AAKF,eAAO,MAAM,WAAW,GAAI,QAAQ,UAAU,KAAG,MAkBhD,CAAC;AAKF,eAAO,MAAM,SAAS,GAAI,OAAO,SAAS,EAAE,EAAE,mBAAc,KAAG,MAY9D,CAAC;AAMF,eAAO,MAAM,OAAO,QAAO,MACiD,CAAC;AAK7E,eAAO,MAAM,QAAQ,GACnB,SAAS,MAAM,EACf,UAAU,MAAM,KACf,OAAO,CAAC,IAAI,CAMd,CAAC;AAaF,QAAA,MAAM,KAAK,EAAE;IAEX,cAAc,EAAE,OAAO,cAAc,CAAC;IAEtC,QAAQ,EAAE,OAAO,QAAQ,CAAC;CACI,CAAC;AAGjC,eAAe,KAAK,CAAC"}
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.response = exports.docsDir = exports.readItems = exports.readMethods = exports.readResponse = exports.readFormDataBody = exports.readQueryParams = exports.readRequest = exports.readAuthorization = exports.createMarkdown = exports.cell = void 0;
4
+ const promises_1 = require("fs/promises");
5
+ const path_1 = require("path");
6
+ const cell = (value) => String(value ?? "")
7
+ .replace(/\r?\n/g, " ")
8
+ .replace(/\\/g, "\\\\")
9
+ .replace(/\|/g, "\\|");
10
+ exports.cell = cell;
11
+ const createMarkdown = (data) => {
12
+ if (!data || !data.info)
13
+ return "";
14
+ const parts = [];
15
+ parts.push(`# ${data.info.name || ""}\n\n`);
16
+ if (data.info.description !== undefined) {
17
+ parts.push(`${data.info.description || ""}\n`);
18
+ }
19
+ parts.push((0, exports.readItems)((data.item || [])));
20
+ parts.push("\n");
21
+ return parts.join("");
22
+ };
23
+ exports.createMarkdown = createMarkdown;
24
+ const readAuthorization = (data) => {
25
+ if (!data || !data.bearer)
26
+ return "";
27
+ const parts = [];
28
+ parts.push(`## 🔑 Authentication ${data.type}\n\n`);
29
+ parts.push("|Param|value|Type|\n");
30
+ parts.push("|---|---|---|\n");
31
+ for (let i = 0, len = data.bearer.length; i < len; i++) {
32
+ const auth = data.bearer[i];
33
+ parts.push(`|${(0, exports.cell)(auth.key)}|${(0, exports.cell)(auth.value)}|${(0, exports.cell)(auth.type)}|\n`);
34
+ }
35
+ parts.push("\n");
36
+ return parts.join("");
37
+ };
38
+ exports.readAuthorization = readAuthorization;
39
+ const readRequest = (data) => {
40
+ if (!data || !data.header)
41
+ return "";
42
+ const parts = [];
43
+ parts.push("### Request Headers\n\n");
44
+ parts.push("|Parameter|Value|Description|\n");
45
+ parts.push("|---|---|---|\n");
46
+ for (let i = 0, len = data.header.length; i < len; i++) {
47
+ const header = data.header[i];
48
+ parts.push(`|${(0, exports.cell)(header.key)}|${(0, exports.cell)(header.value)}|${(0, exports.cell)(header.description)}|\n`);
49
+ }
50
+ parts.push("\n");
51
+ return parts.join("");
52
+ };
53
+ exports.readRequest = readRequest;
54
+ const readQueryParams = (url) => {
55
+ if (!url || typeof url === "string" || !url.query)
56
+ return "";
57
+ const parts = [];
58
+ parts.push("### Query Params\n\n");
59
+ parts.push("|Param|value|\n");
60
+ parts.push("|---|---|\n");
61
+ for (let i = 0, len = url.query.length; i < len; i++) {
62
+ const param = url.query[i];
63
+ if (param)
64
+ parts.push(`|${(0, exports.cell)(param.key)}|${(0, exports.cell)(param.value)}|\n`);
65
+ }
66
+ parts.push("\n");
67
+ return parts.join("");
68
+ };
69
+ exports.readQueryParams = readQueryParams;
70
+ function formatFieldValue(form) {
71
+ if (form.type === "file") {
72
+ return form.src ?? "";
73
+ }
74
+ return form.value !== undefined ? form.value.replace(/\\n/g, "") : "";
75
+ }
76
+ const readFormDataBody = (body) => {
77
+ if (!body)
78
+ return "";
79
+ const parts = [];
80
+ if (body.mode === "raw") {
81
+ parts.push(`### Body (**${body.mode}**)\n\n`);
82
+ parts.push("```json\n");
83
+ parts.push(`${body.raw ?? ""}\n`);
84
+ parts.push("```\n\n");
85
+ }
86
+ if (body.mode === "formdata" && body.formdata) {
87
+ parts.push(`### Body ${body.mode}\n\n`);
88
+ parts.push("|Param|value|Type|\n");
89
+ parts.push("|---|---|---|\n");
90
+ for (let i = 0, len = body.formdata.length; i < len; i++) {
91
+ const form = body.formdata[i];
92
+ parts.push(`|${(0, exports.cell)(form.key)}|${(0, exports.cell)(formatFieldValue(form))}|${(0, exports.cell)(form.type)}|\n`);
93
+ }
94
+ parts.push("\n");
95
+ }
96
+ return parts.join("");
97
+ };
98
+ exports.readFormDataBody = readFormDataBody;
99
+ const readResponse = (responses) => {
100
+ if (!responses || responses.length === 0)
101
+ return "";
102
+ const parts = [];
103
+ const first = responses[0];
104
+ parts.push("### Response\n\n");
105
+ parts.push("|Code|Status|\n");
106
+ parts.push("|---|---|\n");
107
+ for (let i = 0, len = responses.length; i < len; i++) {
108
+ const resp = responses[i];
109
+ if (resp)
110
+ parts.push(`|${(0, exports.cell)(resp.code)}|${(0, exports.cell)(resp.status)}|\n`);
111
+ }
112
+ parts.push("\n#### Example response\n\n");
113
+ parts.push("```json\n");
114
+ parts.push(`${first.body}\n`);
115
+ parts.push("```\n\n");
116
+ return parts.join("");
117
+ };
118
+ exports.readResponse = readResponse;
119
+ const readMethods = (method) => {
120
+ const parts = ["\n"];
121
+ if (method.request?.description !== undefined) {
122
+ parts.push(`#${method.request.description || ""}\n\n`);
123
+ }
124
+ parts.push(`### ${method.request?.method ?? ""} ${method.name}\n\n`);
125
+ parts.push(">```\n");
126
+ const urlString = typeof method.request?.url === "string" ? method.request.url : "";
127
+ parts.push(`>${urlString}\n`);
128
+ parts.push(">```\n\n");
129
+ parts.push((0, exports.readRequest)(method.request));
130
+ parts.push((0, exports.readFormDataBody)(method.request?.body));
131
+ parts.push((0, exports.readQueryParams)(method.request?.url));
132
+ parts.push((0, exports.readAuthorization)(method.request?.auth));
133
+ parts.push((0, exports.readResponse)(method.response));
134
+ parts.push("![divider][divider]\n");
135
+ return parts.join("");
136
+ };
137
+ exports.readMethods = readMethods;
138
+ const readItems = (items, folderDeep = 1) => {
139
+ const parts = [];
140
+ for (let i = 0, len = items.length; i < len; i++) {
141
+ const item = items[i];
142
+ if (item.item) {
143
+ parts.push(`${"#".repeat(folderDeep)} 📁 Collection: ${item.name} \n`);
144
+ parts.push((0, exports.readItems)(item.item, folderDeep + 1));
145
+ }
146
+ else {
147
+ parts.push((0, exports.readMethods)(item));
148
+ }
149
+ }
150
+ return parts.join("");
151
+ };
152
+ exports.readItems = readItems;
153
+ const docsDir = () => process.env["CRYPTO_API_DOCS_DIR"] ?? (0, path_1.resolve)(__dirname, "../../src/docs");
154
+ exports.docsDir = docsDir;
155
+ const response = async (content, fileName) => {
156
+ const dir = (0, exports.docsDir)();
157
+ await (0, promises_1.mkdir)(dir, { recursive: true });
158
+ const safeName = (0, path_1.basename)(fileName);
159
+ await (0, promises_1.writeFile)((0, path_1.join)(dir, `${safeName}.md`), content, "utf8");
160
+ };
161
+ exports.response = response;
162
+ const utils = { createMarkdown: exports.createMarkdown, response: exports.response };
163
+ exports.default = utils;
164
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,116 @@
1
+ {
2
+ "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
3
+ "autoupdate": {
4
+ "fileMap": [
5
+ {
6
+ "basePath": "dist",
7
+ "files": [
8
+ "**/*"
9
+ ]
10
+ }
11
+ ],
12
+ "source": "git",
13
+ "target": "git://github.com/sebastienrousseau/crypto-service.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/sebastienrousseau/crypto-service/issues"
17
+ },
18
+ "description": "The Crypto Service Suite APIs are typical REST APIs that use HTTPS requests and responses for common cryptographic operations.",
19
+ "dependencies": {
20
+ "minimist": "^1.2.8"
21
+ },
22
+ "devDependencies": {
23
+ "@sebastienrousseau/c8-config": "^0.0.3",
24
+ "@sebastienrousseau/eslint-config": "^0.0.2",
25
+ "@sebastienrousseau/jsdoc-config": "^0.0.5",
26
+ "@sebastienrousseau/markdownlint-config": "^0.0.1",
27
+ "@sebastienrousseau/mocha-config": "^0.0.5",
28
+ "@sebastienrousseau/prettier-config": "^0.0.4",
29
+ "@sebastienrousseau/remark-config": "^0.0.3",
30
+ "@types/chai": "^4.3.7",
31
+ "@types/chai-as-promised": "^8.0.2",
32
+ "@types/mocha": "^10.0.2",
33
+ "@types/node": "^26.4.1",
34
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
35
+ "@typescript-eslint/parser": "^6.21.0",
36
+ "c8": "^12.0.0",
37
+ "chai": "^4.5.0",
38
+ "chai-as-promised": "^7.1.2",
39
+ "eslint": "^8.57.1",
40
+ "eslint-import-resolver-typescript": "^3.10.1",
41
+ "eslint-plugin-import": "^2.28.1",
42
+ "filesizes": "^0.1.2",
43
+ "mocha": "^10.8.2",
44
+ "prettier": "^3.9.8",
45
+ "remark-cli": "^12.0.0",
46
+ "remark-footnotes": "^5.0.0",
47
+ "remark-preset-lint-consistent": "^6.0.1",
48
+ "remark-preset-lint-markdown-style-guide": "^5.1.3",
49
+ "remark-preset-lint-recommended": "^7.0.1",
50
+ "rimraf": "^6.1.3",
51
+ "ts-node": "^10.9.1",
52
+ "typedoc": "^0.28.20",
53
+ "typedoc-plugin-missing-exports": "^4.1.4",
54
+ "typescript": "~5.9.3"
55
+ },
56
+ "directories": {
57
+ "src": "./src",
58
+ "test": "__tests__"
59
+ },
60
+ "engines": {
61
+ "node": ">=22.0.0"
62
+ },
63
+ "files": [
64
+ "dist/**/*.js",
65
+ "dist/**/*.d.ts",
66
+ "dist/**/*.d.ts.map"
67
+ ],
68
+ "funding": [
69
+ {
70
+ "type": "github",
71
+ "url": "https://github.com/sponsors/sebastienrousseau"
72
+ },
73
+ {
74
+ "type": "paypal",
75
+ "url": "https://paypal.me/wwdseb"
76
+ }
77
+ ],
78
+ "homepage": "https://crypto-api.io",
79
+ "keywords": [
80
+ "crypto-api"
81
+ ],
82
+ "license": "MIT OR Apache-2.0",
83
+ "license_URI": "http://www.opensource.org/licenses/mit-license.php",
84
+ "main": "./dist/index.js",
85
+ "exports": {
86
+ ".": {
87
+ "types": "./dist/index.d.ts",
88
+ "require": "./dist/index.js",
89
+ "import": "./dist/index.js"
90
+ }
91
+ },
92
+ "name": "@sebastienrousseau/crypto-api",
93
+ "private": false,
94
+ "publishConfig": {
95
+ "access": "public"
96
+ },
97
+ "repository": {
98
+ "directory": "packages/crypto-api",
99
+ "type": "git",
100
+ "url": "git@github.com:sebastienrousseau/crypto-service.git"
101
+ },
102
+ "types": "./dist/index.d.ts",
103
+ "sideEffects": false,
104
+ "version": "0.0.7",
105
+ "scripts": {
106
+ "build": "tsc --build tsconfig.json",
107
+ "clean": "rimraf ./coverage ./dist ./docs",
108
+ "format": "prettier --write src/**/*.ts",
109
+ "format:check": "prettier --check \"src/**/*.ts\"",
110
+ "lint": "eslint --ext .ts src __tests__",
111
+ "lint:fix": "eslint --cache --fix --ext .ts src __tests__",
112
+ "start": "node dist/index.js",
113
+ "test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --reporter=lcov --reporter=text mocha --config=.mocharc.cjs",
114
+ "docs": "typedoc"
115
+ }
116
+ }