@space-ai/contracts 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.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # @space-ai/contracts
2
+
3
+ npm-пакет с типами и функциями HTTP-запросов к API. Axios не входит в бандл — передаётся при инициализации (`peerDependency`).
4
+
5
+ ## Структура
6
+
7
+ ```
8
+ src/ — исходники (типы, api, core)
9
+ dist/ — сборка для npm (генерируется, в git не коммитится)
10
+ ```
11
+
12
+ ## Локальная разработка
13
+
14
+ ```bash
15
+ npm install
16
+ npm run build
17
+ ```
18
+
19
+ ## Использование
20
+
21
+ ```typescript
22
+ import axios from 'axios';
23
+ import { initApiClient, getUser } from '@space-ai/contracts';
24
+
25
+ const api = axios.create({ baseURL: '/api' });
26
+ initApiClient(api);
27
+
28
+ const user = await getUser(1);
29
+ ```
30
+
31
+ ## Публикация в npm
32
+
33
+ 1. Создайте организацию/scope на [npmjs.com](https://www.npmjs.com/) (например `@space-ai`).
34
+ 2. Сгенерируйте **Automation token** (не publish token с 2FA-проблемами): npm → Access Tokens → Granular Access Token → Read and write, scope — ваш пакет/org.
35
+ 3. В GitHub: **Settings → Secrets and variables → Actions → New repository secret** → имя `NPM_TOKEN`, значение — токен.
36
+ 4. Обновите в `package.json`: `name`, `repository.url` (пакет публикуется как **public** scoped).
37
+ 5. Локально поднимите версию и запушьте тег:
38
+
39
+ ```bash
40
+ npm version patch # или minor / major
41
+ git push origin main --tags
42
+ ```
43
+
44
+ CI workflow `.github/workflows/publish.yml` соберёт пакет и выполнит `npm publish` при пуше тега `v*.*.*`.
45
+
46
+ ## GitHub
47
+
48
+ | Что | Зачем |
49
+ |-----|-------|
50
+ | Secret `NPM_TOKEN` | авторизация `npm publish` в Actions |
51
+ | Workflow `ci.yml` | проверка сборки на PR и push в main |
52
+ | Workflow `publish.yml` | публикация по git-тегу |
53
+ | (опционально) Branch protection | merge только после зелёного CI |
54
+
55
+ Первый релиз: после настройки секрета выполните `npm version 0.1.0 && git push origin main --tags`.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ export declare function getAxios(): AxiosInstance;
3
+ export declare function setAxios(axios: AxiosInstance): void;
4
+ export declare function resetAxios(): void;
5
+ //# sourceMappingURL=axios-instance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios-instance.d.ts","sourceRoot":"","sources":["../../src/core/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAI3C,wBAAgB,QAAQ,IAAI,aAAa,CAWxC;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAEnD;AAED,wBAAgB,UAAU,IAAI,IAAI,CAEjC"}
@@ -0,0 +1,17 @@
1
+ let instance = null;
2
+ export function getAxios() {
3
+ if (instance)
4
+ return instance;
5
+ if (typeof window !== 'undefined' && window.axios) {
6
+ instance = window.axios;
7
+ return instance;
8
+ }
9
+ throw new Error('Axios не найден. Вызовите initApiClient(axios) или установите window.axios');
10
+ }
11
+ export function setAxios(axios) {
12
+ instance = axios;
13
+ }
14
+ export function resetAxios() {
15
+ instance = null;
16
+ }
17
+ //# sourceMappingURL=axios-instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios-instance.js","sourceRoot":"","sources":["../../src/core/axios-instance.ts"],"names":[],"mappings":"AAEA,IAAI,QAAQ,GAAyB,IAAI,CAAC;AAE1C,MAAM,UAAU,QAAQ;IACtB,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAE9B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAClD,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC;QACxB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAoB;IAC3C,QAAQ,GAAG,KAAK,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,QAAQ,GAAG,IAAI,CAAC;AAClB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ export declare function initApiClient(axios?: AxiosInstance): void;
3
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/core/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,IAAI,CAYzD"}
@@ -0,0 +1,13 @@
1
+ import { setAxios } from './axios-instance.js';
2
+ export function initApiClient(axios) {
3
+ if (axios) {
4
+ setAxios(axios);
5
+ return;
6
+ }
7
+ if (typeof window !== 'undefined' && window.axios) {
8
+ setAxios(window.axios);
9
+ return;
10
+ }
11
+ throw new Error('Не передан axios и нет window.axios');
12
+ }
13
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/core/init.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,UAAU,aAAa,CAAC,KAAqB;IACjD,IAAI,KAAK,EAAE,CAAC;QACV,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChB,OAAO;IACT,CAAC;IAED,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAClD,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { initApiClient } from './core/init.js';
2
+ export { getAxios, resetAxios } from './core/axios-instance.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { initApiClient } from './core/init.js';
2
+ export { getAxios, resetAxios } from './core/axios-instance.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@space-ai/contracts",
3
+ "version": "0.1.0",
4
+ "description": "Типы и функции HTTP-запросов к API (axios — peer dependency)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "prepublishOnly": "npm run build",
20
+ "typecheck": "tsc --noEmit"
21
+ },
22
+ "peerDependencies": {
23
+ "axios": "^1.0.0"
24
+ },
25
+ "devDependencies": {
26
+ "axios": "^1.7.0",
27
+ "typescript": "^5.7.0"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/YOUR_ORG/contracts.git"
35
+ },
36
+ "license": "UNLICENSED"
37
+ }