@superdurable/connector-bmob 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/dex-connector.json +60 -0
- package/dist/index.d.ts +160 -0
- package/dist/index.js +303 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Bmob TypeScript connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@superdurable/connector-bmob` provides `countClassObjects`, a read-only Query that returns the count for one Bmob class without reading records. The host resolves the application ID and REST API key for each call; they never enter Flow input or persisted output.
|
|
4
|
+
|
|
5
|
+
The runnable [class count example](examples/class-count/README.md) binds the static `bmob` connection. Configure the app-specific API origin and credentials in Dex Web Connections using `connector.yaml` guidance. The package replays Go provider scenarios for successful counts, rejections, malformed responses, bounded reads, rate limits, and transport failures. Its integration test exercises a real Dex Worker and Client against a local provider fake. A real Bmob application and authorization have not been verified.
|
|
6
|
+
|
|
7
|
+
Install with `npm install @superdurable/connector-bmob`. `BmobClient` validates its configured API origin and request limits during construction. `newProjectConnection` loads the named project connection. Normal Flows use the generated `newCountClassObjectsStep` factory; `BmobClientOptions.send` supports an approved transport or deterministic test sender.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "bmob",
|
|
3
|
+
"releaseTag": "connectors/bmob/go/v0.1.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "npm",
|
|
6
|
+
"name": "@superdurable/connector-bmob",
|
|
7
|
+
"version": "0.1.1"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "newCountClassObjectsStep",
|
|
12
|
+
"kind": "query",
|
|
13
|
+
"operationId": "countClassObjects",
|
|
14
|
+
"inputType": "CountClassObjectsInput",
|
|
15
|
+
"description": "Count objects in one Bmob class without returning records.",
|
|
16
|
+
"fields": {
|
|
17
|
+
"stepType": "stepType",
|
|
18
|
+
"annotations": "annotations",
|
|
19
|
+
"connectionName": "connectionName",
|
|
20
|
+
"resultAttribute": "resultAttribute"
|
|
21
|
+
},
|
|
22
|
+
"branches": [
|
|
23
|
+
{
|
|
24
|
+
"id": "counted",
|
|
25
|
+
"field": "counted",
|
|
26
|
+
"optional": false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "providerRejected",
|
|
30
|
+
"field": "providerRejected",
|
|
31
|
+
"optional": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "invalidResponse",
|
|
35
|
+
"field": "invalidResponse",
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "defect",
|
|
40
|
+
"field": "defect",
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"inputSchema": {
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"description": "CountClassObjectsInput identifies one existing Bmob class.",
|
|
47
|
+
"properties": {
|
|
48
|
+
"className": {
|
|
49
|
+
"description": "ClassName is the case-sensitive Bmob class name from the app's Data console.",
|
|
50
|
+
"type": "string"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"required": [
|
|
54
|
+
"className"
|
|
55
|
+
],
|
|
56
|
+
"type": "object"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
|
|
3
|
+
import { CredentialProvider, SecretString, QueryDefinition, Query, ConnectionRef, QueryStepConfig, QueryResult, QueryStep, Call, QueryAttempt } from '@superdurable/connectors-sdk';
|
|
4
|
+
import { StepTarget } from '@superdurable/dex';
|
|
5
|
+
import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
|
|
6
|
+
import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
|
|
7
|
+
|
|
8
|
+
/** Connector configuration; omitted fields use manifest defaults. */
|
|
9
|
+
interface Config {
|
|
10
|
+
/** Required HTTPS API domain for your Bmob application. In https://www.bmobapp.com/ open your app > 控制台 > 应用设置 > 域名管理 > API域名; copy its root URL without /1. Blank is invalid; do not use another app's domain. */
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
/** Maximum time for one class count as a positive Go duration, such as 5s or 1m. Leave blank for the displayed default; raise only for a slow approved proxy. Runtime value in milliseconds. */
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
/** Maximum Bmob response size in bytes as a positive integer. Leave blank for the displayed default; raise only if a legitimate count response exceeds it. */
|
|
15
|
+
maxResponseBytes?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Runtime schema for manifest configuration. */
|
|
18
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
19
|
+
baseUrl: z.ZodString;
|
|
20
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
maxResponseBytes: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
/** Private connector credentials resolved by the host. */
|
|
24
|
+
interface Credentials {
|
|
25
|
+
/** Application ID from https://www.bmobapp.com/ > your app > 设置 > 应用密钥. Copy the exact ID for this app; Dex stores it only as a credential. Blank prevents requests. */
|
|
26
|
+
applicationId: SecretString;
|
|
27
|
+
/** REST API Key paired with the Application ID at https://www.bmobapp.com/ > your app > 设置 > 应用密钥. Copy its exact string, never Master Key; Dex stores it only as a credential. Blank prevents requests. */
|
|
28
|
+
restApiKey: SecretString;
|
|
29
|
+
}
|
|
30
|
+
/** Stored credential material that fails the connector credential checks, so no retry can succeed. */
|
|
31
|
+
declare class CredentialMaterialError extends TypeError {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
/** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
|
|
35
|
+
declare function isCredentialMaterialError(error: unknown): boolean;
|
|
36
|
+
/** Decode private credential fields for the connector. */
|
|
37
|
+
declare function decodeCredentials(value: unknown): Credentials;
|
|
38
|
+
/** Host-owned source of private connector credentials. */
|
|
39
|
+
type CredentialSource = CredentialProvider<Credentials>;
|
|
40
|
+
/** CountClassObjectsInput identifies one existing Bmob class. */
|
|
41
|
+
interface CountClassObjectsInput {
|
|
42
|
+
/** ClassName is the case-sensitive Bmob class name from the app's Data console. */
|
|
43
|
+
"className": string;
|
|
44
|
+
}
|
|
45
|
+
/** CountClassObjectsOutput contains the count without object fields or identifiers. */
|
|
46
|
+
interface CountClassObjectsOutput {
|
|
47
|
+
/** Count is the number of objects matching the class, as returned by Bmob. */
|
|
48
|
+
"count": number;
|
|
49
|
+
}
|
|
50
|
+
/** Runtime validator for CountClassObjectsInput. */
|
|
51
|
+
declare const CountClassObjectsInputSchema: z.ZodObject<{
|
|
52
|
+
className: z.ZodString;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
/** Runtime validator for CountClassObjectsOutput. */
|
|
55
|
+
declare const CountClassObjectsOutputSchema: z.ZodObject<{
|
|
56
|
+
count: z.ZodNumber;
|
|
57
|
+
}, z.core.$strict>;
|
|
58
|
+
|
|
59
|
+
/** Stable connector identity. */
|
|
60
|
+
declare const ConnectorID = "bmob";
|
|
61
|
+
/** Provider identity for named connections. */
|
|
62
|
+
declare const ProviderID = "bmob";
|
|
63
|
+
/** Branch IDs for countClassObjects. */
|
|
64
|
+
declare const CountClassObjectsBranch: {
|
|
65
|
+
readonly Counted: "counted";
|
|
66
|
+
readonly ProviderRejected: "providerRejected";
|
|
67
|
+
readonly InvalidResponse: "invalidResponse";
|
|
68
|
+
readonly Defect: "defect";
|
|
69
|
+
};
|
|
70
|
+
/** Bmob returned the class object count. */
|
|
71
|
+
declare const CountClassObjectsBranchCounted: "counted";
|
|
72
|
+
/** Bmob rejected credentials, class access, or the class name. */
|
|
73
|
+
declare const CountClassObjectsBranchProviderRejected: "providerRejected";
|
|
74
|
+
/** Bmob returned malformed or oversized data. */
|
|
75
|
+
declare const CountClassObjectsBranchInvalidResponse: "invalidResponse";
|
|
76
|
+
/** Local input or connection configuration is invalid. */
|
|
77
|
+
declare const CountClassObjectsBranchDefect: "defect";
|
|
78
|
+
/** Manifest definition for countClassObjects. */
|
|
79
|
+
declare const CountClassObjectsDefinition: QueryDefinition;
|
|
80
|
+
/** Manifest metadata for countClassObjects. */
|
|
81
|
+
declare const CountClassObjectsMetadata: {
|
|
82
|
+
readonly kind: "query";
|
|
83
|
+
readonly idempotency: "none";
|
|
84
|
+
readonly authorization: "required";
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Typed operations supplied by a client or mock. */
|
|
88
|
+
interface Operations {
|
|
89
|
+
/** Invoke countClassObjects through this connection. */
|
|
90
|
+
countClassObjects(): Query<CountClassObjectsInput, CountClassObjectsOutput>;
|
|
91
|
+
}
|
|
92
|
+
/** Named connector connection kept outside Flow state. */
|
|
93
|
+
declare class Connection<BoundOperations = Operations> {
|
|
94
|
+
/** Stable provider and connection name. */
|
|
95
|
+
readonly reference: ConnectionRef;
|
|
96
|
+
/** Bound provider operations. */
|
|
97
|
+
readonly operations: BoundOperations;
|
|
98
|
+
/** Validate a reference and bind operations. */
|
|
99
|
+
constructor(reference: ConnectionRef, operations: BoundOperations);
|
|
100
|
+
}
|
|
101
|
+
/** Bind a client to a named connection. */
|
|
102
|
+
declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
|
|
103
|
+
/** Bind scripted operations to a named connection. */
|
|
104
|
+
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
105
|
+
|
|
106
|
+
/** Configuration for the countClassObjects connector Step. */
|
|
107
|
+
interface CountClassObjectsStepConfig<StepInput, OperationInput = CountClassObjectsInput, OperationOutput = CountClassObjectsOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
108
|
+
/** Named connection supplying this operation. */
|
|
109
|
+
connection: Connection<{
|
|
110
|
+
countClassObjects(): Query<OperationInput, OperationOutput>;
|
|
111
|
+
}>;
|
|
112
|
+
/** Name matching the bound connection. */
|
|
113
|
+
connectionName: string;
|
|
114
|
+
/** Bmob returned the class object count. */
|
|
115
|
+
counted: StepTarget<QueryResult<OperationOutput>>;
|
|
116
|
+
/** Bmob rejected credentials, class access, or the class name. */
|
|
117
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
118
|
+
/** Bmob returned malformed or oversized data. */
|
|
119
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
120
|
+
/** Local input or connection configuration is invalid. */
|
|
121
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
122
|
+
}
|
|
123
|
+
/** Build the countClassObjects Step from a named connection. */
|
|
124
|
+
declare function newCountClassObjectsStep<StepInput, OperationInput = CountClassObjectsInput, OperationOutput = CountClassObjectsOutput>(configuration: CountClassObjectsStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
125
|
+
|
|
126
|
+
/** Provider transport override for tests and approved gateways. */
|
|
127
|
+
interface BmobClientOptions {
|
|
128
|
+
send?: (request: ProviderRequest) => Promise<ProviderResponse>;
|
|
129
|
+
}
|
|
130
|
+
/** Bmob REST client for count-only class queries. */
|
|
131
|
+
declare class BmobClient {
|
|
132
|
+
private readonly credentials;
|
|
133
|
+
private readonly baseURL;
|
|
134
|
+
private readonly timeoutMs;
|
|
135
|
+
private readonly maxResponseBytes;
|
|
136
|
+
private readonly send;
|
|
137
|
+
/** Validate the app-specific API origin and request limits. */
|
|
138
|
+
constructor(config: Config, credentials: CredentialSource, options?: BmobClientOptions);
|
|
139
|
+
/** Bind the countClassObjects Query. */ countClassObjects(): CountClassObjectsOperation;
|
|
140
|
+
/** Send one count-only request with credentials resolved per call. */
|
|
141
|
+
requestCount(call: Call, className: string): Promise<{
|
|
142
|
+
response?: ProviderResponse;
|
|
143
|
+
tooLarge?: boolean;
|
|
144
|
+
credentialFailed?: boolean;
|
|
145
|
+
transportFailed?: boolean;
|
|
146
|
+
}>;
|
|
147
|
+
}
|
|
148
|
+
/** Read the number of objects in one named Bmob class. */
|
|
149
|
+
declare class CountClassObjectsOperation implements Query<CountClassObjectsInput, CountClassObjectsOutput> {
|
|
150
|
+
private readonly client;
|
|
151
|
+
/** Bind the client. */ constructor(client: BmobClient);
|
|
152
|
+
/** Return the generated Query definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
|
|
153
|
+
/** Classify one count request without reading object contents. */
|
|
154
|
+
invoke(call: Call, input: CountClassObjectsInput): Promise<QueryAttempt<CountClassObjectsOutput>>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Open a named Bmob connection using generated private and shared credential decoders. */
|
|
158
|
+
declare function newProjectConnection(project: LoadedProject, connectionName: string, options?: BmobClientOptions): Connection<Operations>;
|
|
159
|
+
|
|
160
|
+
export { BmobClient, type BmobClientOptions, type Config, ConfigSchema, Connection, ConnectorID, CountClassObjectsBranch, CountClassObjectsBranchCounted, CountClassObjectsBranchDefect, CountClassObjectsBranchInvalidResponse, CountClassObjectsBranchProviderRejected, CountClassObjectsDefinition, type CountClassObjectsInput, CountClassObjectsInputSchema, CountClassObjectsMetadata, CountClassObjectsOperation, type CountClassObjectsOutput, CountClassObjectsOutputSchema, type CountClassObjectsStepConfig, CredentialMaterialError, type CredentialSource, type Credentials, ProviderID, decodeCredentials, isCredentialMaterialError, newConnection, newConnectionWithOperations, newCountClassObjectsStep, newProjectConnection };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// src/generated/models.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
4
|
+
var ConfigSchema = z.object({
|
|
5
|
+
"baseUrl": z.string(),
|
|
6
|
+
"timeoutMs": z.number().int().optional(),
|
|
7
|
+
"maxResponseBytes": z.number().int().optional()
|
|
8
|
+
});
|
|
9
|
+
var CredentialMaterialError = class extends TypeError {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "CredentialMaterialError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
|
|
16
|
+
"project credential decoding failed",
|
|
17
|
+
"shared project credential decoding failed",
|
|
18
|
+
"project credential decoding failed: this connector version does not support shared credentials"
|
|
19
|
+
]);
|
|
20
|
+
function isCredentialMaterialError(error) {
|
|
21
|
+
return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
|
|
22
|
+
}
|
|
23
|
+
function decodeCredentials(value) {
|
|
24
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
|
|
25
|
+
const fields = value;
|
|
26
|
+
const allowed = /* @__PURE__ */ new Set(["application_id", "rest_api_key"]);
|
|
27
|
+
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
|
|
28
|
+
if (fields["application_id"] != null && !(typeof fields["application_id"] === "string")) throw new CredentialMaterialError("credential application_id has an invalid type");
|
|
29
|
+
if (fields["rest_api_key"] != null && !(typeof fields["rest_api_key"] === "string")) throw new CredentialMaterialError("credential rest_api_key has an invalid type");
|
|
30
|
+
const credentials = {};
|
|
31
|
+
if (!fields["application_id"]) throw new CredentialMaterialError("credential application_id is required");
|
|
32
|
+
credentials.applicationId = new SecretString(fields["application_id"] ?? "");
|
|
33
|
+
if (!fields["rest_api_key"]) throw new CredentialMaterialError("credential rest_api_key is required");
|
|
34
|
+
credentials.restApiKey = new SecretString(fields["rest_api_key"] ?? "");
|
|
35
|
+
return credentials;
|
|
36
|
+
}
|
|
37
|
+
var CountClassObjectsInputSchema = z.strictObject({
|
|
38
|
+
"className": z.string()
|
|
39
|
+
});
|
|
40
|
+
var CountClassObjectsOutputSchema = z.strictObject({
|
|
41
|
+
"count": z.number().int()
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// src/generated/definitions.ts
|
|
45
|
+
var ConnectorID = "bmob";
|
|
46
|
+
var ProviderID = "bmob";
|
|
47
|
+
var CountClassObjectsBranch = {
|
|
48
|
+
Counted: "counted",
|
|
49
|
+
ProviderRejected: "providerRejected",
|
|
50
|
+
InvalidResponse: "invalidResponse",
|
|
51
|
+
Defect: "defect"
|
|
52
|
+
};
|
|
53
|
+
var CountClassObjectsBranchCounted = CountClassObjectsBranch.Counted;
|
|
54
|
+
var CountClassObjectsBranchProviderRejected = CountClassObjectsBranch.ProviderRejected;
|
|
55
|
+
var CountClassObjectsBranchInvalidResponse = CountClassObjectsBranch.InvalidResponse;
|
|
56
|
+
var CountClassObjectsBranchDefect = CountClassObjectsBranch.Defect;
|
|
57
|
+
var CountClassObjectsDefinition = {
|
|
58
|
+
operation: { connectorId: ConnectorID, operationId: "countClassObjects" },
|
|
59
|
+
branches: [
|
|
60
|
+
{ id: "counted", description: "Bmob returned the class object count." },
|
|
61
|
+
{ id: "providerRejected", description: "Bmob rejected credentials, class access, or the class name.", optional: true },
|
|
62
|
+
{ id: "invalidResponse", description: "Bmob returned malformed or oversized data.", optional: true },
|
|
63
|
+
{ id: "defect", description: "Local input or connection configuration is invalid.", optional: true }
|
|
64
|
+
],
|
|
65
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
66
|
+
};
|
|
67
|
+
var CountClassObjectsMetadata = { kind: "query", idempotency: "none", authorization: "required" };
|
|
68
|
+
|
|
69
|
+
// src/generated/steps.ts
|
|
70
|
+
import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
|
|
71
|
+
function newCountClassObjectsStep(configuration) {
|
|
72
|
+
const { connection, connectionName, counted, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
73
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
74
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.countClassObjects(), connection: connection.reference, branches: [
|
|
75
|
+
goToBranch("counted", counted),
|
|
76
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
77
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
78
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
79
|
+
] });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/generated/connection.ts
|
|
83
|
+
import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
|
|
84
|
+
var Connection = class {
|
|
85
|
+
/** Stable provider and connection name. */
|
|
86
|
+
reference;
|
|
87
|
+
/** Bound provider operations. */
|
|
88
|
+
operations;
|
|
89
|
+
/** Validate a reference and bind operations. */
|
|
90
|
+
constructor(reference, operations) {
|
|
91
|
+
this.reference = ConnectionRefSchema.parse(reference);
|
|
92
|
+
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
93
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
94
|
+
this.operations = operations;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function newConnection(client, reference) {
|
|
98
|
+
if (!client) throw new TypeError("connector client is required");
|
|
99
|
+
return new Connection(reference, client);
|
|
100
|
+
}
|
|
101
|
+
function newConnectionWithOperations(operations, reference) {
|
|
102
|
+
return new Connection(reference, operations);
|
|
103
|
+
}
|
|
104
|
+
function newProjectConnection(project, connectionName, createClient) {
|
|
105
|
+
if (!project) throw new TypeError("loaded project is required");
|
|
106
|
+
const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
107
|
+
const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
|
|
108
|
+
if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
|
|
109
|
+
return newConnection(createClient(project, connectionName), reference);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/client.ts
|
|
113
|
+
import { isIP } from "net";
|
|
114
|
+
import { newQueryBranch, newQueryRetry, SecretString as SecretString2, zeroReceipt } from "@superdurable/connectors-sdk";
|
|
115
|
+
import { BodyTooLargeError, parseRetryAfter, sendProviderRequest } from "@superdurable/connectors-sdk/providerhttp";
|
|
116
|
+
var BmobClient = class {
|
|
117
|
+
/** Validate the app-specific API origin and request limits. */
|
|
118
|
+
constructor(config, credentials, options = {}) {
|
|
119
|
+
this.credentials = credentials;
|
|
120
|
+
if (!config || !credentials) throw new TypeError("Bmob configuration and credential source are required");
|
|
121
|
+
const url = new URL(config.baseUrl);
|
|
122
|
+
const hostname = url.hostname.toLowerCase();
|
|
123
|
+
const isLoopback = hostname === "localhost" || isIP(hostname) === 4 && hostname.startsWith("127.") || hostname === "[::1]";
|
|
124
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && isLoopback) || url.username || url.password || url.search || url.hash || url.pathname !== "/")
|
|
125
|
+
throw new TypeError("Bmob API URL must be an HTTPS origin or loopback test origin");
|
|
126
|
+
this.baseURL = url.origin;
|
|
127
|
+
this.timeoutMs = config.timeoutMs ?? 1e4;
|
|
128
|
+
this.maxResponseBytes = config.maxResponseBytes ?? 65536;
|
|
129
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0)
|
|
130
|
+
throw new TypeError("Bmob request limits are invalid");
|
|
131
|
+
this.send = options.send ?? sendProviderRequest;
|
|
132
|
+
}
|
|
133
|
+
credentials;
|
|
134
|
+
baseURL;
|
|
135
|
+
timeoutMs;
|
|
136
|
+
maxResponseBytes;
|
|
137
|
+
send;
|
|
138
|
+
/** Bind the countClassObjects Query. */
|
|
139
|
+
countClassObjects() {
|
|
140
|
+
return new CountClassObjectsOperation(this);
|
|
141
|
+
}
|
|
142
|
+
/** Send one count-only request with credentials resolved per call. */
|
|
143
|
+
async requestCount(call, className) {
|
|
144
|
+
let applicationId;
|
|
145
|
+
let restApiKey;
|
|
146
|
+
try {
|
|
147
|
+
const credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
148
|
+
applicationId = credentials.applicationId instanceof SecretString2 ? credentials.applicationId.reveal() : "";
|
|
149
|
+
restApiKey = credentials.restApiKey instanceof SecretString2 ? credentials.restApiKey.reveal() : "";
|
|
150
|
+
} catch {
|
|
151
|
+
return { credentialFailed: true };
|
|
152
|
+
}
|
|
153
|
+
if (!validCredential(applicationId) || !validCredential(restApiKey)) return { credentialFailed: true };
|
|
154
|
+
const url = new URL(`${this.baseURL}/1/classes/${className}`);
|
|
155
|
+
url.searchParams.set("count", "1");
|
|
156
|
+
url.searchParams.set("limit", "0");
|
|
157
|
+
const request = {
|
|
158
|
+
url: url.toString(),
|
|
159
|
+
method: "GET",
|
|
160
|
+
headers: { Accept: "application/json", "X-Bmob-Application-Id": applicationId, "X-Bmob-REST-API-Key": restApiKey },
|
|
161
|
+
timeoutMs: this.timeoutMs,
|
|
162
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
163
|
+
addressPolicy: this.baseURL.startsWith("https:") ? "publicHTTPS" : "privateNetworkHTTP",
|
|
164
|
+
signal: call.context.cancellationSignal
|
|
165
|
+
};
|
|
166
|
+
try {
|
|
167
|
+
const response = await this.send(request);
|
|
168
|
+
return { response, tooLarge: response.body.length > this.maxResponseBytes };
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error instanceof BodyTooLargeError && error.status !== void 0)
|
|
171
|
+
return { response: { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() }, tooLarge: true };
|
|
172
|
+
return { transportFailed: true };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var CountClassObjectsOperation = class {
|
|
177
|
+
/** Bind the client. */
|
|
178
|
+
constructor(client) {
|
|
179
|
+
this.client = client;
|
|
180
|
+
}
|
|
181
|
+
client;
|
|
182
|
+
/** Return the generated Query definition. */
|
|
183
|
+
definition() {
|
|
184
|
+
return CountClassObjectsDefinition;
|
|
185
|
+
}
|
|
186
|
+
/** Classify one count request without reading object contents. */
|
|
187
|
+
async invoke(call, input) {
|
|
188
|
+
if (!validClassName(input.className)) return terminal("defect", "VALIDATION", "class name is invalid");
|
|
189
|
+
const result = await this.client.requestCount(call, input.className);
|
|
190
|
+
if (result.credentialFailed) return terminal("defect", "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
191
|
+
if (result.transportFailed || !result.response) return newQueryRetry(failure("AVAILABILITY", "Bmob request failed"));
|
|
192
|
+
const response = result.response;
|
|
193
|
+
const retryAfter = retryDelay(response);
|
|
194
|
+
if (response.status === 429) return newQueryRetry(failure("RATE_LIMIT", "Bmob rate limited the request"), retryAfter);
|
|
195
|
+
if (response.status === 408 || response.status >= 500) return newQueryRetry(failure("AVAILABILITY", "Bmob is temporarily unavailable"), retryAfter);
|
|
196
|
+
if (result.tooLarge) return terminal("invalidResponse", "RESPONSE_TOO_LARGE", "Bmob response exceeded the configured limit");
|
|
197
|
+
if (response.status !== 200) {
|
|
198
|
+
const kind = response.status === 401 ? "AUTHENTICATION" : response.status === 403 ? "AUTHORIZATION" : [400, 404].includes(response.status) ? "VALIDATION" : "PROVIDER_REJECTION";
|
|
199
|
+
return terminal("providerRejected", kind, `Bmob rejected the request with HTTP ${response.status}`);
|
|
200
|
+
}
|
|
201
|
+
let value;
|
|
202
|
+
try {
|
|
203
|
+
value = decodeProviderJSON(response.body);
|
|
204
|
+
} catch {
|
|
205
|
+
return terminal("invalidResponse", "PROTOCOL", "Bmob returned an invalid count response");
|
|
206
|
+
}
|
|
207
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return terminal("invalidResponse", "PROTOCOL", "Bmob returned an invalid count response");
|
|
208
|
+
const fields = value;
|
|
209
|
+
if (!Number.isSafeInteger(fields.count) || fields.count < 0 || !Array.isArray(fields.results) || fields.results.length !== 0)
|
|
210
|
+
return terminal("invalidResponse", "PROTOCOL", "Bmob returned an invalid count response");
|
|
211
|
+
return newQueryBranch("counted", { count: fields.count }, zeroReceipt());
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
function validClassName(value) {
|
|
215
|
+
return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_]{0,127}$/.test(value);
|
|
216
|
+
}
|
|
217
|
+
function validCredential(value) {
|
|
218
|
+
return value.length > 0 && value.length <= 512 && /^[!-~]+$/.test(value);
|
|
219
|
+
}
|
|
220
|
+
function failure(kind, message) {
|
|
221
|
+
return { kind, provider: "bmob", operation: "countClassObjects", message };
|
|
222
|
+
}
|
|
223
|
+
function terminal(branch, kind, message) {
|
|
224
|
+
return newQueryBranch(branch, { count: 0 }, zeroReceipt(), failure(kind, message));
|
|
225
|
+
}
|
|
226
|
+
function retryDelay(response) {
|
|
227
|
+
const value = Object.entries(response.headers).find(([name]) => name.toLowerCase() === "retry-after")?.[1];
|
|
228
|
+
return parseRetryAfter(Array.isArray(value) ? value[0] ?? "" : value ?? "") || 0;
|
|
229
|
+
}
|
|
230
|
+
function decodeProviderJSON(body) {
|
|
231
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body), (_key, value, context) => {
|
|
232
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) return Object.fromEntries(Object.entries(value).map(([key, field]) => [key.toLowerCase(), field]));
|
|
233
|
+
if (typeof value !== "number") return value;
|
|
234
|
+
const raw = context?.source ?? "";
|
|
235
|
+
if (raw.length > 20 || !/^-?\d+$/.test(raw)) return NaN;
|
|
236
|
+
if (Number.isSafeInteger(value)) return value;
|
|
237
|
+
const integer = BigInt(raw);
|
|
238
|
+
return integer >= -(1n << 63n) && integer < 1n << 63n ? value : NaN;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/project.ts
|
|
243
|
+
function newProjectConnection2(project, connectionName, options = {}) {
|
|
244
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
245
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "bmob" && entry.connectionName === name);
|
|
246
|
+
if (!selected) throw new TypeError("Bmob project connection is not configured");
|
|
247
|
+
const raw = selected.configuration;
|
|
248
|
+
const settings = ConfigSchema.parse({
|
|
249
|
+
...raw,
|
|
250
|
+
...raw.timeout !== void 0 ? { timeoutMs: typeof raw.timeout === "number" ? Math.ceil(raw.timeout / 1e6) : parseDurationMilliseconds(raw.timeout) } : {}
|
|
251
|
+
});
|
|
252
|
+
const config = {
|
|
253
|
+
baseUrl: settings.baseUrl,
|
|
254
|
+
...settings.timeoutMs !== void 0 ? { timeoutMs: settings.timeoutMs } : {},
|
|
255
|
+
...settings.maxResponseBytes !== void 0 ? { maxResponseBytes: settings.maxResponseBytes } : {}
|
|
256
|
+
};
|
|
257
|
+
const credentials = {
|
|
258
|
+
async resolve(call, signal) {
|
|
259
|
+
void call;
|
|
260
|
+
return decodeCredentials(await loadedProject.resolveCredential("bmob", name, signal));
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
return new BmobClient(config, credentials, options);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function parseDurationMilliseconds(value) {
|
|
267
|
+
if (typeof value !== "string") throw new TypeError("Bmob timeout must be a positive Go duration");
|
|
268
|
+
let remaining = value;
|
|
269
|
+
let milliseconds = 0;
|
|
270
|
+
const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
|
|
271
|
+
while (remaining) {
|
|
272
|
+
const component = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
|
|
273
|
+
if (!component) throw new TypeError("Bmob timeout must be a positive Go duration");
|
|
274
|
+
milliseconds += Number(component[1]) * (units[component[2] ?? ""] ?? NaN);
|
|
275
|
+
remaining = remaining.slice(component[0].length);
|
|
276
|
+
}
|
|
277
|
+
if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("Bmob timeout must resolve to positive whole milliseconds");
|
|
278
|
+
return milliseconds;
|
|
279
|
+
}
|
|
280
|
+
export {
|
|
281
|
+
BmobClient,
|
|
282
|
+
ConfigSchema,
|
|
283
|
+
Connection,
|
|
284
|
+
ConnectorID,
|
|
285
|
+
CountClassObjectsBranch,
|
|
286
|
+
CountClassObjectsBranchCounted,
|
|
287
|
+
CountClassObjectsBranchDefect,
|
|
288
|
+
CountClassObjectsBranchInvalidResponse,
|
|
289
|
+
CountClassObjectsBranchProviderRejected,
|
|
290
|
+
CountClassObjectsDefinition,
|
|
291
|
+
CountClassObjectsInputSchema,
|
|
292
|
+
CountClassObjectsMetadata,
|
|
293
|
+
CountClassObjectsOperation,
|
|
294
|
+
CountClassObjectsOutputSchema,
|
|
295
|
+
CredentialMaterialError,
|
|
296
|
+
ProviderID,
|
|
297
|
+
decodeCredentials,
|
|
298
|
+
isCredentialMaterialError,
|
|
299
|
+
newConnection,
|
|
300
|
+
newConnectionWithOperations,
|
|
301
|
+
newCountClassObjectsStep,
|
|
302
|
+
newProjectConnection2 as newProjectConnection
|
|
303
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-bmob",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Bmob connector for Dex TypeScript applications",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/superdurable/dex-connectors-library.git",
|
|
8
|
+
"directory": "connectors/bmob/typescript"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": "^22.0.0 || ^24.0.0"
|
|
17
|
+
},
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./dex-connector.json": "./dex-connector.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"dex-connector.json",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"lint": "eslint src test examples",
|
|
37
|
+
"test": "npm run build && vitest run --exclude 'test/integration/**'",
|
|
38
|
+
"test:integration": "npm run build && vitest run test/integration/*.integration.test.ts",
|
|
39
|
+
"check": "npm test && npm run typecheck && npm run lint",
|
|
40
|
+
"example:worker": "tsx examples/bmob/worker.ts",
|
|
41
|
+
"example:start": "tsx examples/bmob/start.ts"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@superdurable/connectors-sdk": "0.12.0",
|
|
45
|
+
"@superdurable/dex": ">=1.28.0",
|
|
46
|
+
"zod": "^4.1.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^9.0.0",
|
|
50
|
+
"@types/node": "^22.0.0",
|
|
51
|
+
"eslint": "^9.0.0",
|
|
52
|
+
"tsup": "^8.0.0",
|
|
53
|
+
"tsx": "^4.23.15",
|
|
54
|
+
"typescript": "^5.9.0",
|
|
55
|
+
"typescript-eslint": "^8.0.0",
|
|
56
|
+
"vitest": "^3.0.0",
|
|
57
|
+
"yaml": "^2.9.1"
|
|
58
|
+
},
|
|
59
|
+
"license": "MIT"
|
|
60
|
+
}
|