@lark-apaas/miaoda-connections-sdk 0.1.1-alpha.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/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.cjs +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.mjs +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.cjs +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.mjs +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateParam.cjs +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateParam.mjs +8 -0
- package/dist/client.cjs +64 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.mjs +64 -0
- package/dist/client.mjs.map +1 -0
- package/dist/create-client.cjs +9 -0
- package/dist/create-client.cjs.map +1 -0
- package/dist/create-client.d.cts +7 -0
- package/dist/create-client.d.cts.map +1 -0
- package/dist/create-client.d.mts +7 -0
- package/dist/create-client.d.mts.map +1 -0
- package/dist/create-client.mjs +9 -0
- package/dist/create-client.mjs.map +1 -0
- package/dist/envelope.cjs +52 -0
- package/dist/envelope.cjs.map +1 -0
- package/dist/envelope.mjs +51 -0
- package/dist/envelope.mjs.map +1 -0
- package/dist/errors.cjs +19 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +19 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +19 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +19 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +13 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +4 -0
- package/dist/nestjs.cjs +43 -0
- package/dist/nestjs.cjs.map +1 -0
- package/dist/nestjs.d.cts +11 -0
- package/dist/nestjs.d.cts.map +1 -0
- package/dist/nestjs.d.mts +11 -0
- package/dist/nestjs.d.mts.map +1 -0
- package/dist/nestjs.mjs +37 -0
- package/dist/nestjs.mjs.map +1 -0
- package/dist/platform-http-client.cjs +38 -0
- package/dist/platform-http-client.cjs.map +1 -0
- package/dist/platform-http-client.mjs +38 -0
- package/dist/platform-http-client.mjs.map +1 -0
- package/dist/redaction.cjs +35 -0
- package/dist/redaction.cjs.map +1 -0
- package/dist/redaction.mjs +34 -0
- package/dist/redaction.mjs.map +1 -0
- package/dist/types.d.cts +80 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +80 -0
- package/dist/types.d.mts.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
|
|
2
|
+
function __decorate(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.__decorate = __decorate;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorate.js
|
|
2
|
+
function __decorate(decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { __decorate };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.115.0/helpers/decorateMetadata.js
|
|
2
|
+
function __decorateMetadata(k, v) {
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
exports.__decorateMetadata = __decorateMetadata;
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const require_errors = require("./errors.cjs");
|
|
2
|
+
const require_envelope = require("./envelope.cjs");
|
|
3
|
+
const require_redaction = require("./redaction.cjs");
|
|
4
|
+
//#region src/client.ts
|
|
5
|
+
var ConnectionsClientImpl = class {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
async getConnection(input) {
|
|
10
|
+
const connectionName = typeof input === "string" ? input : input.connectionName;
|
|
11
|
+
return this.fetchConnection(connectionName);
|
|
12
|
+
}
|
|
13
|
+
async fetchConnection(name) {
|
|
14
|
+
const normalizedName = normalizeConnectionName(name);
|
|
15
|
+
const path = `/innerapi/v1/integration/credentials/${encodeURIComponent(normalizedName)}`;
|
|
16
|
+
try {
|
|
17
|
+
this.logDebug("connections.getConnection.request", {
|
|
18
|
+
method: "GET",
|
|
19
|
+
path: path.replace(encodeURIComponent(normalizedName), require_redaction.redactConnectionName(normalizedName))
|
|
20
|
+
});
|
|
21
|
+
const envelope = await this.options.transport.request({
|
|
22
|
+
method: "GET",
|
|
23
|
+
path,
|
|
24
|
+
timeoutMs: this.options.timeoutMs
|
|
25
|
+
});
|
|
26
|
+
const result = require_envelope.unwrapEnvelope(envelope);
|
|
27
|
+
require_envelope.assertConnectionResult(result);
|
|
28
|
+
this.logDebug("connections.getConnection.response", {
|
|
29
|
+
method: "GET",
|
|
30
|
+
status_code: envelope.status_code,
|
|
31
|
+
state: result.state,
|
|
32
|
+
connectionType: result.state === "connected" ? result.value.type : void 0
|
|
33
|
+
});
|
|
34
|
+
return result;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error instanceof require_errors.ConnectionsSDKError) throw error;
|
|
37
|
+
throw new require_errors.ConnectionsSDKError({
|
|
38
|
+
code: error instanceof DOMException && error.name === "TimeoutError" ? "TIMEOUT" : "REQUEST_FAILED",
|
|
39
|
+
message: "Connection request failed",
|
|
40
|
+
cause: require_redaction.sanitizeCause(error)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
logDebug(message, meta) {
|
|
45
|
+
if (!this.options.debug) return;
|
|
46
|
+
this.options.logger?.debug(message, meta);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function normalizeConnectionName(name) {
|
|
50
|
+
if (typeof name !== "string") throw new require_errors.ConnectionsSDKError({
|
|
51
|
+
code: "INVALID_CONNECTION_NAME",
|
|
52
|
+
message: "Connection name must be a string"
|
|
53
|
+
});
|
|
54
|
+
const normalizedName = name.trim();
|
|
55
|
+
if (!normalizedName) throw new require_errors.ConnectionsSDKError({
|
|
56
|
+
code: "INVALID_CONNECTION_NAME",
|
|
57
|
+
message: "Connection name must not be empty"
|
|
58
|
+
});
|
|
59
|
+
return normalizedName;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.ConnectionsClientImpl = ConnectionsClientImpl;
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.cjs","names":["redactConnectionName","unwrapEnvelope","ConnectionsSDKError","sanitizeCause"],"sources":["../src/client.ts"],"sourcesContent":["import { assertConnectionResult, unwrapEnvelope } from './envelope';\nimport { ConnectionsSDKError } from './errors';\nimport { redactConnectionName, sanitizeCause } from './redaction';\nimport type {\n ApiEnvelope,\n ConnectionResult,\n ConnectionsClient,\n CreateConnectionsClientOptions,\n GetConnectionOptions,\n} from './types';\n\nexport class ConnectionsClientImpl implements ConnectionsClient {\n constructor(\n private readonly options: Required<\n Pick<CreateConnectionsClientOptions, 'transport'>\n > &\n Omit<CreateConnectionsClientOptions, 'transport'>\n ) {}\n\n async getConnection(name: string): Promise<ConnectionResult>;\n async getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;\n async getConnection(\n input: string | GetConnectionOptions\n ): Promise<ConnectionResult> {\n const connectionName =\n typeof input === 'string' ? input : input.connectionName;\n return this.fetchConnection(connectionName);\n }\n\n private async fetchConnection(name: string): Promise<ConnectionResult> {\n const normalizedName = normalizeConnectionName(name);\n const path = `/innerapi/v1/integration/credentials/${encodeURIComponent(normalizedName)}`;\n\n try {\n this.logDebug('connections.getConnection.request', {\n method: 'GET',\n path: path.replace(\n encodeURIComponent(normalizedName),\n redactConnectionName(normalizedName)\n ),\n });\n\n const envelope = await this.options.transport.request<\n ApiEnvelope<ConnectionResult>\n >({\n method: 'GET',\n path,\n timeoutMs: this.options.timeoutMs,\n });\n const result = unwrapEnvelope(envelope);\n assertConnectionResult(result);\n\n this.logDebug('connections.getConnection.response', {\n method: 'GET',\n status_code: envelope.status_code,\n state: result.state,\n connectionType:\n result.state === 'connected' ? result.value.type : undefined,\n });\n\n return result;\n } catch (error) {\n if (error instanceof ConnectionsSDKError) throw error;\n throw new ConnectionsSDKError({\n code:\n error instanceof DOMException && error.name === 'TimeoutError'\n ? 'TIMEOUT'\n : 'REQUEST_FAILED',\n message: 'Connection request failed',\n cause: sanitizeCause(error),\n });\n }\n }\n\n private logDebug(message: string, meta: Record<string, unknown>): void {\n if (!this.options.debug) return;\n this.options.logger?.debug(message, meta);\n }\n}\n\nexport function normalizeConnectionName(name: string): string {\n if (typeof name !== 'string') {\n throw new ConnectionsSDKError({\n code: 'INVALID_CONNECTION_NAME',\n message: 'Connection name must be a string',\n });\n }\n\n const normalizedName = name.trim();\n if (!normalizedName) {\n throw new ConnectionsSDKError({\n code: 'INVALID_CONNECTION_NAME',\n message: 'Connection name must not be empty',\n });\n }\n\n return normalizedName;\n}\n"],"mappings":";;;;AAWA,IAAa,wBAAb,MAAgE;CAC9D,YACE,SAIA;AAJiB,OAAA,UAAA;;CAQnB,MAAM,cACJ,OAC2B;EAC3B,MAAM,iBACJ,OAAO,UAAU,WAAW,QAAQ,MAAM;AAC5C,SAAO,KAAK,gBAAgB,eAAe;;CAG7C,MAAc,gBAAgB,MAAyC;EACrE,MAAM,iBAAiB,wBAAwB,KAAK;EACpD,MAAM,OAAO,wCAAwC,mBAAmB,eAAe;AAEvF,MAAI;AACF,QAAK,SAAS,qCAAqC;IACjD,QAAQ;IACR,MAAM,KAAK,QACT,mBAAmB,eAAe,EAClCA,kBAAAA,qBAAqB,eAAe,CACrC;IACF,CAAC;GAEF,MAAM,WAAW,MAAM,KAAK,QAAQ,UAAU,QAE5C;IACA,QAAQ;IACR;IACA,WAAW,KAAK,QAAQ;IACzB,CAAC;GACF,MAAM,SAASC,iBAAAA,eAAe,SAAS;AACvC,oBAAA,uBAAuB,OAAO;AAE9B,QAAK,SAAS,sCAAsC;IAClD,QAAQ;IACR,aAAa,SAAS;IACtB,OAAO,OAAO;IACd,gBACE,OAAO,UAAU,cAAc,OAAO,MAAM,OAAO,KAAA;IACtD,CAAC;AAEF,UAAO;WACA,OAAO;AACd,OAAI,iBAAiBC,eAAAA,oBAAqB,OAAM;AAChD,SAAM,IAAIA,eAAAA,oBAAoB;IAC5B,MACE,iBAAiB,gBAAgB,MAAM,SAAS,iBAC5C,YACA;IACN,SAAS;IACT,OAAOC,kBAAAA,cAAc,MAAM;IAC5B,CAAC;;;CAIN,SAAiB,SAAiB,MAAqC;AACrE,MAAI,CAAC,KAAK,QAAQ,MAAO;AACzB,OAAK,QAAQ,QAAQ,MAAM,SAAS,KAAK;;;AAI7C,SAAgB,wBAAwB,MAAsB;AAC5D,KAAI,OAAO,SAAS,SAClB,OAAM,IAAID,eAAAA,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC;CAGJ,MAAM,iBAAiB,KAAK,MAAM;AAClC,KAAI,CAAC,eACH,OAAM,IAAIA,eAAAA,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC;AAGJ,QAAO"}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ConnectionsSDKError } from "./errors.mjs";
|
|
2
|
+
import { assertConnectionResult, unwrapEnvelope } from "./envelope.mjs";
|
|
3
|
+
import { redactConnectionName, sanitizeCause } from "./redaction.mjs";
|
|
4
|
+
//#region src/client.ts
|
|
5
|
+
var ConnectionsClientImpl = class {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
async getConnection(input) {
|
|
10
|
+
const connectionName = typeof input === "string" ? input : input.connectionName;
|
|
11
|
+
return this.fetchConnection(connectionName);
|
|
12
|
+
}
|
|
13
|
+
async fetchConnection(name) {
|
|
14
|
+
const normalizedName = normalizeConnectionName(name);
|
|
15
|
+
const path = `/innerapi/v1/integration/credentials/${encodeURIComponent(normalizedName)}`;
|
|
16
|
+
try {
|
|
17
|
+
this.logDebug("connections.getConnection.request", {
|
|
18
|
+
method: "GET",
|
|
19
|
+
path: path.replace(encodeURIComponent(normalizedName), redactConnectionName(normalizedName))
|
|
20
|
+
});
|
|
21
|
+
const envelope = await this.options.transport.request({
|
|
22
|
+
method: "GET",
|
|
23
|
+
path,
|
|
24
|
+
timeoutMs: this.options.timeoutMs
|
|
25
|
+
});
|
|
26
|
+
const result = unwrapEnvelope(envelope);
|
|
27
|
+
assertConnectionResult(result);
|
|
28
|
+
this.logDebug("connections.getConnection.response", {
|
|
29
|
+
method: "GET",
|
|
30
|
+
status_code: envelope.status_code,
|
|
31
|
+
state: result.state,
|
|
32
|
+
connectionType: result.state === "connected" ? result.value.type : void 0
|
|
33
|
+
});
|
|
34
|
+
return result;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error instanceof ConnectionsSDKError) throw error;
|
|
37
|
+
throw new ConnectionsSDKError({
|
|
38
|
+
code: error instanceof DOMException && error.name === "TimeoutError" ? "TIMEOUT" : "REQUEST_FAILED",
|
|
39
|
+
message: "Connection request failed",
|
|
40
|
+
cause: sanitizeCause(error)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
logDebug(message, meta) {
|
|
45
|
+
if (!this.options.debug) return;
|
|
46
|
+
this.options.logger?.debug(message, meta);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function normalizeConnectionName(name) {
|
|
50
|
+
if (typeof name !== "string") throw new ConnectionsSDKError({
|
|
51
|
+
code: "INVALID_CONNECTION_NAME",
|
|
52
|
+
message: "Connection name must be a string"
|
|
53
|
+
});
|
|
54
|
+
const normalizedName = name.trim();
|
|
55
|
+
if (!normalizedName) throw new ConnectionsSDKError({
|
|
56
|
+
code: "INVALID_CONNECTION_NAME",
|
|
57
|
+
message: "Connection name must not be empty"
|
|
58
|
+
});
|
|
59
|
+
return normalizedName;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { ConnectionsClientImpl };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import { assertConnectionResult, unwrapEnvelope } from './envelope';\nimport { ConnectionsSDKError } from './errors';\nimport { redactConnectionName, sanitizeCause } from './redaction';\nimport type {\n ApiEnvelope,\n ConnectionResult,\n ConnectionsClient,\n CreateConnectionsClientOptions,\n GetConnectionOptions,\n} from './types';\n\nexport class ConnectionsClientImpl implements ConnectionsClient {\n constructor(\n private readonly options: Required<\n Pick<CreateConnectionsClientOptions, 'transport'>\n > &\n Omit<CreateConnectionsClientOptions, 'transport'>\n ) {}\n\n async getConnection(name: string): Promise<ConnectionResult>;\n async getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;\n async getConnection(\n input: string | GetConnectionOptions\n ): Promise<ConnectionResult> {\n const connectionName =\n typeof input === 'string' ? input : input.connectionName;\n return this.fetchConnection(connectionName);\n }\n\n private async fetchConnection(name: string): Promise<ConnectionResult> {\n const normalizedName = normalizeConnectionName(name);\n const path = `/innerapi/v1/integration/credentials/${encodeURIComponent(normalizedName)}`;\n\n try {\n this.logDebug('connections.getConnection.request', {\n method: 'GET',\n path: path.replace(\n encodeURIComponent(normalizedName),\n redactConnectionName(normalizedName)\n ),\n });\n\n const envelope = await this.options.transport.request<\n ApiEnvelope<ConnectionResult>\n >({\n method: 'GET',\n path,\n timeoutMs: this.options.timeoutMs,\n });\n const result = unwrapEnvelope(envelope);\n assertConnectionResult(result);\n\n this.logDebug('connections.getConnection.response', {\n method: 'GET',\n status_code: envelope.status_code,\n state: result.state,\n connectionType:\n result.state === 'connected' ? result.value.type : undefined,\n });\n\n return result;\n } catch (error) {\n if (error instanceof ConnectionsSDKError) throw error;\n throw new ConnectionsSDKError({\n code:\n error instanceof DOMException && error.name === 'TimeoutError'\n ? 'TIMEOUT'\n : 'REQUEST_FAILED',\n message: 'Connection request failed',\n cause: sanitizeCause(error),\n });\n }\n }\n\n private logDebug(message: string, meta: Record<string, unknown>): void {\n if (!this.options.debug) return;\n this.options.logger?.debug(message, meta);\n }\n}\n\nexport function normalizeConnectionName(name: string): string {\n if (typeof name !== 'string') {\n throw new ConnectionsSDKError({\n code: 'INVALID_CONNECTION_NAME',\n message: 'Connection name must be a string',\n });\n }\n\n const normalizedName = name.trim();\n if (!normalizedName) {\n throw new ConnectionsSDKError({\n code: 'INVALID_CONNECTION_NAME',\n message: 'Connection name must not be empty',\n });\n }\n\n return normalizedName;\n}\n"],"mappings":";;;;AAWA,IAAa,wBAAb,MAAgE;CAC9D,YACE,SAIA;AAJiB,OAAA,UAAA;;CAQnB,MAAM,cACJ,OAC2B;EAC3B,MAAM,iBACJ,OAAO,UAAU,WAAW,QAAQ,MAAM;AAC5C,SAAO,KAAK,gBAAgB,eAAe;;CAG7C,MAAc,gBAAgB,MAAyC;EACrE,MAAM,iBAAiB,wBAAwB,KAAK;EACpD,MAAM,OAAO,wCAAwC,mBAAmB,eAAe;AAEvF,MAAI;AACF,QAAK,SAAS,qCAAqC;IACjD,QAAQ;IACR,MAAM,KAAK,QACT,mBAAmB,eAAe,EAClC,qBAAqB,eAAe,CACrC;IACF,CAAC;GAEF,MAAM,WAAW,MAAM,KAAK,QAAQ,UAAU,QAE5C;IACA,QAAQ;IACR;IACA,WAAW,KAAK,QAAQ;IACzB,CAAC;GACF,MAAM,SAAS,eAAe,SAAS;AACvC,0BAAuB,OAAO;AAE9B,QAAK,SAAS,sCAAsC;IAClD,QAAQ;IACR,aAAa,SAAS;IACtB,OAAO,OAAO;IACd,gBACE,OAAO,UAAU,cAAc,OAAO,MAAM,OAAO,KAAA;IACtD,CAAC;AAEF,UAAO;WACA,OAAO;AACd,OAAI,iBAAiB,oBAAqB,OAAM;AAChD,SAAM,IAAI,oBAAoB;IAC5B,MACE,iBAAiB,gBAAgB,MAAM,SAAS,iBAC5C,YACA;IACN,SAAS;IACT,OAAO,cAAc,MAAM;IAC5B,CAAC;;;CAIN,SAAiB,SAAiB,MAAqC;AACrE,MAAI,CAAC,KAAK,QAAQ,MAAO;AACzB,OAAK,QAAQ,QAAQ,MAAM,SAAS,KAAK;;;AAI7C,SAAgB,wBAAwB,MAAsB;AAC5D,KAAI,OAAO,SAAS,SAClB,OAAM,IAAI,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC;CAGJ,MAAM,iBAAiB,KAAK,MAAM;AAClC,KAAI,CAAC,eACH,OAAM,IAAI,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC;AAGJ,QAAO"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const require_client = require("./client.cjs");
|
|
2
|
+
//#region src/create-client.ts
|
|
3
|
+
function createConnectionsClient(options) {
|
|
4
|
+
return new require_client.ConnectionsClientImpl({ ...options });
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.createConnectionsClient = createConnectionsClient;
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=create-client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-client.cjs","names":["ConnectionsClientImpl"],"sources":["../src/create-client.ts"],"sourcesContent":["import { ConnectionsClientImpl } from './client';\nimport type {\n ConnectionsClient,\n CreateConnectionsClientOptions,\n} from './types';\n\nexport function createConnectionsClient(\n options: CreateConnectionsClientOptions\n): ConnectionsClient {\n return new ConnectionsClientImpl({\n ...options,\n });\n}\n"],"mappings":";;AAMA,SAAgB,wBACd,SACmB;AACnB,QAAO,IAAIA,eAAAA,sBAAsB,EAC/B,GAAG,SACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConnectionsClient, CreateConnectionsClientOptions } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/create-client.d.ts
|
|
4
|
+
declare function createConnectionsClient(options: CreateConnectionsClientOptions): ConnectionsClient;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createConnectionsClient };
|
|
7
|
+
//# sourceMappingURL=create-client.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-client.d.cts","names":[],"sources":["../src/create-client.ts"],"mappings":";;;iBAMgB,uBAAA,CACd,OAAA,EAAS,8BAAA,GACR,iBAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConnectionsClient, CreateConnectionsClientOptions } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/create-client.d.ts
|
|
4
|
+
declare function createConnectionsClient(options: CreateConnectionsClientOptions): ConnectionsClient;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createConnectionsClient };
|
|
7
|
+
//# sourceMappingURL=create-client.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-client.d.mts","names":[],"sources":["../src/create-client.ts"],"mappings":";;;iBAMgB,uBAAA,CACd,OAAA,EAAS,8BAAA,GACR,iBAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConnectionsClientImpl } from "./client.mjs";
|
|
2
|
+
//#region src/create-client.ts
|
|
3
|
+
function createConnectionsClient(options) {
|
|
4
|
+
return new ConnectionsClientImpl({ ...options });
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createConnectionsClient };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=create-client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-client.mjs","names":[],"sources":["../src/create-client.ts"],"sourcesContent":["import { ConnectionsClientImpl } from './client';\nimport type {\n ConnectionsClient,\n CreateConnectionsClientOptions,\n} from './types';\n\nexport function createConnectionsClient(\n options: CreateConnectionsClientOptions\n): ConnectionsClient {\n return new ConnectionsClientImpl({\n ...options,\n });\n}\n"],"mappings":";;AAMA,SAAgB,wBACd,SACmB;AACnB,QAAO,IAAI,sBAAsB,EAC/B,GAAG,SACJ,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const require_errors = require("./errors.cjs");
|
|
2
|
+
//#region src/envelope.ts
|
|
3
|
+
const CONNECTION_TYPES = new Set([
|
|
4
|
+
"oauth2",
|
|
5
|
+
"api_key",
|
|
6
|
+
"basic",
|
|
7
|
+
"rdb",
|
|
8
|
+
"custom"
|
|
9
|
+
]);
|
|
10
|
+
function unwrapEnvelope(envelope) {
|
|
11
|
+
const statusCode = envelope.status_code;
|
|
12
|
+
if (typeof statusCode !== "string") throw new require_errors.ConnectionsSDKError({
|
|
13
|
+
code: "INVALID_RESPONSE",
|
|
14
|
+
message: "Invalid connection response: missing status_code"
|
|
15
|
+
});
|
|
16
|
+
if (statusCode !== "0") throw new require_errors.ConnectionsSDKError({
|
|
17
|
+
code: "BUSINESS_ERROR",
|
|
18
|
+
message: envelope.error_msg || `Connection service returned ${statusCode}`
|
|
19
|
+
});
|
|
20
|
+
if (envelope.data === void 0 || envelope.data === null) throw new require_errors.ConnectionsSDKError({
|
|
21
|
+
code: "MISSING_DATA",
|
|
22
|
+
message: "Invalid connection response: missing data"
|
|
23
|
+
});
|
|
24
|
+
return envelope.data;
|
|
25
|
+
}
|
|
26
|
+
function assertConnectionResult(value) {
|
|
27
|
+
if (typeof value !== "object" || value === null) throwInvalidConnectionResult();
|
|
28
|
+
const result = value;
|
|
29
|
+
if (result.state === "connected") {
|
|
30
|
+
const connected = result;
|
|
31
|
+
const connectionValue = connected.value;
|
|
32
|
+
if (typeof connected.issuedAt !== "string" || typeof connected.issuanceId !== "string" || typeof connectionValue?.type !== "string" || !CONNECTION_TYPES.has(connectionValue.type)) throwInvalidConnectionResult();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (result.state === "not_connected") {
|
|
36
|
+
const notConnected = result;
|
|
37
|
+
if (typeof notConnected.reason !== "string" || typeof notConnected.recoveryHint !== "string") throwInvalidConnectionResult();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
throwInvalidConnectionResult();
|
|
41
|
+
}
|
|
42
|
+
function throwInvalidConnectionResult() {
|
|
43
|
+
throw new require_errors.ConnectionsSDKError({
|
|
44
|
+
code: "INVALID_RESPONSE",
|
|
45
|
+
message: "Invalid connection response: unexpected data shape"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.assertConnectionResult = assertConnectionResult;
|
|
50
|
+
exports.unwrapEnvelope = unwrapEnvelope;
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=envelope.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.cjs","names":["ConnectionsSDKError"],"sources":["../src/envelope.ts"],"sourcesContent":["import { ConnectionsSDKError } from './errors';\nimport type { ApiEnvelope, ConnectionResult } from './types';\n\nconst CONNECTION_TYPES = new Set([\n 'oauth2',\n 'api_key',\n 'basic',\n 'rdb',\n 'custom',\n]);\n\nexport function unwrapEnvelope<T>(envelope: ApiEnvelope<T>): T {\n const statusCode = envelope.status_code;\n\n if (typeof statusCode !== 'string') {\n throw new ConnectionsSDKError({\n code: 'INVALID_RESPONSE',\n message: 'Invalid connection response: missing status_code',\n });\n }\n\n if (statusCode !== '0') {\n throw new ConnectionsSDKError({\n code: 'BUSINESS_ERROR',\n message:\n envelope.error_msg || `Connection service returned ${statusCode}`,\n });\n }\n\n if (envelope.data === undefined || envelope.data === null) {\n throw new ConnectionsSDKError({\n code: 'MISSING_DATA',\n message: 'Invalid connection response: missing data',\n });\n }\n\n return envelope.data;\n}\n\nexport function assertConnectionResult(\n value: unknown\n): asserts value is ConnectionResult {\n if (typeof value !== 'object' || value === null) {\n throwInvalidConnectionResult();\n }\n\n const result = value as Partial<ConnectionResult>;\n if (result.state === 'connected') {\n const connected = result as Partial<\n Extract<ConnectionResult, { state: 'connected' }>\n >;\n const connectionValue = connected.value as { type?: unknown } | undefined;\n if (\n typeof connected.issuedAt !== 'string' ||\n typeof connected.issuanceId !== 'string' ||\n typeof connectionValue?.type !== 'string' ||\n !CONNECTION_TYPES.has(connectionValue.type)\n ) {\n throwInvalidConnectionResult();\n }\n return;\n }\n\n if (result.state === 'not_connected') {\n const notConnected = result as Partial<\n Extract<ConnectionResult, { state: 'not_connected' }>\n >;\n if (\n typeof notConnected.reason !== 'string' ||\n typeof notConnected.recoveryHint !== 'string'\n ) {\n throwInvalidConnectionResult();\n }\n return;\n }\n\n throwInvalidConnectionResult();\n}\n\nfunction throwInvalidConnectionResult(): never {\n throw new ConnectionsSDKError({\n code: 'INVALID_RESPONSE',\n message: 'Invalid connection response: unexpected data shape',\n });\n}\n"],"mappings":";;AAGA,MAAM,mBAAmB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,eAAkB,UAA6B;CAC7D,MAAM,aAAa,SAAS;AAE5B,KAAI,OAAO,eAAe,SACxB,OAAM,IAAIA,eAAAA,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC;AAGJ,KAAI,eAAe,IACjB,OAAM,IAAIA,eAAAA,oBAAoB;EAC5B,MAAM;EACN,SACE,SAAS,aAAa,+BAA+B;EACxD,CAAC;AAGJ,KAAI,SAAS,SAAS,KAAA,KAAa,SAAS,SAAS,KACnD,OAAM,IAAIA,eAAAA,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC;AAGJ,QAAO,SAAS;;AAGlB,SAAgB,uBACd,OACmC;AACnC,KAAI,OAAO,UAAU,YAAY,UAAU,KACzC,+BAA8B;CAGhC,MAAM,SAAS;AACf,KAAI,OAAO,UAAU,aAAa;EAChC,MAAM,YAAY;EAGlB,MAAM,kBAAkB,UAAU;AAClC,MACE,OAAO,UAAU,aAAa,YAC9B,OAAO,UAAU,eAAe,YAChC,OAAO,iBAAiB,SAAS,YACjC,CAAC,iBAAiB,IAAI,gBAAgB,KAAK,CAE3C,+BAA8B;AAEhC;;AAGF,KAAI,OAAO,UAAU,iBAAiB;EACpC,MAAM,eAAe;AAGrB,MACE,OAAO,aAAa,WAAW,YAC/B,OAAO,aAAa,iBAAiB,SAErC,+BAA8B;AAEhC;;AAGF,+BAA8B;;AAGhC,SAAS,+BAAsC;AAC7C,OAAM,IAAIA,eAAAA,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ConnectionsSDKError } from "./errors.mjs";
|
|
2
|
+
//#region src/envelope.ts
|
|
3
|
+
const CONNECTION_TYPES = new Set([
|
|
4
|
+
"oauth2",
|
|
5
|
+
"api_key",
|
|
6
|
+
"basic",
|
|
7
|
+
"rdb",
|
|
8
|
+
"custom"
|
|
9
|
+
]);
|
|
10
|
+
function unwrapEnvelope(envelope) {
|
|
11
|
+
const statusCode = envelope.status_code;
|
|
12
|
+
if (typeof statusCode !== "string") throw new ConnectionsSDKError({
|
|
13
|
+
code: "INVALID_RESPONSE",
|
|
14
|
+
message: "Invalid connection response: missing status_code"
|
|
15
|
+
});
|
|
16
|
+
if (statusCode !== "0") throw new ConnectionsSDKError({
|
|
17
|
+
code: "BUSINESS_ERROR",
|
|
18
|
+
message: envelope.error_msg || `Connection service returned ${statusCode}`
|
|
19
|
+
});
|
|
20
|
+
if (envelope.data === void 0 || envelope.data === null) throw new ConnectionsSDKError({
|
|
21
|
+
code: "MISSING_DATA",
|
|
22
|
+
message: "Invalid connection response: missing data"
|
|
23
|
+
});
|
|
24
|
+
return envelope.data;
|
|
25
|
+
}
|
|
26
|
+
function assertConnectionResult(value) {
|
|
27
|
+
if (typeof value !== "object" || value === null) throwInvalidConnectionResult();
|
|
28
|
+
const result = value;
|
|
29
|
+
if (result.state === "connected") {
|
|
30
|
+
const connected = result;
|
|
31
|
+
const connectionValue = connected.value;
|
|
32
|
+
if (typeof connected.issuedAt !== "string" || typeof connected.issuanceId !== "string" || typeof connectionValue?.type !== "string" || !CONNECTION_TYPES.has(connectionValue.type)) throwInvalidConnectionResult();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (result.state === "not_connected") {
|
|
36
|
+
const notConnected = result;
|
|
37
|
+
if (typeof notConnected.reason !== "string" || typeof notConnected.recoveryHint !== "string") throwInvalidConnectionResult();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
throwInvalidConnectionResult();
|
|
41
|
+
}
|
|
42
|
+
function throwInvalidConnectionResult() {
|
|
43
|
+
throw new ConnectionsSDKError({
|
|
44
|
+
code: "INVALID_RESPONSE",
|
|
45
|
+
message: "Invalid connection response: unexpected data shape"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { assertConnectionResult, unwrapEnvelope };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=envelope.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.mjs","names":[],"sources":["../src/envelope.ts"],"sourcesContent":["import { ConnectionsSDKError } from './errors';\nimport type { ApiEnvelope, ConnectionResult } from './types';\n\nconst CONNECTION_TYPES = new Set([\n 'oauth2',\n 'api_key',\n 'basic',\n 'rdb',\n 'custom',\n]);\n\nexport function unwrapEnvelope<T>(envelope: ApiEnvelope<T>): T {\n const statusCode = envelope.status_code;\n\n if (typeof statusCode !== 'string') {\n throw new ConnectionsSDKError({\n code: 'INVALID_RESPONSE',\n message: 'Invalid connection response: missing status_code',\n });\n }\n\n if (statusCode !== '0') {\n throw new ConnectionsSDKError({\n code: 'BUSINESS_ERROR',\n message:\n envelope.error_msg || `Connection service returned ${statusCode}`,\n });\n }\n\n if (envelope.data === undefined || envelope.data === null) {\n throw new ConnectionsSDKError({\n code: 'MISSING_DATA',\n message: 'Invalid connection response: missing data',\n });\n }\n\n return envelope.data;\n}\n\nexport function assertConnectionResult(\n value: unknown\n): asserts value is ConnectionResult {\n if (typeof value !== 'object' || value === null) {\n throwInvalidConnectionResult();\n }\n\n const result = value as Partial<ConnectionResult>;\n if (result.state === 'connected') {\n const connected = result as Partial<\n Extract<ConnectionResult, { state: 'connected' }>\n >;\n const connectionValue = connected.value as { type?: unknown } | undefined;\n if (\n typeof connected.issuedAt !== 'string' ||\n typeof connected.issuanceId !== 'string' ||\n typeof connectionValue?.type !== 'string' ||\n !CONNECTION_TYPES.has(connectionValue.type)\n ) {\n throwInvalidConnectionResult();\n }\n return;\n }\n\n if (result.state === 'not_connected') {\n const notConnected = result as Partial<\n Extract<ConnectionResult, { state: 'not_connected' }>\n >;\n if (\n typeof notConnected.reason !== 'string' ||\n typeof notConnected.recoveryHint !== 'string'\n ) {\n throwInvalidConnectionResult();\n }\n return;\n }\n\n throwInvalidConnectionResult();\n}\n\nfunction throwInvalidConnectionResult(): never {\n throw new ConnectionsSDKError({\n code: 'INVALID_RESPONSE',\n message: 'Invalid connection response: unexpected data shape',\n });\n}\n"],"mappings":";;AAGA,MAAM,mBAAmB,IAAI,IAAI;CAC/B;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,eAAkB,UAA6B;CAC7D,MAAM,aAAa,SAAS;AAE5B,KAAI,OAAO,eAAe,SACxB,OAAM,IAAI,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC;AAGJ,KAAI,eAAe,IACjB,OAAM,IAAI,oBAAoB;EAC5B,MAAM;EACN,SACE,SAAS,aAAa,+BAA+B;EACxD,CAAC;AAGJ,KAAI,SAAS,SAAS,KAAA,KAAa,SAAS,SAAS,KACnD,OAAM,IAAI,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC;AAGJ,QAAO,SAAS;;AAGlB,SAAgB,uBACd,OACmC;AACnC,KAAI,OAAO,UAAU,YAAY,UAAU,KACzC,+BAA8B;CAGhC,MAAM,SAAS;AACf,KAAI,OAAO,UAAU,aAAa;EAChC,MAAM,YAAY;EAGlB,MAAM,kBAAkB,UAAU;AAClC,MACE,OAAO,UAAU,aAAa,YAC9B,OAAO,UAAU,eAAe,YAChC,OAAO,iBAAiB,SAAS,YACjC,CAAC,iBAAiB,IAAI,gBAAgB,KAAK,CAE3C,+BAA8B;AAEhC;;AAGF,KAAI,OAAO,UAAU,iBAAiB;EACpC,MAAM,eAAe;AAGrB,MACE,OAAO,aAAa,WAAW,YAC/B,OAAO,aAAa,iBAAiB,SAErC,+BAA8B;AAEhC;;AAGF,+BAA8B;;AAGhC,SAAS,+BAAsC;AAC7C,OAAM,IAAI,oBAAoB;EAC5B,MAAM;EACN,SAAS;EACV,CAAC"}
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
var ConnectionsSDKError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
statusCode;
|
|
5
|
+
requestId;
|
|
6
|
+
cause;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options.message);
|
|
9
|
+
this.name = "ConnectionsSDKError";
|
|
10
|
+
this.code = options.code;
|
|
11
|
+
this.statusCode = options.statusCode;
|
|
12
|
+
this.requestId = options.requestId;
|
|
13
|
+
this.cause = options.cause;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.ConnectionsSDKError = ConnectionsSDKError;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export type ConnectionsSDKErrorCode =\n | 'INVALID_CONNECTION_NAME'\n | 'BUSINESS_ERROR'\n | 'REQUEST_FAILED'\n | 'TIMEOUT'\n | 'MISSING_DATA'\n | 'INVALID_RESPONSE';\n\nexport interface ConnectionsSDKErrorOptions {\n code: ConnectionsSDKErrorCode;\n message: string;\n statusCode?: number;\n requestId?: string;\n cause?: unknown;\n}\n\nexport class ConnectionsSDKError extends Error {\n readonly code: ConnectionsSDKErrorCode;\n readonly statusCode?: number;\n readonly requestId?: string;\n override readonly cause?: unknown;\n\n constructor(options: ConnectionsSDKErrorOptions) {\n super(options.message);\n this.name = 'ConnectionsSDKError';\n this.code = options.code;\n this.statusCode = options.statusCode;\n this.requestId = options.requestId;\n this.cause = options.cause;\n }\n}\n"],"mappings":";AAgBA,IAAa,sBAAb,cAAyC,MAAM;CAC7C;CACA;CACA;CACA;CAEA,YAAY,SAAqC;AAC/C,QAAM,QAAQ,QAAQ;AACtB,OAAK,OAAO;AACZ,OAAK,OAAO,QAAQ;AACpB,OAAK,aAAa,QAAQ;AAC1B,OAAK,YAAY,QAAQ;AACzB,OAAK,QAAQ,QAAQ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/errors.d.ts
|
|
2
|
+
type ConnectionsSDKErrorCode = 'INVALID_CONNECTION_NAME' | 'BUSINESS_ERROR' | 'REQUEST_FAILED' | 'TIMEOUT' | 'MISSING_DATA' | 'INVALID_RESPONSE';
|
|
3
|
+
interface ConnectionsSDKErrorOptions {
|
|
4
|
+
code: ConnectionsSDKErrorCode;
|
|
5
|
+
message: string;
|
|
6
|
+
statusCode?: number;
|
|
7
|
+
requestId?: string;
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
}
|
|
10
|
+
declare class ConnectionsSDKError extends Error {
|
|
11
|
+
readonly code: ConnectionsSDKErrorCode;
|
|
12
|
+
readonly statusCode?: number;
|
|
13
|
+
readonly requestId?: string;
|
|
14
|
+
readonly cause?: unknown;
|
|
15
|
+
constructor(options: ConnectionsSDKErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ConnectionsSDKError, ConnectionsSDKErrorCode, ConnectionsSDKErrorOptions };
|
|
19
|
+
//# sourceMappingURL=errors.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":[],"sources":["../src/errors.ts"],"mappings":";KAAY,uBAAA;AAAA,UAQK,0BAAA;EACf,IAAA,EAAM,uBAAA;EACN,OAAA;EACA,UAAA;EACA,SAAA;EACA,KAAA;AAAA;AAAA,cAGW,mBAAA,SAA4B,KAAA;EAAA,SAC9B,IAAA,EAAM,uBAAA;EAAA,SACN,UAAA;EAAA,SACA,SAAA;EAAA,SACS,KAAA;cAEN,OAAA,EAAS,0BAAA;AAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/errors.d.ts
|
|
2
|
+
type ConnectionsSDKErrorCode = 'INVALID_CONNECTION_NAME' | 'BUSINESS_ERROR' | 'REQUEST_FAILED' | 'TIMEOUT' | 'MISSING_DATA' | 'INVALID_RESPONSE';
|
|
3
|
+
interface ConnectionsSDKErrorOptions {
|
|
4
|
+
code: ConnectionsSDKErrorCode;
|
|
5
|
+
message: string;
|
|
6
|
+
statusCode?: number;
|
|
7
|
+
requestId?: string;
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
}
|
|
10
|
+
declare class ConnectionsSDKError extends Error {
|
|
11
|
+
readonly code: ConnectionsSDKErrorCode;
|
|
12
|
+
readonly statusCode?: number;
|
|
13
|
+
readonly requestId?: string;
|
|
14
|
+
readonly cause?: unknown;
|
|
15
|
+
constructor(options: ConnectionsSDKErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ConnectionsSDKError, ConnectionsSDKErrorCode, ConnectionsSDKErrorOptions };
|
|
19
|
+
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";KAAY,uBAAA;AAAA,UAQK,0BAAA;EACf,IAAA,EAAM,uBAAA;EACN,OAAA;EACA,UAAA;EACA,SAAA;EACA,KAAA;AAAA;AAAA,cAGW,mBAAA,SAA4B,KAAA;EAAA,SAC9B,IAAA,EAAM,uBAAA;EAAA,SACN,UAAA;EAAA,SACA,SAAA;EAAA,SACS,KAAA;cAEN,OAAA,EAAS,0BAAA;AAAA"}
|
package/dist/errors.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/errors.ts
|
|
2
|
+
var ConnectionsSDKError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
statusCode;
|
|
5
|
+
requestId;
|
|
6
|
+
cause;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options.message);
|
|
9
|
+
this.name = "ConnectionsSDKError";
|
|
10
|
+
this.code = options.code;
|
|
11
|
+
this.statusCode = options.statusCode;
|
|
12
|
+
this.requestId = options.requestId;
|
|
13
|
+
this.cause = options.cause;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ConnectionsSDKError };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export type ConnectionsSDKErrorCode =\n | 'INVALID_CONNECTION_NAME'\n | 'BUSINESS_ERROR'\n | 'REQUEST_FAILED'\n | 'TIMEOUT'\n | 'MISSING_DATA'\n | 'INVALID_RESPONSE';\n\nexport interface ConnectionsSDKErrorOptions {\n code: ConnectionsSDKErrorCode;\n message: string;\n statusCode?: number;\n requestId?: string;\n cause?: unknown;\n}\n\nexport class ConnectionsSDKError extends Error {\n readonly code: ConnectionsSDKErrorCode;\n readonly statusCode?: number;\n readonly requestId?: string;\n override readonly cause?: unknown;\n\n constructor(options: ConnectionsSDKErrorOptions) {\n super(options.message);\n this.name = 'ConnectionsSDKError';\n this.code = options.code;\n this.statusCode = options.statusCode;\n this.requestId = options.requestId;\n this.cause = options.cause;\n }\n}\n"],"mappings":";AAgBA,IAAa,sBAAb,cAAyC,MAAM;CAC7C;CACA;CACA;CACA;CAEA,YAAY,SAAqC;AAC/C,QAAM,QAAQ,QAAQ;AACtB,OAAK,OAAO;AACZ,OAAK,OAAO,QAAQ;AACpB,OAAK,aAAa,QAAQ;AAC1B,OAAK,YAAY,QAAQ;AACzB,OAAK,QAAQ,QAAQ"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_errors = require("./errors.cjs");
|
|
3
|
+
const require_create_client = require("./create-client.cjs");
|
|
4
|
+
const require_nestjs = require("./nestjs.cjs");
|
|
5
|
+
exports.ConnectionsSDKError = require_errors.ConnectionsSDKError;
|
|
6
|
+
exports.ConnectionsService = require_nestjs.ConnectionsService;
|
|
7
|
+
Object.defineProperty(exports, "MiaodaConnectionsModule", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function() {
|
|
10
|
+
return require_nestjs.MiaodaConnectionsModule;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
exports.createConnectionsClient = require_create_client.createConnectionsClient;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApiEnvelope, ApiKeyConnection, BasicConnection, ConnectedConnection, ConnectionResult, ConnectionValue, ConnectionsClient, ConnectionsLogger, ConnectionsRequest, ConnectionsTransport, CreateConnectionsClientOptions, CustomConnection, GetConnectionOptions, NotConnectedConnection, OAuth2Connection, RdbConnection } from "./types.cjs";
|
|
2
|
+
import { createConnectionsClient } from "./create-client.cjs";
|
|
3
|
+
import { ConnectionsSDKError, ConnectionsSDKErrorCode, ConnectionsSDKErrorOptions } from "./errors.cjs";
|
|
4
|
+
import { ConnectionsService, MiaodaConnectionsModule } from "./nestjs.cjs";
|
|
5
|
+
export { type ApiEnvelope, type ApiKeyConnection, type BasicConnection, type ConnectedConnection, type ConnectionResult, type ConnectionValue, type ConnectionsClient, type ConnectionsLogger, type ConnectionsRequest, ConnectionsSDKError, type ConnectionsSDKErrorCode, type ConnectionsSDKErrorOptions, ConnectionsService, type ConnectionsTransport, type CreateConnectionsClientOptions, type CustomConnection, type GetConnectionOptions, MiaodaConnectionsModule, type NotConnectedConnection, type OAuth2Connection, type RdbConnection, createConnectionsClient };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApiEnvelope, ApiKeyConnection, BasicConnection, ConnectedConnection, ConnectionResult, ConnectionValue, ConnectionsClient, ConnectionsLogger, ConnectionsRequest, ConnectionsTransport, CreateConnectionsClientOptions, CustomConnection, GetConnectionOptions, NotConnectedConnection, OAuth2Connection, RdbConnection } from "./types.mjs";
|
|
2
|
+
import { createConnectionsClient } from "./create-client.mjs";
|
|
3
|
+
import { ConnectionsSDKError, ConnectionsSDKErrorCode, ConnectionsSDKErrorOptions } from "./errors.mjs";
|
|
4
|
+
import { ConnectionsService, MiaodaConnectionsModule } from "./nestjs.mjs";
|
|
5
|
+
export { type ApiEnvelope, type ApiKeyConnection, type BasicConnection, type ConnectedConnection, type ConnectionResult, type ConnectionValue, type ConnectionsClient, type ConnectionsLogger, type ConnectionsRequest, ConnectionsSDKError, type ConnectionsSDKErrorCode, type ConnectionsSDKErrorOptions, ConnectionsService, type ConnectionsTransport, type CreateConnectionsClientOptions, type CustomConnection, type GetConnectionOptions, MiaodaConnectionsModule, type NotConnectedConnection, type OAuth2Connection, type RdbConnection, createConnectionsClient };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ConnectionsSDKError } from "./errors.mjs";
|
|
2
|
+
import { createConnectionsClient } from "./create-client.mjs";
|
|
3
|
+
import { ConnectionsService, MiaodaConnectionsModule } from "./nestjs.mjs";
|
|
4
|
+
export { ConnectionsSDKError, ConnectionsService, MiaodaConnectionsModule, createConnectionsClient };
|
package/dist/nestjs.cjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const require_create_client = require("./create-client.cjs");
|
|
2
|
+
const require_platform_http_client = require("./platform-http-client.cjs");
|
|
3
|
+
const require_decorateMetadata = require("./_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.cjs");
|
|
4
|
+
const require_decorateParam = require("./_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateParam.cjs");
|
|
5
|
+
const require_decorate = require("./_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.cjs");
|
|
6
|
+
let _nestjs_common = require("@nestjs/common");
|
|
7
|
+
let _lark_apaas_nestjs_common = require("@lark-apaas/nestjs-common");
|
|
8
|
+
//#region src/nestjs.ts
|
|
9
|
+
var ConnectionsService = class {};
|
|
10
|
+
let PlatformConnectionsService = class PlatformConnectionsService extends ConnectionsService {
|
|
11
|
+
client;
|
|
12
|
+
constructor(platformHttpClient) {
|
|
13
|
+
super();
|
|
14
|
+
this.client = require_create_client.createConnectionsClient({ transport: require_platform_http_client.createPlatformHttpClientTransport(platformHttpClient) });
|
|
15
|
+
}
|
|
16
|
+
getConnection(input) {
|
|
17
|
+
if (typeof input === "string") return this.client.getConnection(input);
|
|
18
|
+
return this.client.getConnection(input);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
PlatformConnectionsService = require_decorate.__decorate([
|
|
22
|
+
(0, _nestjs_common.Injectable)(),
|
|
23
|
+
require_decorateParam.__decorateParam(0, (0, _nestjs_common.Inject)(_lark_apaas_nestjs_common.PLATFORM_HTTP_CLIENT)),
|
|
24
|
+
require_decorateMetadata.__decorateMetadata("design:paramtypes", [Object])
|
|
25
|
+
], PlatformConnectionsService);
|
|
26
|
+
let MiaodaConnectionsModule = class MiaodaConnectionsModule {};
|
|
27
|
+
MiaodaConnectionsModule = require_decorate.__decorate([(0, _nestjs_common.Module)({
|
|
28
|
+
providers: [{
|
|
29
|
+
provide: ConnectionsService,
|
|
30
|
+
useClass: PlatformConnectionsService
|
|
31
|
+
}],
|
|
32
|
+
exports: [ConnectionsService]
|
|
33
|
+
})], MiaodaConnectionsModule);
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.ConnectionsService = ConnectionsService;
|
|
36
|
+
Object.defineProperty(exports, "MiaodaConnectionsModule", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function() {
|
|
39
|
+
return MiaodaConnectionsModule;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=nestjs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nestjs.cjs","names":["createConnectionsClient","createPlatformHttpClientTransport","PLATFORM_HTTP_CLIENT"],"sources":["../src/nestjs.ts"],"sourcesContent":["import { Inject, Injectable, Module } from '@nestjs/common';\nimport {\n PLATFORM_HTTP_CLIENT,\n type PlatformHttpClient,\n} from '@lark-apaas/nestjs-common';\n\nimport { createConnectionsClient } from './create-client';\nimport { createPlatformHttpClientTransport } from './platform-http-client';\nimport type {\n ConnectionResult,\n ConnectionsClient,\n GetConnectionOptions,\n} from './types';\n\nexport abstract class ConnectionsService implements ConnectionsClient {\n abstract getConnection(name: string): Promise<ConnectionResult>;\n abstract getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;\n}\n\n@Injectable()\nclass PlatformConnectionsService extends ConnectionsService {\n private readonly client: ConnectionsClient;\n\n constructor(\n @Inject(PLATFORM_HTTP_CLIENT)\n platformHttpClient: PlatformHttpClient\n ) {\n super();\n this.client = createConnectionsClient({\n transport: createPlatformHttpClientTransport(platformHttpClient),\n });\n }\n\n getConnection(name: string): Promise<ConnectionResult>;\n getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;\n getConnection(input: string | GetConnectionOptions): Promise<ConnectionResult> {\n if (typeof input === 'string') {\n return this.client.getConnection(input);\n }\n\n return this.client.getConnection(input);\n }\n}\n\n@Module({\n providers: [\n {\n provide: ConnectionsService,\n useClass: PlatformConnectionsService,\n },\n ],\n exports: [ConnectionsService],\n})\nexport class MiaodaConnectionsModule {}\n"],"mappings":";;;;;;;;AAcA,IAAsB,qBAAtB,MAAsE;AAKtE,IAAA,6BAAA,MACM,mCAAmC,mBAAmB;CAC1D;CAEA,YACE,oBAEA;AACA,SAAO;AACP,OAAK,SAASA,sBAAAA,wBAAwB,EACpC,WAAWC,6BAAAA,kCAAkC,mBAAmB,EACjE,CAAC;;CAKJ,cAAc,OAAiE;AAC7E,MAAI,OAAO,UAAU,SACnB,QAAO,KAAK,OAAO,cAAc,MAAM;AAGzC,SAAO,KAAK,OAAO,cAAc,MAAM;;;;iCArB9B;qEAKDC,0BAAAA,qBAAqB,CAAA;;;AA6B1B,IAAA,0BAAA,MAAM,wBAAwB;kFAT7B;CACN,WAAW,CACT;EACE,SAAS;EACT,UAAU;EACX,CACF;CACD,SAAS,CAAC,mBAAmB;CAC9B,CAAC,CAAA,EAAA,wBAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConnectionResult, ConnectionsClient, GetConnectionOptions } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/nestjs.d.ts
|
|
4
|
+
declare abstract class ConnectionsService implements ConnectionsClient {
|
|
5
|
+
abstract getConnection(name: string): Promise<ConnectionResult>;
|
|
6
|
+
abstract getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;
|
|
7
|
+
}
|
|
8
|
+
declare class MiaodaConnectionsModule {}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ConnectionsService, MiaodaConnectionsModule };
|
|
11
|
+
//# sourceMappingURL=nestjs.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nestjs.d.cts","names":[],"sources":["../src/nestjs.ts"],"mappings":";;;uBAcsB,kBAAA,YAA8B,iBAAA;EAAA,SACzC,aAAA,CAAc,IAAA,WAAe,OAAA,CAAQ,gBAAA;EAAA,SACrC,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,OAAA,CAAQ,gBAAA;AAAA;AAAA,cAqCpD,uBAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConnectionResult, ConnectionsClient, GetConnectionOptions } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/nestjs.d.ts
|
|
4
|
+
declare abstract class ConnectionsService implements ConnectionsClient {
|
|
5
|
+
abstract getConnection(name: string): Promise<ConnectionResult>;
|
|
6
|
+
abstract getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;
|
|
7
|
+
}
|
|
8
|
+
declare class MiaodaConnectionsModule {}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ConnectionsService, MiaodaConnectionsModule };
|
|
11
|
+
//# sourceMappingURL=nestjs.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nestjs.d.mts","names":[],"sources":["../src/nestjs.ts"],"mappings":";;;uBAcsB,kBAAA,YAA8B,iBAAA;EAAA,SACzC,aAAA,CAAc,IAAA,WAAe,OAAA,CAAQ,gBAAA;EAAA,SACrC,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,OAAA,CAAQ,gBAAA;AAAA;AAAA,cAqCpD,uBAAA"}
|
package/dist/nestjs.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createConnectionsClient } from "./create-client.mjs";
|
|
2
|
+
import { createPlatformHttpClientTransport } from "./platform-http-client.mjs";
|
|
3
|
+
import { __decorateMetadata } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.mjs";
|
|
4
|
+
import { __decorateParam } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateParam.mjs";
|
|
5
|
+
import { __decorate } from "./_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.mjs";
|
|
6
|
+
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
7
|
+
import { PLATFORM_HTTP_CLIENT } from "@lark-apaas/nestjs-common";
|
|
8
|
+
//#region src/nestjs.ts
|
|
9
|
+
var ConnectionsService = class {};
|
|
10
|
+
let PlatformConnectionsService = class PlatformConnectionsService extends ConnectionsService {
|
|
11
|
+
client;
|
|
12
|
+
constructor(platformHttpClient) {
|
|
13
|
+
super();
|
|
14
|
+
this.client = createConnectionsClient({ transport: createPlatformHttpClientTransport(platformHttpClient) });
|
|
15
|
+
}
|
|
16
|
+
getConnection(input) {
|
|
17
|
+
if (typeof input === "string") return this.client.getConnection(input);
|
|
18
|
+
return this.client.getConnection(input);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
PlatformConnectionsService = __decorate([
|
|
22
|
+
Injectable(),
|
|
23
|
+
__decorateParam(0, Inject(PLATFORM_HTTP_CLIENT)),
|
|
24
|
+
__decorateMetadata("design:paramtypes", [Object])
|
|
25
|
+
], PlatformConnectionsService);
|
|
26
|
+
let MiaodaConnectionsModule = class MiaodaConnectionsModule {};
|
|
27
|
+
MiaodaConnectionsModule = __decorate([Module({
|
|
28
|
+
providers: [{
|
|
29
|
+
provide: ConnectionsService,
|
|
30
|
+
useClass: PlatformConnectionsService
|
|
31
|
+
}],
|
|
32
|
+
exports: [ConnectionsService]
|
|
33
|
+
})], MiaodaConnectionsModule);
|
|
34
|
+
//#endregion
|
|
35
|
+
export { ConnectionsService, MiaodaConnectionsModule };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=nestjs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nestjs.mjs","names":[],"sources":["../src/nestjs.ts"],"sourcesContent":["import { Inject, Injectable, Module } from '@nestjs/common';\nimport {\n PLATFORM_HTTP_CLIENT,\n type PlatformHttpClient,\n} from '@lark-apaas/nestjs-common';\n\nimport { createConnectionsClient } from './create-client';\nimport { createPlatformHttpClientTransport } from './platform-http-client';\nimport type {\n ConnectionResult,\n ConnectionsClient,\n GetConnectionOptions,\n} from './types';\n\nexport abstract class ConnectionsService implements ConnectionsClient {\n abstract getConnection(name: string): Promise<ConnectionResult>;\n abstract getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;\n}\n\n@Injectable()\nclass PlatformConnectionsService extends ConnectionsService {\n private readonly client: ConnectionsClient;\n\n constructor(\n @Inject(PLATFORM_HTTP_CLIENT)\n platformHttpClient: PlatformHttpClient\n ) {\n super();\n this.client = createConnectionsClient({\n transport: createPlatformHttpClientTransport(platformHttpClient),\n });\n }\n\n getConnection(name: string): Promise<ConnectionResult>;\n getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;\n getConnection(input: string | GetConnectionOptions): Promise<ConnectionResult> {\n if (typeof input === 'string') {\n return this.client.getConnection(input);\n }\n\n return this.client.getConnection(input);\n }\n}\n\n@Module({\n providers: [\n {\n provide: ConnectionsService,\n useClass: PlatformConnectionsService,\n },\n ],\n exports: [ConnectionsService],\n})\nexport class MiaodaConnectionsModule {}\n"],"mappings":";;;;;;;;AAcA,IAAsB,qBAAtB,MAAsE;AAKtE,IAAA,6BAAA,MACM,mCAAmC,mBAAmB;CAC1D;CAEA,YACE,oBAEA;AACA,SAAO;AACP,OAAK,SAAS,wBAAwB,EACpC,WAAW,kCAAkC,mBAAmB,EACjE,CAAC;;CAKJ,cAAc,OAAiE;AAC7E,MAAI,OAAO,UAAU,SACnB,QAAO,KAAK,OAAO,cAAc,MAAM;AAGzC,SAAO,KAAK,OAAO,cAAc,MAAM;;;;CArB1C,YAAY;oBAKR,OAAO,qBAAqB,CAAA;;;AA6B1B,IAAA,0BAAA,MAAM,wBAAwB;sCATpC,OAAO;CACN,WAAW,CACT;EACE,SAAS;EACT,UAAU;EACX,CACF;CACD,SAAS,CAAC,mBAAmB;CAC9B,CAAC,CAAA,EAAA,wBAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const require_errors = require("./errors.cjs");
|
|
2
|
+
const require_redaction = require("./redaction.cjs");
|
|
3
|
+
//#region src/platform-http-client.ts
|
|
4
|
+
function createPlatformHttpClientTransport(client) {
|
|
5
|
+
return { async request(request) {
|
|
6
|
+
const response = await client.get(request.path, { timeout: request.timeoutMs });
|
|
7
|
+
const requestId = response.headers.get("x-tt-logid") ?? response.headers.get("x-request-id") ?? void 0;
|
|
8
|
+
const text = await response.text();
|
|
9
|
+
if (!response.ok) throw new require_errors.ConnectionsSDKError({
|
|
10
|
+
code: "REQUEST_FAILED",
|
|
11
|
+
message: `Connection request failed with HTTP ${response.status}`,
|
|
12
|
+
statusCode: response.status,
|
|
13
|
+
requestId,
|
|
14
|
+
cause: text ? require_redaction.sanitizeCause(text) : void 0
|
|
15
|
+
});
|
|
16
|
+
if (!text) throw new require_errors.ConnectionsSDKError({
|
|
17
|
+
code: "INVALID_RESPONSE",
|
|
18
|
+
message: "Connection response body is empty",
|
|
19
|
+
statusCode: response.status,
|
|
20
|
+
requestId
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(text);
|
|
24
|
+
} catch (cause) {
|
|
25
|
+
throw new require_errors.ConnectionsSDKError({
|
|
26
|
+
code: "INVALID_RESPONSE",
|
|
27
|
+
message: "Connection response body is not valid JSON",
|
|
28
|
+
statusCode: response.status,
|
|
29
|
+
requestId,
|
|
30
|
+
cause: require_redaction.sanitizeCause(cause)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
} };
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.createPlatformHttpClientTransport = createPlatformHttpClientTransport;
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=platform-http-client.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-http-client.cjs","names":["ConnectionsSDKError","sanitizeCause"],"sources":["../src/platform-http-client.ts"],"sourcesContent":["import { ConnectionsSDKError } from './errors';\nimport { sanitizeCause } from './redaction';\nimport type { ConnectionsRequest, ConnectionsTransport } from './types';\n\nexport interface PlatformHttpClientLike {\n get(url: string, config?: { timeout?: number }): Promise<Response>;\n}\n\nexport function createPlatformHttpClientTransport(\n client: PlatformHttpClientLike\n): ConnectionsTransport {\n return {\n async request<T>(request: ConnectionsRequest): Promise<T> {\n const response = await client.get(request.path, {\n timeout: request.timeoutMs,\n });\n\n const requestId =\n response.headers.get('x-tt-logid') ??\n response.headers.get('x-request-id') ??\n undefined;\n const text = await response.text();\n\n if (!response.ok) {\n throw new ConnectionsSDKError({\n code: 'REQUEST_FAILED',\n message: `Connection request failed with HTTP ${response.status}`,\n statusCode: response.status,\n requestId,\n cause: text ? sanitizeCause(text) : undefined,\n });\n }\n\n if (!text) {\n throw new ConnectionsSDKError({\n code: 'INVALID_RESPONSE',\n message: 'Connection response body is empty',\n statusCode: response.status,\n requestId,\n });\n }\n\n try {\n return JSON.parse(text) as T;\n } catch (cause) {\n throw new ConnectionsSDKError({\n code: 'INVALID_RESPONSE',\n message: 'Connection response body is not valid JSON',\n statusCode: response.status,\n requestId,\n cause: sanitizeCause(cause),\n });\n }\n },\n };\n}\n"],"mappings":";;;AAQA,SAAgB,kCACd,QACsB;AACtB,QAAO,EACL,MAAM,QAAW,SAAyC;EACxD,MAAM,WAAW,MAAM,OAAO,IAAI,QAAQ,MAAM,EAC9C,SAAS,QAAQ,WAClB,CAAC;EAEF,MAAM,YACJ,SAAS,QAAQ,IAAI,aAAa,IAClC,SAAS,QAAQ,IAAI,eAAe,IACpC,KAAA;EACF,MAAM,OAAO,MAAM,SAAS,MAAM;AAElC,MAAI,CAAC,SAAS,GACZ,OAAM,IAAIA,eAAAA,oBAAoB;GAC5B,MAAM;GACN,SAAS,uCAAuC,SAAS;GACzD,YAAY,SAAS;GACrB;GACA,OAAO,OAAOC,kBAAAA,cAAc,KAAK,GAAG,KAAA;GACrC,CAAC;AAGJ,MAAI,CAAC,KACH,OAAM,IAAID,eAAAA,oBAAoB;GAC5B,MAAM;GACN,SAAS;GACT,YAAY,SAAS;GACrB;GACD,CAAC;AAGJ,MAAI;AACF,UAAO,KAAK,MAAM,KAAK;WAChB,OAAO;AACd,SAAM,IAAIA,eAAAA,oBAAoB;IAC5B,MAAM;IACN,SAAS;IACT,YAAY,SAAS;IACrB;IACA,OAAOC,kBAAAA,cAAc,MAAM;IAC5B,CAAC;;IAGP"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ConnectionsSDKError } from "./errors.mjs";
|
|
2
|
+
import { sanitizeCause } from "./redaction.mjs";
|
|
3
|
+
//#region src/platform-http-client.ts
|
|
4
|
+
function createPlatformHttpClientTransport(client) {
|
|
5
|
+
return { async request(request) {
|
|
6
|
+
const response = await client.get(request.path, { timeout: request.timeoutMs });
|
|
7
|
+
const requestId = response.headers.get("x-tt-logid") ?? response.headers.get("x-request-id") ?? void 0;
|
|
8
|
+
const text = await response.text();
|
|
9
|
+
if (!response.ok) throw new ConnectionsSDKError({
|
|
10
|
+
code: "REQUEST_FAILED",
|
|
11
|
+
message: `Connection request failed with HTTP ${response.status}`,
|
|
12
|
+
statusCode: response.status,
|
|
13
|
+
requestId,
|
|
14
|
+
cause: text ? sanitizeCause(text) : void 0
|
|
15
|
+
});
|
|
16
|
+
if (!text) throw new ConnectionsSDKError({
|
|
17
|
+
code: "INVALID_RESPONSE",
|
|
18
|
+
message: "Connection response body is empty",
|
|
19
|
+
statusCode: response.status,
|
|
20
|
+
requestId
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(text);
|
|
24
|
+
} catch (cause) {
|
|
25
|
+
throw new ConnectionsSDKError({
|
|
26
|
+
code: "INVALID_RESPONSE",
|
|
27
|
+
message: "Connection response body is not valid JSON",
|
|
28
|
+
statusCode: response.status,
|
|
29
|
+
requestId,
|
|
30
|
+
cause: sanitizeCause(cause)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
} };
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createPlatformHttpClientTransport };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=platform-http-client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-http-client.mjs","names":[],"sources":["../src/platform-http-client.ts"],"sourcesContent":["import { ConnectionsSDKError } from './errors';\nimport { sanitizeCause } from './redaction';\nimport type { ConnectionsRequest, ConnectionsTransport } from './types';\n\nexport interface PlatformHttpClientLike {\n get(url: string, config?: { timeout?: number }): Promise<Response>;\n}\n\nexport function createPlatformHttpClientTransport(\n client: PlatformHttpClientLike\n): ConnectionsTransport {\n return {\n async request<T>(request: ConnectionsRequest): Promise<T> {\n const response = await client.get(request.path, {\n timeout: request.timeoutMs,\n });\n\n const requestId =\n response.headers.get('x-tt-logid') ??\n response.headers.get('x-request-id') ??\n undefined;\n const text = await response.text();\n\n if (!response.ok) {\n throw new ConnectionsSDKError({\n code: 'REQUEST_FAILED',\n message: `Connection request failed with HTTP ${response.status}`,\n statusCode: response.status,\n requestId,\n cause: text ? sanitizeCause(text) : undefined,\n });\n }\n\n if (!text) {\n throw new ConnectionsSDKError({\n code: 'INVALID_RESPONSE',\n message: 'Connection response body is empty',\n statusCode: response.status,\n requestId,\n });\n }\n\n try {\n return JSON.parse(text) as T;\n } catch (cause) {\n throw new ConnectionsSDKError({\n code: 'INVALID_RESPONSE',\n message: 'Connection response body is not valid JSON',\n statusCode: response.status,\n requestId,\n cause: sanitizeCause(cause),\n });\n }\n },\n };\n}\n"],"mappings":";;;AAQA,SAAgB,kCACd,QACsB;AACtB,QAAO,EACL,MAAM,QAAW,SAAyC;EACxD,MAAM,WAAW,MAAM,OAAO,IAAI,QAAQ,MAAM,EAC9C,SAAS,QAAQ,WAClB,CAAC;EAEF,MAAM,YACJ,SAAS,QAAQ,IAAI,aAAa,IAClC,SAAS,QAAQ,IAAI,eAAe,IACpC,KAAA;EACF,MAAM,OAAO,MAAM,SAAS,MAAM;AAElC,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,oBAAoB;GAC5B,MAAM;GACN,SAAS,uCAAuC,SAAS;GACzD,YAAY,SAAS;GACrB;GACA,OAAO,OAAO,cAAc,KAAK,GAAG,KAAA;GACrC,CAAC;AAGJ,MAAI,CAAC,KACH,OAAM,IAAI,oBAAoB;GAC5B,MAAM;GACN,SAAS;GACT,YAAY,SAAS;GACrB;GACD,CAAC;AAGJ,MAAI;AACF,UAAO,KAAK,MAAM,KAAK;WAChB,OAAO;AACd,SAAM,IAAI,oBAAoB;IAC5B,MAAM;IACN,SAAS;IACT,YAAY,SAAS;IACrB;IACA,OAAO,cAAc,MAAM;IAC5B,CAAC;;IAGP"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/redaction.ts
|
|
2
|
+
const SENSITIVE_KEY_PATTERN = /(?:access[_-]?token|api[_-]?key|authorization|password|secret|credential|payload)/i;
|
|
3
|
+
const SENSITIVE_VALUE_PATTERN = /(Bearer\s+)[^\s,;]+|((?:access[_-]?token|api[_-]?key|password|secret|credential)["']?\s*[:=]\s*["']?)[^"',;\s}]+/gi;
|
|
4
|
+
function redactString(value) {
|
|
5
|
+
return value.replace(SENSITIVE_VALUE_PATTERN, (_match, bearerPrefix, keyPrefix) => {
|
|
6
|
+
if (bearerPrefix) return `${bearerPrefix}[REDACTED]`;
|
|
7
|
+
return `${keyPrefix}[REDACTED]`;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function redactConnectionName(name) {
|
|
11
|
+
if (name.length <= 4) return "[REDACTED]";
|
|
12
|
+
return `${name.slice(0, 2)}***${name.slice(-2)}`;
|
|
13
|
+
}
|
|
14
|
+
function sanitizeCause(cause) {
|
|
15
|
+
if (cause instanceof Error) return {
|
|
16
|
+
name: cause.name,
|
|
17
|
+
message: redactString(cause.message)
|
|
18
|
+
};
|
|
19
|
+
if (typeof cause === "string") return redactString(cause);
|
|
20
|
+
if (typeof cause !== "object" || cause === null) return cause;
|
|
21
|
+
const result = {};
|
|
22
|
+
for (const [key, value] of Object.entries(cause)) {
|
|
23
|
+
if (SENSITIVE_KEY_PATTERN.test(key)) {
|
|
24
|
+
result[key] = "[REDACTED]";
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
result[key] = typeof value === "string" ? redactString(value) : value;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.redactConnectionName = redactConnectionName;
|
|
33
|
+
exports.sanitizeCause = sanitizeCause;
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=redaction.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.cjs","names":[],"sources":["../src/redaction.ts"],"sourcesContent":["const SENSITIVE_KEY_PATTERN =\n /(?:access[_-]?token|api[_-]?key|authorization|password|secret|credential|payload)/i;\nconst SENSITIVE_VALUE_PATTERN =\n /(Bearer\\s+)[^\\s,;]+|((?:access[_-]?token|api[_-]?key|password|secret|credential)[\"']?\\s*[:=]\\s*[\"']?)[^\"',;\\s}]+/gi;\n\nexport function redactString(value: string): string {\n return value.replace(\n SENSITIVE_VALUE_PATTERN,\n (_match, bearerPrefix, keyPrefix) => {\n if (bearerPrefix) return `${bearerPrefix}[REDACTED]`;\n return `${keyPrefix}[REDACTED]`;\n }\n );\n}\n\nexport function redactConnectionName(name: string): string {\n if (name.length <= 4) return '[REDACTED]';\n return `${name.slice(0, 2)}***${name.slice(-2)}`;\n}\n\nexport function sanitizeCause(cause: unknown): unknown {\n if (cause instanceof Error) {\n return {\n name: cause.name,\n message: redactString(cause.message),\n };\n }\n\n if (typeof cause === 'string') return redactString(cause);\n if (typeof cause !== 'object' || cause === null) return cause;\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(cause as Record<string, unknown>)) {\n if (SENSITIVE_KEY_PATTERN.test(key)) {\n result[key] = '[REDACTED]';\n continue;\n }\n\n result[key] = typeof value === 'string' ? redactString(value) : value;\n }\n return result;\n}\n"],"mappings":";AAAA,MAAM,wBACJ;AACF,MAAM,0BACJ;AAEF,SAAgB,aAAa,OAAuB;AAClD,QAAO,MAAM,QACX,0BACC,QAAQ,cAAc,cAAc;AACnC,MAAI,aAAc,QAAO,GAAG,aAAa;AACzC,SAAO,GAAG,UAAU;GAEvB;;AAGH,SAAgB,qBAAqB,MAAsB;AACzD,KAAI,KAAK,UAAU,EAAG,QAAO;AAC7B,QAAO,GAAG,KAAK,MAAM,GAAG,EAAE,CAAC,KAAK,KAAK,MAAM,GAAG;;AAGhD,SAAgB,cAAc,OAAyB;AACrD,KAAI,iBAAiB,MACnB,QAAO;EACL,MAAM,MAAM;EACZ,SAAS,aAAa,MAAM,QAAQ;EACrC;AAGH,KAAI,OAAO,UAAU,SAAU,QAAO,aAAa,MAAM;AACzD,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CAExD,MAAM,SAAkC,EAAE;AAC1C,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAiC,EAAE;AAC3E,MAAI,sBAAsB,KAAK,IAAI,EAAE;AACnC,UAAO,OAAO;AACd;;AAGF,SAAO,OAAO,OAAO,UAAU,WAAW,aAAa,MAAM,GAAG;;AAElE,QAAO"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/redaction.ts
|
|
2
|
+
const SENSITIVE_KEY_PATTERN = /(?:access[_-]?token|api[_-]?key|authorization|password|secret|credential|payload)/i;
|
|
3
|
+
const SENSITIVE_VALUE_PATTERN = /(Bearer\s+)[^\s,;]+|((?:access[_-]?token|api[_-]?key|password|secret|credential)["']?\s*[:=]\s*["']?)[^"',;\s}]+/gi;
|
|
4
|
+
function redactString(value) {
|
|
5
|
+
return value.replace(SENSITIVE_VALUE_PATTERN, (_match, bearerPrefix, keyPrefix) => {
|
|
6
|
+
if (bearerPrefix) return `${bearerPrefix}[REDACTED]`;
|
|
7
|
+
return `${keyPrefix}[REDACTED]`;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function redactConnectionName(name) {
|
|
11
|
+
if (name.length <= 4) return "[REDACTED]";
|
|
12
|
+
return `${name.slice(0, 2)}***${name.slice(-2)}`;
|
|
13
|
+
}
|
|
14
|
+
function sanitizeCause(cause) {
|
|
15
|
+
if (cause instanceof Error) return {
|
|
16
|
+
name: cause.name,
|
|
17
|
+
message: redactString(cause.message)
|
|
18
|
+
};
|
|
19
|
+
if (typeof cause === "string") return redactString(cause);
|
|
20
|
+
if (typeof cause !== "object" || cause === null) return cause;
|
|
21
|
+
const result = {};
|
|
22
|
+
for (const [key, value] of Object.entries(cause)) {
|
|
23
|
+
if (SENSITIVE_KEY_PATTERN.test(key)) {
|
|
24
|
+
result[key] = "[REDACTED]";
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
result[key] = typeof value === "string" ? redactString(value) : value;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { redactConnectionName, sanitizeCause };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=redaction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.mjs","names":[],"sources":["../src/redaction.ts"],"sourcesContent":["const SENSITIVE_KEY_PATTERN =\n /(?:access[_-]?token|api[_-]?key|authorization|password|secret|credential|payload)/i;\nconst SENSITIVE_VALUE_PATTERN =\n /(Bearer\\s+)[^\\s,;]+|((?:access[_-]?token|api[_-]?key|password|secret|credential)[\"']?\\s*[:=]\\s*[\"']?)[^\"',;\\s}]+/gi;\n\nexport function redactString(value: string): string {\n return value.replace(\n SENSITIVE_VALUE_PATTERN,\n (_match, bearerPrefix, keyPrefix) => {\n if (bearerPrefix) return `${bearerPrefix}[REDACTED]`;\n return `${keyPrefix}[REDACTED]`;\n }\n );\n}\n\nexport function redactConnectionName(name: string): string {\n if (name.length <= 4) return '[REDACTED]';\n return `${name.slice(0, 2)}***${name.slice(-2)}`;\n}\n\nexport function sanitizeCause(cause: unknown): unknown {\n if (cause instanceof Error) {\n return {\n name: cause.name,\n message: redactString(cause.message),\n };\n }\n\n if (typeof cause === 'string') return redactString(cause);\n if (typeof cause !== 'object' || cause === null) return cause;\n\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(cause as Record<string, unknown>)) {\n if (SENSITIVE_KEY_PATTERN.test(key)) {\n result[key] = '[REDACTED]';\n continue;\n }\n\n result[key] = typeof value === 'string' ? redactString(value) : value;\n }\n return result;\n}\n"],"mappings":";AAAA,MAAM,wBACJ;AACF,MAAM,0BACJ;AAEF,SAAgB,aAAa,OAAuB;AAClD,QAAO,MAAM,QACX,0BACC,QAAQ,cAAc,cAAc;AACnC,MAAI,aAAc,QAAO,GAAG,aAAa;AACzC,SAAO,GAAG,UAAU;GAEvB;;AAGH,SAAgB,qBAAqB,MAAsB;AACzD,KAAI,KAAK,UAAU,EAAG,QAAO;AAC7B,QAAO,GAAG,KAAK,MAAM,GAAG,EAAE,CAAC,KAAK,KAAK,MAAM,GAAG;;AAGhD,SAAgB,cAAc,OAAyB;AACrD,KAAI,iBAAiB,MACnB,QAAO;EACL,MAAM,MAAM;EACZ,SAAS,aAAa,MAAM,QAAQ;EACrC;AAGH,KAAI,OAAO,UAAU,SAAU,QAAO,aAAa,MAAM;AACzD,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CAExD,MAAM,SAAkC,EAAE;AAC1C,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAiC,EAAE;AAC3E,MAAI,sBAAsB,KAAK,IAAI,EAAE;AACnC,UAAO,OAAO;AACd;;AAGF,SAAO,OAAO,OAAO,UAAU,WAAW,aAAa,MAAM,GAAG;;AAElE,QAAO"}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface CreateConnectionsClientOptions {
|
|
3
|
+
transport: ConnectionsTransport;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
logger?: ConnectionsLogger;
|
|
7
|
+
}
|
|
8
|
+
interface ConnectionsClient {
|
|
9
|
+
getConnection(name: string): Promise<ConnectionResult>;
|
|
10
|
+
getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;
|
|
11
|
+
}
|
|
12
|
+
interface GetConnectionOptions {
|
|
13
|
+
connectionName: string;
|
|
14
|
+
}
|
|
15
|
+
interface ConnectionsLogger {
|
|
16
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
17
|
+
}
|
|
18
|
+
interface ConnectionsTransport {
|
|
19
|
+
request<T>(request: ConnectionsRequest): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
interface ConnectionsRequest {
|
|
22
|
+
method: 'GET';
|
|
23
|
+
path: string;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
}
|
|
26
|
+
interface ApiEnvelope<T> {
|
|
27
|
+
status_code: string;
|
|
28
|
+
error_msg?: string;
|
|
29
|
+
data?: T;
|
|
30
|
+
}
|
|
31
|
+
type ConnectionResult = ConnectedConnection | NotConnectedConnection;
|
|
32
|
+
interface ConnectedConnection {
|
|
33
|
+
state: 'connected';
|
|
34
|
+
value: ConnectionValue;
|
|
35
|
+
issuedAt: string;
|
|
36
|
+
issuanceId: string;
|
|
37
|
+
}
|
|
38
|
+
interface NotConnectedConnection {
|
|
39
|
+
state: 'not_connected';
|
|
40
|
+
reason: 'first_time' | 'expired' | 'revoked' | 'refresh_failed' | 'outdated';
|
|
41
|
+
recoveryHint: 'authorize' | 'admin_reauthorize';
|
|
42
|
+
requiredScopes?: string[];
|
|
43
|
+
consoleUrl?: string;
|
|
44
|
+
}
|
|
45
|
+
type ConnectionValue = OAuth2Connection | ApiKeyConnection | BasicConnection | RdbConnection | CustomConnection;
|
|
46
|
+
interface OAuth2Connection {
|
|
47
|
+
type: 'oauth2';
|
|
48
|
+
accessToken: string;
|
|
49
|
+
tokenType: 'Bearer';
|
|
50
|
+
expiresAt?: string;
|
|
51
|
+
scopes?: string[];
|
|
52
|
+
}
|
|
53
|
+
interface ApiKeyConnection {
|
|
54
|
+
type: 'api_key';
|
|
55
|
+
key: string;
|
|
56
|
+
in: 'header' | 'query';
|
|
57
|
+
name: string;
|
|
58
|
+
}
|
|
59
|
+
interface BasicConnection {
|
|
60
|
+
type: 'basic';
|
|
61
|
+
username: string;
|
|
62
|
+
password: string;
|
|
63
|
+
}
|
|
64
|
+
interface RdbConnection {
|
|
65
|
+
type: 'rdb';
|
|
66
|
+
host: string;
|
|
67
|
+
port: number;
|
|
68
|
+
username: string;
|
|
69
|
+
password: string;
|
|
70
|
+
database?: string;
|
|
71
|
+
sslMode?: string;
|
|
72
|
+
}
|
|
73
|
+
interface CustomConnection {
|
|
74
|
+
type: 'custom';
|
|
75
|
+
payloadType: string;
|
|
76
|
+
payload: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { ApiEnvelope, ApiKeyConnection, BasicConnection, ConnectedConnection, ConnectionResult, ConnectionValue, ConnectionsClient, ConnectionsLogger, ConnectionsRequest, ConnectionsTransport, CreateConnectionsClientOptions, CustomConnection, GetConnectionOptions, NotConnectedConnection, OAuth2Connection, RdbConnection };
|
|
80
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";UAAiB,8BAAA;EACf,SAAA,EAAW,oBAAA;EACX,SAAA;EACA,KAAA;EACA,MAAA,GAAS,iBAAA;AAAA;AAAA,UAGM,iBAAA;EACf,aAAA,CAAc,IAAA,WAAe,OAAA,CAAQ,gBAAA;EACrC,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,OAAA,CAAQ,gBAAA;AAAA;AAAA,UAGvC,oBAAA;EACf,cAAA;AAAA;AAAA,UAGe,iBAAA;EACf,KAAA,CAAM,OAAA,UAAiB,IAAA,GAAO,MAAA;AAAA;AAAA,UAGf,oBAAA;EACf,OAAA,IAAW,OAAA,EAAS,kBAAA,GAAqB,OAAA,CAAQ,CAAA;AAAA;AAAA,UAGlC,kBAAA;EACf,MAAA;EACA,IAAA;EACA,SAAA;AAAA;AAAA,UAGe,WAAA;EACf,WAAA;EACA,SAAA;EACA,IAAA,GAAO,CAAA;AAAA;AAAA,KAGG,gBAAA,GAAmB,mBAAA,GAAsB,sBAAA;AAAA,UAEpC,mBAAA;EACf,KAAA;EACA,KAAA,EAAO,eAAA;EACP,QAAA;EACA,UAAA;AAAA;AAAA,UAGe,sBAAA;EACf,KAAA;EACA,MAAA;EACA,YAAA;EACA,cAAA;EACA,UAAA;AAAA;AAAA,KAGU,eAAA,GACR,gBAAA,GACA,gBAAA,GACA,eAAA,GACA,aAAA,GACA,gBAAA;AAAA,UAEa,gBAAA;EACf,IAAA;EACA,WAAA;EACA,SAAA;EACA,SAAA;EACA,MAAA;AAAA;AAAA,UAGe,gBAAA;EACf,IAAA;EACA,GAAA;EACA,EAAA;EACA,IAAA;AAAA;AAAA,UAGe,eAAA;EACf,IAAA;EACA,QAAA;EACA,QAAA;AAAA;AAAA,UAGe,aAAA;EACf,IAAA;EACA,IAAA;EACA,IAAA;EACA,QAAA;EACA,QAAA;EACA,QAAA;EACA,OAAA;AAAA;AAAA,UAGe,gBAAA;EACf,IAAA;EACA,WAAA;EACA,OAAA,EAAS,MAAA;AAAA"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface CreateConnectionsClientOptions {
|
|
3
|
+
transport: ConnectionsTransport;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
logger?: ConnectionsLogger;
|
|
7
|
+
}
|
|
8
|
+
interface ConnectionsClient {
|
|
9
|
+
getConnection(name: string): Promise<ConnectionResult>;
|
|
10
|
+
getConnection(options: GetConnectionOptions): Promise<ConnectionResult>;
|
|
11
|
+
}
|
|
12
|
+
interface GetConnectionOptions {
|
|
13
|
+
connectionName: string;
|
|
14
|
+
}
|
|
15
|
+
interface ConnectionsLogger {
|
|
16
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
17
|
+
}
|
|
18
|
+
interface ConnectionsTransport {
|
|
19
|
+
request<T>(request: ConnectionsRequest): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
interface ConnectionsRequest {
|
|
22
|
+
method: 'GET';
|
|
23
|
+
path: string;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
}
|
|
26
|
+
interface ApiEnvelope<T> {
|
|
27
|
+
status_code: string;
|
|
28
|
+
error_msg?: string;
|
|
29
|
+
data?: T;
|
|
30
|
+
}
|
|
31
|
+
type ConnectionResult = ConnectedConnection | NotConnectedConnection;
|
|
32
|
+
interface ConnectedConnection {
|
|
33
|
+
state: 'connected';
|
|
34
|
+
value: ConnectionValue;
|
|
35
|
+
issuedAt: string;
|
|
36
|
+
issuanceId: string;
|
|
37
|
+
}
|
|
38
|
+
interface NotConnectedConnection {
|
|
39
|
+
state: 'not_connected';
|
|
40
|
+
reason: 'first_time' | 'expired' | 'revoked' | 'refresh_failed' | 'outdated';
|
|
41
|
+
recoveryHint: 'authorize' | 'admin_reauthorize';
|
|
42
|
+
requiredScopes?: string[];
|
|
43
|
+
consoleUrl?: string;
|
|
44
|
+
}
|
|
45
|
+
type ConnectionValue = OAuth2Connection | ApiKeyConnection | BasicConnection | RdbConnection | CustomConnection;
|
|
46
|
+
interface OAuth2Connection {
|
|
47
|
+
type: 'oauth2';
|
|
48
|
+
accessToken: string;
|
|
49
|
+
tokenType: 'Bearer';
|
|
50
|
+
expiresAt?: string;
|
|
51
|
+
scopes?: string[];
|
|
52
|
+
}
|
|
53
|
+
interface ApiKeyConnection {
|
|
54
|
+
type: 'api_key';
|
|
55
|
+
key: string;
|
|
56
|
+
in: 'header' | 'query';
|
|
57
|
+
name: string;
|
|
58
|
+
}
|
|
59
|
+
interface BasicConnection {
|
|
60
|
+
type: 'basic';
|
|
61
|
+
username: string;
|
|
62
|
+
password: string;
|
|
63
|
+
}
|
|
64
|
+
interface RdbConnection {
|
|
65
|
+
type: 'rdb';
|
|
66
|
+
host: string;
|
|
67
|
+
port: number;
|
|
68
|
+
username: string;
|
|
69
|
+
password: string;
|
|
70
|
+
database?: string;
|
|
71
|
+
sslMode?: string;
|
|
72
|
+
}
|
|
73
|
+
interface CustomConnection {
|
|
74
|
+
type: 'custom';
|
|
75
|
+
payloadType: string;
|
|
76
|
+
payload: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { ApiEnvelope, ApiKeyConnection, BasicConnection, ConnectedConnection, ConnectionResult, ConnectionValue, ConnectionsClient, ConnectionsLogger, ConnectionsRequest, ConnectionsTransport, CreateConnectionsClientOptions, CustomConnection, GetConnectionOptions, NotConnectedConnection, OAuth2Connection, RdbConnection };
|
|
80
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";UAAiB,8BAAA;EACf,SAAA,EAAW,oBAAA;EACX,SAAA;EACA,KAAA;EACA,MAAA,GAAS,iBAAA;AAAA;AAAA,UAGM,iBAAA;EACf,aAAA,CAAc,IAAA,WAAe,OAAA,CAAQ,gBAAA;EACrC,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,OAAA,CAAQ,gBAAA;AAAA;AAAA,UAGvC,oBAAA;EACf,cAAA;AAAA;AAAA,UAGe,iBAAA;EACf,KAAA,CAAM,OAAA,UAAiB,IAAA,GAAO,MAAA;AAAA;AAAA,UAGf,oBAAA;EACf,OAAA,IAAW,OAAA,EAAS,kBAAA,GAAqB,OAAA,CAAQ,CAAA;AAAA;AAAA,UAGlC,kBAAA;EACf,MAAA;EACA,IAAA;EACA,SAAA;AAAA;AAAA,UAGe,WAAA;EACf,WAAA;EACA,SAAA;EACA,IAAA,GAAO,CAAA;AAAA;AAAA,KAGG,gBAAA,GAAmB,mBAAA,GAAsB,sBAAA;AAAA,UAEpC,mBAAA;EACf,KAAA;EACA,KAAA,EAAO,eAAA;EACP,QAAA;EACA,UAAA;AAAA;AAAA,UAGe,sBAAA;EACf,KAAA;EACA,MAAA;EACA,YAAA;EACA,cAAA;EACA,UAAA;AAAA;AAAA,KAGU,eAAA,GACR,gBAAA,GACA,gBAAA,GACA,eAAA,GACA,aAAA,GACA,gBAAA;AAAA,UAEa,gBAAA;EACf,IAAA;EACA,WAAA;EACA,SAAA;EACA,SAAA;EACA,MAAA;AAAA;AAAA,UAGe,gBAAA;EACf,IAAA;EACA,GAAA;EACA,EAAA;EACA,IAAA;AAAA;AAAA,UAGe,eAAA;EACf,IAAA;EACA,QAAA;EACA,QAAA;AAAA;AAAA,UAGe,aAAA;EACf,IAAA;EACA,IAAA;EACA,IAAA;EACA,QAAA;EACA,QAAA;EACA,QAAA;EACA,OAAA;AAAA;AAAA,UAGe,gBAAA;EACf,IAAA;EACA,WAAA;EACA,OAAA,EAAS,MAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lark-apaas/miaoda-connections-sdk",
|
|
3
|
+
"version": "0.1.1-alpha.0",
|
|
4
|
+
"description": "Miaoda server runtime SDK for connections",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.mts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"miaoda",
|
|
15
|
+
"connections",
|
|
16
|
+
"server",
|
|
17
|
+
"typescript"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18.0.0"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/index.d.mts",
|
|
29
|
+
"default": "./dist/index.mjs"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/index.d.cts",
|
|
33
|
+
"default": "./dist/index.cjs"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsdown",
|
|
40
|
+
"dev": "tsdown --watch",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"test": "vitest run --root ../../.. packages/server/miaoda-connections-sdk/src",
|
|
43
|
+
"test:watch": "vitest",
|
|
44
|
+
"prepublishOnly": "npm run build"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@lark-apaas/nestjs-common": "^0.1.8"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@nestjs/common": "^10.4.20",
|
|
51
|
+
"@nestjs/core": "^10.4.20",
|
|
52
|
+
"@types/node": "^22.0.0",
|
|
53
|
+
"reflect-metadata": "^0.1.13",
|
|
54
|
+
"rxjs": "^7.8.0",
|
|
55
|
+
"tsdown": "^0.21.0",
|
|
56
|
+
"typescript": "^5.9.2",
|
|
57
|
+
"vitest": "^3.2.4"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@nestjs/common": "^10.4.20",
|
|
61
|
+
"@nestjs/core": "^10.4.20",
|
|
62
|
+
"reflect-metadata": "^0.1.13",
|
|
63
|
+
"rxjs": "^7.8.0"
|
|
64
|
+
}
|
|
65
|
+
}
|