@crowdnode/sdk 1.0.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/Readme ADDED
@@ -0,0 +1,44 @@
1
+ # Crowdnode SDK
2
+
3
+ The **Crowdnode SDK** is the central "Contract" and communication layer between our **Backend** and our **Frontend**.
4
+
5
+ Instead of the Frontend and Backend "guessing" what the data looks like, this SDK acts as the single source of truth. It ensures security, privacy, and full type safety across the entire project.
6
+
7
+ ---
8
+
9
+ ## 1. The Three Pillars of Data
10
+ We organize our data into three specific layers to ensure that sensitive database information never accidentally "leaks" to the user's phone.
11
+
12
+ | Layer | Type Name | Where it lives | Purpose |
13
+ | :--- | :--- | :--- | :--- |
14
+ | **Storage** | `[Name]Storage` | Backend | The raw "ugly" data. Includes private IDs, internal flags, and sensitive dates. |
15
+ | **Logic** | `[Name]Logic` | Backend/SDK | The "Brain." This version includes calculated fields (e.g., `isFundingActive`) and business rules used by the services. |
16
+ | **UI** | `[Name]UI` | Frontend/SDK | The "Pretty" version. Sanitized and safe. This is the only version the Expo app is allowed to see. |
17
+ | **Input** | `[Name]Input` | Shared | The "Form." Defines exactly what a user is allowed to send to the API when creating or updating something. |
18
+
19
+ ---
20
+
21
+ ## 2. How It Works (The Data Flow)
22
+
23
+ The SDK facilitates a strict 3-step communication process:
24
+
25
+ 1. **Definition:** We define the `Storage`, `Logic`, and `UI` types inside this SDK.
26
+ 2. **Conversion (Backend):** The NestJS backend fetches a Storage object from the database. Before sending it back, it uses a *Converter* function to transform it into a UI object, stripping away any private data.
27
+ 3. **Consumption (Frontend):** The frontend uses the `CrowdnodeClient` provided by this SDK. It automatically receives the UI type, providing full autocomplete and preventing crashes.
28
+
29
+
30
+
31
+ ---
32
+
33
+ ## 3. Repository Structure
34
+
35
+ ```text
36
+ src/
37
+ ├── resources/
38
+ │ ├── startups/ # Everything related to Startup data
39
+ │ │ ├── startup.types.ts # Storage, Logic, UI, and Input interfaces
40
+ │ │ └── startup.client.ts # The SDK functions for the Frontend
41
+ │ └── campaigns/ # Everything related to Fundraising campaigns
42
+ ├── transport/
43
+ │ └── http-client.ts # Base configuration (Axios/Auth headers)
44
+ └── index.ts # Main entry point for the package
@@ -0,0 +1,12 @@
1
+ import { StartupClient } from './resources/startups/startup.client';
2
+ export * from './resources/startups/startup.types';
3
+ interface SDKConfig {
4
+ baseUrl: string;
5
+ getToken?: () => string | null;
6
+ }
7
+ export declare class CrowdnodeSDK {
8
+ startups: StartupClient;
9
+ private http;
10
+ constructor(config: SDKConfig);
11
+ }
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAGpE,cAAc,oCAAoC,CAAC;AAGnD,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,qBAAa,YAAY;IAChB,QAAQ,EAAE,aAAa,CAAC;IAC/B,OAAO,CAAC,IAAI,CAAa;gBAEb,MAAM,EAAE,SAAS;CAO9B"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.CrowdnodeSDK = void 0;
18
+ const http_client_1 = require("./transport/http-client");
19
+ const startup_client_1 = require("./resources/startups/startup.client");
20
+ // 1. Export all the types so the Frontend/Backend can use them
21
+ __exportStar(require("./resources/startups/startup.types"), exports);
22
+ class CrowdnodeSDK {
23
+ constructor(config) {
24
+ // Initialize the Engine
25
+ this.http = new http_client_1.HttpClient(config.baseUrl, config.getToken);
26
+ // Initialize the Resource Clients
27
+ this.startups = new startup_client_1.StartupClient(this.http);
28
+ }
29
+ }
30
+ exports.CrowdnodeSDK = CrowdnodeSDK;
@@ -0,0 +1,9 @@
1
+ import { HttpClient } from '../../transport/http-client';
2
+ import { StartupUI, StartupInput } from './startup.types';
3
+ export declare class StartupClient {
4
+ private api;
5
+ constructor(api: HttpClient);
6
+ getStartup(id: string): Promise<StartupUI>;
7
+ create(data: StartupInput): Promise<StartupUI>;
8
+ }
9
+ //# sourceMappingURL=startup.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"startup.client.d.ts","sourceRoot":"","sources":["../../../src/resources/startups/startup.client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE1D,qBAAa,aAAa;IACZ,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,UAAU;IAG7B,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAK1C,MAAM,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC;CAIrD"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StartupClient = void 0;
4
+ class StartupClient {
5
+ constructor(api) {
6
+ this.api = api;
7
+ }
8
+ // The Promise returns the "UI" type, not the "Storage" type
9
+ async getStartup(id) {
10
+ const response = await this.api.get(`/startups/${id}`);
11
+ return response;
12
+ }
13
+ async create(data) {
14
+ const response = await this.api.post('/startups', data);
15
+ return response;
16
+ }
17
+ }
18
+ exports.StartupClient = StartupClient;
@@ -0,0 +1,32 @@
1
+ /**
2
+ */
3
+ export interface StartupStorage {
4
+ id: number;
5
+ legal_name: string;
6
+ owner_id: string;
7
+ vault_address: string;
8
+ created_at: Date;
9
+ }
10
+ /**
11
+ */
12
+ export interface StartupLogic {
13
+ id: string;
14
+ name: string;
15
+ ownerId: string;
16
+ blockchainReady: boolean;
17
+ }
18
+ /**
19
+ */
20
+ export interface StartupUI {
21
+ id: string;
22
+ name: string;
23
+ isVerified: boolean;
24
+ avatarUrl: string;
25
+ }
26
+ /**
27
+ */
28
+ export interface StartupInput {
29
+ name: string;
30
+ description: string;
31
+ }
32
+ //# sourceMappingURL=startup.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"startup.types.d.ts","sourceRoot":"","sources":["../../../src/resources/startups/startup.types.ts"],"names":[],"mappings":"AAAA;GACG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,IAAI,CAAC;CAClB;AAED;GACG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;GACG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;GACG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ export declare class HttpClient {
3
+ private instance;
4
+ constructor(baseUrl: string, getToken?: () => string | null);
5
+ get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
6
+ post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
7
+ }
8
+ //# sourceMappingURL=http-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/transport/http-client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEjE,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAgB;gBAEpB,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI;IAmBrD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;IAK5D,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC;CAIhF"}
@@ -0,0 +1,35 @@
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.HttpClient = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class HttpClient {
9
+ constructor(baseUrl, getToken) {
10
+ this.instance = axios_1.default.create({
11
+ baseURL: baseUrl,
12
+ headers: { 'Content-Type': 'application/json' },
13
+ });
14
+ // Automatically attach Auth Token if available (for Expo/Mobile)
15
+ if (getToken) {
16
+ this.instance.interceptors.request.use((config) => {
17
+ const token = getToken();
18
+ if (token) {
19
+ config.headers.Authorization = `Bearer ${token}`;
20
+ }
21
+ return config;
22
+ });
23
+ }
24
+ }
25
+ // Generic methods that the Resource Clients will use
26
+ async get(url, config) {
27
+ const response = await this.instance.get(url, config);
28
+ return response.data;
29
+ }
30
+ async post(url, data, config) {
31
+ const response = await this.instance.post(url, data, config);
32
+ return response.data;
33
+ }
34
+ }
35
+ exports.HttpClient = HttpClient;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@crowdnode/sdk",
3
+ "version": "1.0.0",
4
+ "description": "The **Crowdnode SDK** is the central \"Contract\" and communication layer between our **Backend** and our **Frontend**.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepare": "npm run build"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/crowdnode-it/crowdnode-sdk.git"
17
+ },
18
+ "author": "",
19
+ "license": "ISC",
20
+ "bugs": {
21
+ "url": "https://github.com/crowdnode-it/crowdnode-sdk/issues"
22
+ },
23
+ "homepage": "https://github.com/crowdnode-it/crowdnode-sdk#readme",
24
+ "dependencies": {
25
+ "axios": "^1.16.0"
26
+ }
27
+ }