@x12i/helpers 1.0.1 → 1.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 +81 -0
- package/dist/access-definition/index.d.ts +3 -0
- package/dist/access-definition/index.d.ts.map +1 -0
- package/dist/access-definition/index.js +19 -0
- package/dist/access-definition/index.js.map +1 -0
- package/dist/access-definition/integration/integrationDefinition.d.ts +2 -0
- package/dist/access-definition/integration/integrationDefinition.d.ts.map +1 -0
- package/dist/access-definition/integration/integrationDefinition.js +3 -0
- package/dist/access-definition/integration/integrationDefinition.js.map +1 -0
- package/dist/access-definition/types.d.ts +43 -0
- package/dist/access-definition/types.d.ts.map +1 -0
- package/dist/access-definition/types.js +3 -0
- package/dist/access-definition/types.js.map +1 -0
- package/index.js +3 -0
- package/package.json +23 -2
- package/src/access-definition/index.ts +3 -0
- package/src/access-definition/integration/integrationDefinition.ts +2 -0
- package/src/access-definition/types.ts +104 -0
- package/src/helpers/api-contracts.js +398 -0
- package/src/helpers/apiMapper.js +459 -0
- package/src/helpers/firebaseRtdb.js +471 -0
- package/src/helpers/json-mapper.js +3 -0
package/README.md
CHANGED
|
@@ -72,6 +72,80 @@ Direct import:
|
|
|
72
72
|
const { requestToCurl } = require("@x12i/helpers/http-tools");
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
### API contracts + protocol bridge
|
|
76
|
+
|
|
77
|
+
Define protocol-aware API contracts (REST/GraphQL/JSON-RPC/SOAP/custom) with optional request/response validation and auth application.
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
const { defineContract, createRegistry } = require("@x12i/helpers/api-contracts");
|
|
81
|
+
const { createBridge } = require("@x12i/helpers/api-mapper");
|
|
82
|
+
|
|
83
|
+
const registry = createRegistry();
|
|
84
|
+
|
|
85
|
+
registry.register({
|
|
86
|
+
name: "restGetUser",
|
|
87
|
+
protocol: "rest",
|
|
88
|
+
endpoint: "/api/users/{id}",
|
|
89
|
+
method: "GET",
|
|
90
|
+
auth: { type: "bearer" },
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
registry.register({
|
|
94
|
+
name: "gqlGetUser",
|
|
95
|
+
protocol: "graphql",
|
|
96
|
+
endpoint: "https://api.example.com/graphql",
|
|
97
|
+
query: "query GetUser($userId: ID!) { user(id: $userId) { id fullName } }",
|
|
98
|
+
auth: { type: "bearer" },
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const bridge = createBridge({
|
|
102
|
+
source: "restGetUser",
|
|
103
|
+
target: "gqlGetUser",
|
|
104
|
+
registry,
|
|
105
|
+
requestMapping: [{ from: "pathParams.id", to: "variables.userId" }],
|
|
106
|
+
responseMapping: ["user.id", "user.fullName -> user.name"],
|
|
107
|
+
credentials: { target: { token: "TOKEN" } },
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// bridge.call({ pathParams: { id: "42" } })
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Direct imports:
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
const { createBridge, batchCall, chainBridges } = require("@x12i/helpers/api-mapper");
|
|
117
|
+
const { defineContract, createRegistry } = require("@x12i/helpers/api-contracts");
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Firebase Realtime Database (native) — mongo-like helper
|
|
121
|
+
|
|
122
|
+
This helper uses the Firebase Admin SDK and wraps RTDB with a familiar Mongo-ish API (`findOne`, `insertOne`, `updateOne`, etc.).
|
|
123
|
+
|
|
124
|
+
1) Create `.env` (see `.env.example`) and put credentials in `.secrets/firebase-service-account.json`.
|
|
125
|
+
|
|
126
|
+
2) Use it:
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
const { initFirebaseRtdb } = require("@x12i/helpers/firebase-rtdb");
|
|
130
|
+
|
|
131
|
+
const fb = initFirebaseRtdb(); // loads .env by default
|
|
132
|
+
const users = fb.collection("users");
|
|
133
|
+
|
|
134
|
+
const { insertedId } = await users.insertOne({ email: "a@b.com", name: "Ami" });
|
|
135
|
+
const user = await users.findOne({ _id: insertedId });
|
|
136
|
+
|
|
137
|
+
await users.updateOne({ _id: insertedId }, { $set: { name: "Ami N." }, $inc: { loginCount: 1 } });
|
|
138
|
+
await users.deleteOne({ _id: insertedId });
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
If you want native RTDB query features (server-side indexed filtering), use `query()`:
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
const result = await users
|
|
145
|
+
.query({ orderByChild: "email", equalTo: "a@b.com", limitToFirst: 10 })
|
|
146
|
+
.find();
|
|
147
|
+
```
|
|
148
|
+
|
|
75
149
|
## API
|
|
76
150
|
|
|
77
151
|
- `mapObject(source, mapping, opts)`
|
|
@@ -83,4 +157,11 @@ const { requestToCurl } = require("@x12i/helpers/http-tools");
|
|
|
83
157
|
- `curlToRequest(curlCommand)`
|
|
84
158
|
- `buildUrl(baseUrl, pathOrUrl, query)`
|
|
85
159
|
- `createBaseUrlClient(baseUrl, defaults)`
|
|
160
|
+
- `defineContract(config)`
|
|
161
|
+
- `createRegistry()`
|
|
162
|
+
- `createBridge(config)`
|
|
163
|
+
- `batchCall(bridge, paramsList, opts)`
|
|
164
|
+
- `chainBridges(...bridges)`
|
|
165
|
+
- `initFirebaseRtdb(options)`
|
|
166
|
+
- `getFirebaseRtdb()`
|
|
86
167
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/access-definition/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,wCAAwC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
__exportStar(require("./types.js"), exports);
|
|
18
|
+
__exportStar(require("./integration/integrationDefinition.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/access-definition/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,yEAAuD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integrationDefinition.d.ts","sourceRoot":"","sources":["../../../src/access-definition/integration/integrationDefinition.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integrationDefinition.js","sourceRoot":"","sources":["../../../src/access-definition/integration/integrationDefinition.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type AccessLevel = 'public' | 'static-secret' | 'runtime-token' | 'delegated-consent' | 'signed-request' | 'transport-bound' | 'composite';
|
|
2
|
+
export type StorageMode = 'mode-1' | 'mode-2' | 'mode-3';
|
|
3
|
+
export type CredentialKind = 'none' | 'api-key' | 'basic-auth' | 'bearer-token' | 'oauth-access-token' | 'refresh-token' | 'consent-token' | 'session-token' | 'custom-header-secret' | 'hmac-key' | 'jwt-assertion-key' | 'client-certificate';
|
|
4
|
+
export type AcquisitionType = 'preset' | 'client-credentials' | 'authorization-code' | 'refresh-token' | 'token-exchange' | 'login-session' | 'device-code' | 'signed-jwt' | 'manual';
|
|
5
|
+
export type InjectionType = 'header' | 'query' | 'basic-authorization' | 'bearer-authorization' | 'form-body' | 'transport' | 'signature';
|
|
6
|
+
export type PersistenceClass = 'none' | 'ephemeral-memory' | 'local-encrypted' | 'firebase-atm' | 'external-atm';
|
|
7
|
+
export type SecretMaterialClass = 'preset-secret' | 'bootstrap-secret' | 'runtime-token' | 'refresh-material' | 'consent-material' | 'signing-material' | 'transport-identity';
|
|
8
|
+
export type SubjectBinding = 'none' | 'tenant' | 'user' | 'custom';
|
|
9
|
+
export type AccessLeafDefinition = {
|
|
10
|
+
accessLevel: Exclude<AccessLevel, 'composite'>;
|
|
11
|
+
credentialKinds?: CredentialKind[];
|
|
12
|
+
acquisitionType?: AcquisitionType;
|
|
13
|
+
injectionTypes?: InjectionType[];
|
|
14
|
+
persistenceClass?: PersistenceClass;
|
|
15
|
+
refreshSupported?: boolean;
|
|
16
|
+
consentRequired?: boolean;
|
|
17
|
+
signingRequired?: boolean;
|
|
18
|
+
transportRequired?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* References to preset/bootstrap secrets needed to operate this integration.
|
|
21
|
+
* Examples: `secret.hubspot.clientSecret`, `secret.aws.signingKey`.
|
|
22
|
+
*/
|
|
23
|
+
secretRefs?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* References to runtime material produced/consumed by this integration.
|
|
26
|
+
* Examples: `material.hubspot.refresh-token.default`.
|
|
27
|
+
*/
|
|
28
|
+
tokenRefs?: string[];
|
|
29
|
+
};
|
|
30
|
+
export type AccessCompositeDefinition = {
|
|
31
|
+
accessLevel: 'composite';
|
|
32
|
+
layers: AccessDefinition[];
|
|
33
|
+
};
|
|
34
|
+
export type AccessDefinition = AccessLeafDefinition | AccessCompositeDefinition;
|
|
35
|
+
export type IntegrationDefinition = {
|
|
36
|
+
integrationId: string;
|
|
37
|
+
access: AccessDefinition;
|
|
38
|
+
defaults?: {
|
|
39
|
+
subjectBinding?: SubjectBinding;
|
|
40
|
+
storageMode?: StorageMode;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/access-definition/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,gBAAgB,GAChB,iBAAiB,GACjB,WAAW,CAAC;AAEhB,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEzD,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,SAAS,GACT,YAAY,GACZ,cAAc,GACd,oBAAoB,GACpB,eAAe,GACf,eAAe,GACf,eAAe,GACf,sBAAsB,GACtB,UAAU,GACV,mBAAmB,GACnB,oBAAoB,CAAC;AAEzB,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,oBAAoB,GACpB,oBAAoB,GACpB,eAAe,GACf,gBAAgB,GAChB,eAAe,GACf,aAAa,GACb,YAAY,GACZ,QAAQ,CAAC;AAEb,MAAM,MAAM,aAAa,GACrB,QAAQ,GACR,OAAO,GACP,qBAAqB,GACrB,sBAAsB,GACtB,WAAW,GACX,WAAW,GACX,WAAW,CAAC;AAEhB,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,kBAAkB,GAClB,iBAAiB,GACjB,cAAc,GACd,cAAc,CAAC;AAEnB,MAAM,MAAM,mBAAmB,GAC3B,eAAe,GACf,kBAAkB,GAClB,eAAe,GACf,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,oBAAoB,CAAC;AAEzB,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEnE,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAC/C,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IACnC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG,yBAAyB,CAAC;AAEhF,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,CAAC,EAAE;QACT,cAAc,CAAC,EAAE,cAAc,CAAC;QAChC,WAAW,CAAC,EAAE,WAAW,CAAC;KAC3B,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/access-definition/types.ts"],"names":[],"mappings":""}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x12i/helpers",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Small helper utilities for x12i projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "x12i",
|
|
@@ -21,15 +21,36 @@
|
|
|
21
21
|
"exports": {
|
|
22
22
|
".": "./index.js",
|
|
23
23
|
"./objects-mapper": "./src/helpers/objectsMapper.js",
|
|
24
|
-
"./http-tools": "./src/helpers/httpTools.js"
|
|
24
|
+
"./http-tools": "./src/helpers/httpTools.js",
|
|
25
|
+
"./api-mapper": "./src/helpers/apiMapper.js",
|
|
26
|
+
"./api-contracts": "./src/helpers/api-contracts.js",
|
|
27
|
+
"./firebase-rtdb": "./src/helpers/firebaseRtdb.js",
|
|
28
|
+
"./access-definition": {
|
|
29
|
+
"types": "./dist/access-definition/index.d.ts",
|
|
30
|
+
"require": "./dist/access-definition/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./access-definition/*": {
|
|
33
|
+
"types": "./dist/access-definition/*.d.ts",
|
|
34
|
+
"require": "./dist/access-definition/*.js"
|
|
35
|
+
}
|
|
25
36
|
},
|
|
26
37
|
"files": [
|
|
27
38
|
"index.js",
|
|
39
|
+
"dist/",
|
|
28
40
|
"src/",
|
|
29
41
|
"README.md",
|
|
30
42
|
"LICENSE"
|
|
31
43
|
],
|
|
32
44
|
"scripts": {
|
|
45
|
+
"build": "npx tsc -p tsconfig.json",
|
|
46
|
+
"prepublishOnly": "npm run build",
|
|
33
47
|
"test": "node --test"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"firebase-admin": "^13.5.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^24.0.0",
|
|
54
|
+
"typescript": "^5.9.0"
|
|
34
55
|
}
|
|
35
56
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export type AccessLevel =
|
|
2
|
+
| 'public'
|
|
3
|
+
| 'static-secret'
|
|
4
|
+
| 'runtime-token'
|
|
5
|
+
| 'delegated-consent'
|
|
6
|
+
| 'signed-request'
|
|
7
|
+
| 'transport-bound'
|
|
8
|
+
| 'composite';
|
|
9
|
+
|
|
10
|
+
export type StorageMode = 'mode-1' | 'mode-2' | 'mode-3';
|
|
11
|
+
|
|
12
|
+
export type CredentialKind =
|
|
13
|
+
| 'none'
|
|
14
|
+
| 'api-key'
|
|
15
|
+
| 'basic-auth'
|
|
16
|
+
| 'bearer-token'
|
|
17
|
+
| 'oauth-access-token'
|
|
18
|
+
| 'refresh-token'
|
|
19
|
+
| 'consent-token'
|
|
20
|
+
| 'session-token'
|
|
21
|
+
| 'custom-header-secret'
|
|
22
|
+
| 'hmac-key'
|
|
23
|
+
| 'jwt-assertion-key'
|
|
24
|
+
| 'client-certificate';
|
|
25
|
+
|
|
26
|
+
export type AcquisitionType =
|
|
27
|
+
| 'preset'
|
|
28
|
+
| 'client-credentials'
|
|
29
|
+
| 'authorization-code'
|
|
30
|
+
| 'refresh-token'
|
|
31
|
+
| 'token-exchange'
|
|
32
|
+
| 'login-session'
|
|
33
|
+
| 'device-code'
|
|
34
|
+
| 'signed-jwt'
|
|
35
|
+
| 'manual';
|
|
36
|
+
|
|
37
|
+
export type InjectionType =
|
|
38
|
+
| 'header'
|
|
39
|
+
| 'query'
|
|
40
|
+
| 'basic-authorization'
|
|
41
|
+
| 'bearer-authorization'
|
|
42
|
+
| 'form-body'
|
|
43
|
+
| 'transport'
|
|
44
|
+
| 'signature';
|
|
45
|
+
|
|
46
|
+
export type PersistenceClass =
|
|
47
|
+
| 'none'
|
|
48
|
+
| 'ephemeral-memory'
|
|
49
|
+
| 'local-encrypted'
|
|
50
|
+
| 'firebase-atm'
|
|
51
|
+
| 'external-atm';
|
|
52
|
+
|
|
53
|
+
export type SecretMaterialClass =
|
|
54
|
+
| 'preset-secret'
|
|
55
|
+
| 'bootstrap-secret'
|
|
56
|
+
| 'runtime-token'
|
|
57
|
+
| 'refresh-material'
|
|
58
|
+
| 'consent-material'
|
|
59
|
+
| 'signing-material'
|
|
60
|
+
| 'transport-identity';
|
|
61
|
+
|
|
62
|
+
export type SubjectBinding = 'none' | 'tenant' | 'user' | 'custom';
|
|
63
|
+
|
|
64
|
+
export type AccessLeafDefinition = {
|
|
65
|
+
accessLevel: Exclude<AccessLevel, 'composite'>;
|
|
66
|
+
credentialKinds?: CredentialKind[];
|
|
67
|
+
acquisitionType?: AcquisitionType;
|
|
68
|
+
injectionTypes?: InjectionType[];
|
|
69
|
+
persistenceClass?: PersistenceClass;
|
|
70
|
+
|
|
71
|
+
refreshSupported?: boolean;
|
|
72
|
+
consentRequired?: boolean;
|
|
73
|
+
signingRequired?: boolean;
|
|
74
|
+
transportRequired?: boolean;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* References to preset/bootstrap secrets needed to operate this integration.
|
|
78
|
+
* Examples: `secret.hubspot.clientSecret`, `secret.aws.signingKey`.
|
|
79
|
+
*/
|
|
80
|
+
secretRefs?: string[];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* References to runtime material produced/consumed by this integration.
|
|
84
|
+
* Examples: `material.hubspot.refresh-token.default`.
|
|
85
|
+
*/
|
|
86
|
+
tokenRefs?: string[];
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type AccessCompositeDefinition = {
|
|
90
|
+
accessLevel: 'composite';
|
|
91
|
+
layers: AccessDefinition[];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type AccessDefinition = AccessLeafDefinition | AccessCompositeDefinition;
|
|
95
|
+
|
|
96
|
+
export type IntegrationDefinition = {
|
|
97
|
+
integrationId: string;
|
|
98
|
+
access: AccessDefinition;
|
|
99
|
+
defaults?: {
|
|
100
|
+
subjectBinding?: SubjectBinding;
|
|
101
|
+
storageMode?: StorageMode;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|