@superdurable/connector-moka 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,5 @@
1
- # Temporary Holding Version
1
+ # Moka TypeScript connector
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Look up country, province, city, district, and network operator for one public IPv4 address.
4
+
5
+ Install `@superdurable/connector-moka` and use `newProjectConnection` with the static connection name in the runnable [`examples/basic`](examples/basic) Flow. Configure the connection and provider credentials in Dex Web Connections. The operation `listJobFunctions` resolves credentials for each call. Local conformance tests replay the Go provider scenarios; live provider authorization has not been verified.
@@ -0,0 +1,52 @@
1
+ {
2
+ "connectorId": "moka",
3
+ "releaseTag": "connectors/moka/go/v0.1.0",
4
+ "package": {
5
+ "ecosystem": "npm",
6
+ "name": "@superdurable/connector-moka",
7
+ "version": "0.1.0"
8
+ },
9
+ "factories": [
10
+ {
11
+ "name": "newListJobFunctionsStep",
12
+ "kind": "query",
13
+ "operationId": "listJobFunctions",
14
+ "inputType": "ListJobFunctionsInput",
15
+ "description": "List recruitment job functions and counts for one organization and mode.",
16
+ "fields": {
17
+ "stepType": "stepType",
18
+ "annotations": "annotations",
19
+ "connectionName": "connectionName",
20
+ "resultAttribute": "resultAttribute"
21
+ },
22
+ "branches": [
23
+ {
24
+ "id": "found",
25
+ "field": "found",
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": "ListJobFunctionsInput has no user-supplied query parameters.",
47
+ "properties": {},
48
+ "type": "object"
49
+ }
50
+ }
51
+ ]
52
+ }
@@ -0,0 +1,122 @@
1
+ // src/generated/models.ts
2
+ import { z } from "zod";
3
+ import { SecretString } from "@superdurable/connectors-sdk";
4
+ var ConfigSchema = z.object({
5
+ "orgId": z.string(),
6
+ "mode": z.string().optional(),
7
+ "timeoutMs": z.number().int().optional(),
8
+ "maxResponseBytes": z.number().int().optional()
9
+ });
10
+ var CredentialMaterialError = class extends TypeError {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = "CredentialMaterialError";
14
+ }
15
+ };
16
+ var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
17
+ "project credential decoding failed",
18
+ "shared project credential decoding failed",
19
+ "project credential decoding failed: this connector version does not support shared credentials"
20
+ ]);
21
+ function isCredentialMaterialError(error) {
22
+ return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
23
+ }
24
+ function decodeCredentials(value) {
25
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
26
+ const fields = value;
27
+ const allowed = /* @__PURE__ */ new Set(["api_key"]);
28
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
29
+ if (fields["api_key"] != null && !(typeof fields["api_key"] === "string")) throw new CredentialMaterialError("credential api_key has an invalid type");
30
+ const credentials = {};
31
+ if (!fields["api_key"]) throw new CredentialMaterialError("credential api_key is required");
32
+ credentials.apiKey = new SecretString(fields["api_key"] ?? "");
33
+ return credentials;
34
+ }
35
+ var ListJobFunctionsInputSchema = z.strictObject({});
36
+ var JobFunctionSchema = z.strictObject({
37
+ "id": z.number().int(),
38
+ "label": z.string(),
39
+ "parentId": z.number().int(),
40
+ "jobCount": z.number().int()
41
+ });
42
+ var ListJobFunctionsOutputSchema = z.strictObject({
43
+ "functions": z.array(JobFunctionSchema).nullable()
44
+ });
45
+
46
+ // src/generated/definitions.ts
47
+ var ConnectorID = "moka";
48
+ var ProviderID = "moka";
49
+ var ListJobFunctionsBranch = {
50
+ Found: "found",
51
+ ProviderRejected: "providerRejected",
52
+ InvalidResponse: "invalidResponse",
53
+ Defect: "defect"
54
+ };
55
+ var ListJobFunctionsBranchFound = ListJobFunctionsBranch.Found;
56
+ var ListJobFunctionsBranchProviderRejected = ListJobFunctionsBranch.ProviderRejected;
57
+ var ListJobFunctionsBranchInvalidResponse = ListJobFunctionsBranch.InvalidResponse;
58
+ var ListJobFunctionsBranchDefect = ListJobFunctionsBranch.Defect;
59
+ var ListJobFunctionsDefinition = {
60
+ operation: { connectorId: ConnectorID, operationId: "listJobFunctions" },
61
+ branches: [
62
+ { id: "found", description: "Moka returned the job function list." },
63
+ { id: "providerRejected", description: "Moka rejected the job-function request.", optional: true },
64
+ { id: "invalidResponse", description: "Moka returned malformed or oversized data.", optional: true },
65
+ { id: "defect", description: "Local connection credentials or settings are invalid.", optional: true }
66
+ ],
67
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
68
+ };
69
+ var ListJobFunctionsMetadata = { kind: "query", idempotency: "none", authorization: "required" };
70
+
71
+ // src/generated/connection.ts
72
+ import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
73
+ var Connection = class {
74
+ /** Stable provider and connection name. */
75
+ reference;
76
+ /** Bound provider operations. */
77
+ operations;
78
+ /** Validate a reference and bind operations. */
79
+ constructor(reference, operations) {
80
+ this.reference = ConnectionRefSchema.parse(reference);
81
+ if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
82
+ if (!operations) throw new TypeError("connector operations are required");
83
+ this.operations = operations;
84
+ }
85
+ };
86
+ function newConnection(client, reference) {
87
+ if (!client) throw new TypeError("connector client is required");
88
+ return new Connection(reference, client);
89
+ }
90
+ function newConnectionWithOperations(operations, reference) {
91
+ return new Connection(reference, operations);
92
+ }
93
+ function newProjectConnection(project, connectionName, createClient) {
94
+ if (!project) throw new TypeError("loaded project is required");
95
+ const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
96
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
97
+ if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
98
+ return newConnection(createClient(project, connectionName), reference);
99
+ }
100
+
101
+ export {
102
+ ConfigSchema,
103
+ CredentialMaterialError,
104
+ isCredentialMaterialError,
105
+ decodeCredentials,
106
+ ListJobFunctionsInputSchema,
107
+ JobFunctionSchema,
108
+ ListJobFunctionsOutputSchema,
109
+ ConnectorID,
110
+ ProviderID,
111
+ ListJobFunctionsBranch,
112
+ ListJobFunctionsBranchFound,
113
+ ListJobFunctionsBranchProviderRejected,
114
+ ListJobFunctionsBranchInvalidResponse,
115
+ ListJobFunctionsBranchDefect,
116
+ ListJobFunctionsDefinition,
117
+ ListJobFunctionsMetadata,
118
+ Connection,
119
+ newConnection,
120
+ newConnectionWithOperations,
121
+ newProjectConnection
122
+ };
@@ -0,0 +1,94 @@
1
+ import { CredentialProvider, SecretString, Query, ConnectionRef } from '@superdurable/connectors-sdk';
2
+ import { z } from 'zod';
3
+
4
+ /** Connector configuration; omitted fields use manifest defaults. */
5
+ interface Config {
6
+ /** Organization ID from https://app.mokahr.com > Recruitment Website Management > copy your recruitment website link; use the segment after /apply/ in https://app.mokahr.com/apply/{orgId}/{siteId}. Enter that opaque ID without slashes. It is not secret; blank prevents requests. */
7
+ orgId: string;
8
+ /** Recruitment mode for this job-function query. Blank uses the displayed default for general recruiting; switch to the campus option when querying the campus recruitment website. */
9
+ mode?: string;
10
+ /** Maximum job-function request time as a positive Go duration such as 5s or 1m. Blank uses the displayed default; raise only for a slow approved network. Runtime value in milliseconds. */
11
+ timeoutMs?: number;
12
+ /** Maximum provider response size in bytes as a positive integer. Blank uses the displayed default; raise only when the organization has an unusually large function tree. */
13
+ maxResponseBytes?: number;
14
+ }
15
+ /** Runtime schema for manifest configuration. */
16
+ declare const ConfigSchema: z.ZodObject<{
17
+ orgId: z.ZodString;
18
+ mode: z.ZodOptional<z.ZodString>;
19
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
20
+ maxResponseBytes: z.ZodOptional<z.ZodNumber>;
21
+ }, z.core.$strip>;
22
+ /** Private connector credentials resolved by the host. */
23
+ interface Credentials {
24
+ /** Private API Key issued by your Moka Customer Success Manager; start at https://www.mokahr.com/docs/api/index.html#basic-auth and ask your CSM to issue or reset it. Copy the complete opaque key as a Dex secret. The connector sends it as the Basic Auth username with an empty password; blank prevents requests. */
25
+ apiKey: SecretString;
26
+ }
27
+ /** Stored credential material that fails the connector credential checks, so no retry can succeed. */
28
+ declare class CredentialMaterialError extends TypeError {
29
+ constructor(message: string);
30
+ }
31
+ /** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
32
+ declare function isCredentialMaterialError(error: unknown): boolean;
33
+ /** Decode private credential fields for the connector. */
34
+ declare function decodeCredentials(value: unknown): Credentials;
35
+ /** Host-owned source of private connector credentials. */
36
+ type CredentialSource = CredentialProvider<Credentials>;
37
+ /** ListJobFunctionsInput has no user-supplied query parameters. */
38
+ interface ListJobFunctionsInput {
39
+ }
40
+ /** JobFunction contains non-personal recruitment category metadata. */
41
+ interface JobFunction {
42
+ /** ID identifies the job function in Moka. */
43
+ "id": number;
44
+ /** Label is the job function's displayed name. */
45
+ "label": string;
46
+ /** ParentID identifies the parent function, or zero when Moka omits it. */
47
+ "parentId": number;
48
+ /** JobCount counts this function and its descendants' jobs. */
49
+ "jobCount": number;
50
+ }
51
+ /** ListJobFunctionsOutput contains the available recruitment functions. */
52
+ interface ListJobFunctionsOutput {
53
+ /** Functions contains only job function IDs, labels, parent IDs, and counts. */
54
+ "functions": Array<JobFunction> | null;
55
+ }
56
+ /** Runtime validator for ListJobFunctionsInput. */
57
+ declare const ListJobFunctionsInputSchema: z.ZodObject<{}, z.core.$strict>;
58
+ /** Runtime validator for JobFunction. */
59
+ declare const JobFunctionSchema: z.ZodObject<{
60
+ id: z.ZodNumber;
61
+ label: z.ZodString;
62
+ parentId: z.ZodNumber;
63
+ jobCount: z.ZodNumber;
64
+ }, z.core.$strict>;
65
+ /** Runtime validator for ListJobFunctionsOutput. */
66
+ declare const ListJobFunctionsOutputSchema: z.ZodObject<{
67
+ functions: z.ZodNullable<z.ZodArray<z.ZodObject<{
68
+ id: z.ZodNumber;
69
+ label: z.ZodString;
70
+ parentId: z.ZodNumber;
71
+ jobCount: z.ZodNumber;
72
+ }, z.core.$strict>>>;
73
+ }, z.core.$strict>;
74
+
75
+ /** Typed operations supplied by a client or mock. */
76
+ interface Operations {
77
+ /** Invoke listJobFunctions through this connection. */
78
+ listJobFunctions(): Query<ListJobFunctionsInput, ListJobFunctionsOutput>;
79
+ }
80
+ /** Named connector connection kept outside Flow state. */
81
+ declare class Connection<BoundOperations = Operations> {
82
+ /** Stable provider and connection name. */
83
+ readonly reference: ConnectionRef;
84
+ /** Bound provider operations. */
85
+ readonly operations: BoundOperations;
86
+ /** Validate a reference and bind operations. */
87
+ constructor(reference: ConnectionRef, operations: BoundOperations);
88
+ }
89
+ /** Bind a client to a named connection. */
90
+ declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
91
+ /** Bind scripted operations to a named connection. */
92
+ declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
93
+
94
+ export { Connection as C, type JobFunction as J, type ListJobFunctionsInput as L, type Operations as O, type ListJobFunctionsOutput as a, type Config as b, type Credentials as c, ConfigSchema as d, CredentialMaterialError as e, type CredentialSource as f, JobFunctionSchema as g, ListJobFunctionsInputSchema as h, ListJobFunctionsOutputSchema as i, decodeCredentials as j, isCredentialMaterialError as k, newConnectionWithOperations as l, newConnection as n };
@@ -0,0 +1,91 @@
1
+ import { L as ListJobFunctionsInput, a as ListJobFunctionsOutput, C as Connection, O as Operations, b as Config, c as Credentials } from './connection-BBLPbAP2.js';
2
+ export { d as ConfigSchema, e as CredentialMaterialError, f as CredentialSource, J as JobFunction, g as JobFunctionSchema, h as ListJobFunctionsInputSchema, i as ListJobFunctionsOutputSchema, j as decodeCredentials, k as isCredentialMaterialError, n as newConnection, l as newConnectionWithOperations } from './connection-BBLPbAP2.js';
3
+ import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, CredentialProvider, 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
+ import 'zod';
8
+
9
+ /** Stable connector identity. */
10
+ declare const ConnectorID = "moka";
11
+ /** Provider identity for named connections. */
12
+ declare const ProviderID = "moka";
13
+ /** Branch IDs for listJobFunctions. */
14
+ declare const ListJobFunctionsBranch: {
15
+ readonly Found: "found";
16
+ readonly ProviderRejected: "providerRejected";
17
+ readonly InvalidResponse: "invalidResponse";
18
+ readonly Defect: "defect";
19
+ };
20
+ /** Moka returned the job function list. */
21
+ declare const ListJobFunctionsBranchFound: "found";
22
+ /** Moka rejected the job-function request. */
23
+ declare const ListJobFunctionsBranchProviderRejected: "providerRejected";
24
+ /** Moka returned malformed or oversized data. */
25
+ declare const ListJobFunctionsBranchInvalidResponse: "invalidResponse";
26
+ /** Local connection credentials or settings are invalid. */
27
+ declare const ListJobFunctionsBranchDefect: "defect";
28
+ /** Manifest definition for listJobFunctions. */
29
+ declare const ListJobFunctionsDefinition: QueryDefinition;
30
+ /** Manifest metadata for listJobFunctions. */
31
+ declare const ListJobFunctionsMetadata: {
32
+ readonly kind: "query";
33
+ readonly idempotency: "none";
34
+ readonly authorization: "required";
35
+ };
36
+
37
+ /** Configuration for the listJobFunctions connector Step. */
38
+ interface ListJobFunctionsStepConfig<StepInput, OperationInput = ListJobFunctionsInput, OperationOutput = ListJobFunctionsOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
39
+ /** Named connection supplying this operation. */
40
+ connection: Connection<{
41
+ listJobFunctions(): Query<OperationInput, OperationOutput>;
42
+ }>;
43
+ /** Name matching the bound connection. */
44
+ connectionName: string;
45
+ /** Moka returned the job function list. */
46
+ found: StepTarget<QueryResult<OperationOutput>>;
47
+ /** Moka rejected the job-function request. */
48
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
49
+ /** Moka returned malformed or oversized data. */
50
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
51
+ /** Local connection credentials or settings are invalid. */
52
+ defect?: StepTarget<QueryResult<OperationOutput>>;
53
+ }
54
+ /** Build the listJobFunctions Step from a named connection. */
55
+ declare function newListJobFunctionsStep<StepInput, OperationInput = ListJobFunctionsInput, OperationOutput = ListJobFunctionsOutput>(configuration: ListJobFunctionsStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
56
+
57
+ /** Open one named Moka connection from Dex project configuration. */
58
+ declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
59
+
60
+ /** Optional HTTP transport for provider tests. */
61
+ interface MokaClientOptions {
62
+ send?: (request: ProviderRequest) => Promise<ProviderResponse>;
63
+ }
64
+ /** Resolve Moka credentials for each job-function query. */
65
+ declare class MokaClient {
66
+ private readonly credentials;
67
+ private readonly timeoutMs;
68
+ private readonly maxResponseBytes;
69
+ private readonly send;
70
+ private readonly orgId;
71
+ private readonly mode;
72
+ /** Validate settings without contacting Moka. */
73
+ constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: MokaClientOptions);
74
+ /** Bind the read-only job-function Query. */ listJobFunctions(): ListJobFunctionsOperation;
75
+ /** Send one bounded request. */
76
+ request(call: Call): Promise<{
77
+ response?: ProviderResponse;
78
+ error?: 'credential' | 'transport' | 'tooLarge';
79
+ retryAfterMs: number;
80
+ }>;
81
+ }
82
+ /** List recruitment job-function metadata. */
83
+ declare class ListJobFunctionsOperation implements Query<ListJobFunctionsInput, ListJobFunctionsOutput> {
84
+ private readonly client;
85
+ /** Bind the provider client. */ constructor(client: MokaClient);
86
+ /** Return the generated Query definition. */ definition(): QueryDefinition;
87
+ /** Classify the provider response using the Go contract. */
88
+ invoke(call: Call, _input: ListJobFunctionsInput): Promise<QueryAttempt<ListJobFunctionsOutput>>;
89
+ }
90
+
91
+ export { Config, Connection, ConnectorID, Credentials, ListJobFunctionsBranch, ListJobFunctionsBranchDefect, ListJobFunctionsBranchFound, ListJobFunctionsBranchInvalidResponse, ListJobFunctionsBranchProviderRejected, ListJobFunctionsDefinition, ListJobFunctionsInput, ListJobFunctionsMetadata, ListJobFunctionsOutput, type ListJobFunctionsStepConfig, MokaClient, type MokaClientOptions, ProviderID, newListJobFunctionsStep, newProjectConnection };
package/dist/index.js ADDED
@@ -0,0 +1,192 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ CredentialMaterialError,
6
+ JobFunctionSchema,
7
+ ListJobFunctionsBranch,
8
+ ListJobFunctionsBranchDefect,
9
+ ListJobFunctionsBranchFound,
10
+ ListJobFunctionsBranchInvalidResponse,
11
+ ListJobFunctionsBranchProviderRejected,
12
+ ListJobFunctionsDefinition,
13
+ ListJobFunctionsInputSchema,
14
+ ListJobFunctionsMetadata,
15
+ ListJobFunctionsOutputSchema,
16
+ ProviderID,
17
+ decodeCredentials,
18
+ isCredentialMaterialError,
19
+ newConnection,
20
+ newConnectionWithOperations,
21
+ newProjectConnection
22
+ } from "./chunk-XUFSKQRJ.js";
23
+
24
+ // src/generated/steps.ts
25
+ import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
26
+ function newListJobFunctionsStep(configuration) {
27
+ const { connection, connectionName, found, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
28
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
29
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listJobFunctions(), connection: connection.reference, branches: [
30
+ goToBranch("found", found),
31
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
32
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
33
+ ...defect ? [goToBranch("defect", defect)] : []
34
+ ] });
35
+ }
36
+
37
+ // src/client.ts
38
+ import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
39
+ import { BodyTooLargeError, parseRetryAfter, sendProviderRequest } from "@superdurable/connectors-sdk/providerhttp";
40
+ var empty = { functions: [] };
41
+ var MokaClient = class {
42
+ /** Validate settings without contacting Moka. */
43
+ constructor(config, credentials, options = {}) {
44
+ this.credentials = credentials;
45
+ if (!config || !credentials) throw new TypeError("Moka settings and credentials are required");
46
+ this.orgId = config.orgId;
47
+ this.mode = config.mode || "social";
48
+ this.timeoutMs = config.timeoutMs || 1e4;
49
+ this.maxResponseBytes = config.maxResponseBytes || 1048576;
50
+ if (!/^[A-Za-z0-9_-]{1,128}$/.test(this.orgId) || !["social", "campus"].includes(this.mode) || !Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0 || this.maxResponseBytes > 16 * 1024 * 1024) throw new TypeError("Moka settings are invalid");
51
+ this.send = options.send ?? sendProviderRequest;
52
+ }
53
+ credentials;
54
+ timeoutMs;
55
+ maxResponseBytes;
56
+ send;
57
+ orgId;
58
+ mode;
59
+ /** Bind the read-only job-function Query. */
60
+ listJobFunctions() {
61
+ return new ListJobFunctionsOperation(this);
62
+ }
63
+ /** Send one bounded request. */
64
+ async request(call) {
65
+ let apiKey = "";
66
+ try {
67
+ const resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
68
+ apiKey = resolved.apiKey instanceof SecretString ? resolved.apiKey.reveal() : "";
69
+ } catch {
70
+ return { error: "credential", retryAfterMs: 0 };
71
+ }
72
+ if (!apiKey || apiKey.length > 1024 || /[^\x21-\x7e]/.test(apiKey)) return { error: "credential", retryAfterMs: 0 };
73
+ const url = new URL(`https://api.mokahr.com/api-platform/v1/jobs-groupedby-zhineng/${encodeURIComponent(this.orgId)}`);
74
+ url.searchParams.set("mode", this.mode);
75
+ const request = { url: url.toString(), method: "GET", headers: { Accept: "application/json", Authorization: `Basic ${Buffer.from(`${apiKey}:`).toString("base64")}` }, timeoutMs: this.timeoutMs, maxResponseBytes: this.maxResponseBytes, addressPolicy: "publicHTTPS", signal: call.context.cancellationSignal };
76
+ let response;
77
+ try {
78
+ response = await this.send(request);
79
+ } catch (error) {
80
+ if (error instanceof BodyTooLargeError && error.status !== void 0) return { response: { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() }, error: "tooLarge", retryAfterMs: 0 };
81
+ return { error: "transport", retryAfterMs: 0 };
82
+ }
83
+ return { response, error: response.body.length > this.maxResponseBytes ? "tooLarge" : void 0, retryAfterMs: parseRetryAfter(header(response.headers, "retry-after")) };
84
+ }
85
+ };
86
+ var ListJobFunctionsOperation = class {
87
+ /** Bind the provider client. */
88
+ constructor(client) {
89
+ this.client = client;
90
+ }
91
+ client;
92
+ /** Return the generated Query definition. */
93
+ definition() {
94
+ return ListJobFunctionsDefinition;
95
+ }
96
+ /** Classify the provider response using the Go contract. */
97
+ async invoke(call, _input) {
98
+ void _input;
99
+ const exchange = await this.client.request(call);
100
+ if (exchange.error === "credential") return branch("defect", "AUTHENTICATION");
101
+ if (exchange.error === "transport" || !exchange.response) return retry("AVAILABILITY");
102
+ const { status, body } = exchange.response;
103
+ if (status === 429) return retry("RATE_LIMIT", exchange.retryAfterMs);
104
+ if (status === 408 || status >= 500) return retry("AVAILABILITY", exchange.retryAfterMs);
105
+ if (status !== 200) return branch("providerRejected", status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : "PROVIDER_REJECTION");
106
+ if (exchange.error === "tooLarge") return branch("invalidResponse", "RESPONSE_TOO_LARGE");
107
+ let wire;
108
+ try {
109
+ wire = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
110
+ } catch {
111
+ return branch("invalidResponse", "PROTOCOL");
112
+ }
113
+ if (!wire || typeof wire !== "object" || Array.isArray(wire) || !Array.isArray(wire.jobs)) return branch("invalidResponse", "PROTOCOL");
114
+ const jobs = wire.jobs;
115
+ const functions = [];
116
+ for (const item of jobs) {
117
+ if (!item || typeof item !== "object" || Array.isArray(item)) return branch("invalidResponse", "PROTOCOL");
118
+ const record = item;
119
+ if (!Number.isSafeInteger(record.id) || Number(record.id) <= 0 || typeof record.label !== "string" || !record.label || !Number.isSafeInteger(record.jobCount) || Number(record.jobCount) < 0 || record.parentId !== void 0 && (!Number.isSafeInteger(record.parentId) || Number(record.parentId) < 0)) return branch("invalidResponse", "PROTOCOL");
120
+ functions.push({ id: Number(record.id), label: record.label, parentId: Number(record.parentId ?? 0), jobCount: Number(record.jobCount) });
121
+ }
122
+ return newQueryBranch("found", { functions });
123
+ }
124
+ };
125
+ function header(headers, name) {
126
+ const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name)?.[1];
127
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
128
+ }
129
+ function failure(kind) {
130
+ return { provider: "moka", operation: "listJobFunctions", kind, message: "Moka job-function query failed" };
131
+ }
132
+ function branch(name, kind) {
133
+ return newQueryBranch(name, empty, {}, failure(kind));
134
+ }
135
+ function retry(kind, delay = 0) {
136
+ return newQueryRetry(failure(kind), delay);
137
+ }
138
+
139
+ // src/project.ts
140
+ function newProjectConnection2(project, connectionName) {
141
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
142
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "moka" && entry.connectionName === name);
143
+ if (!selected) throw new TypeError("Moka project connection is not configured");
144
+ const fields = selected.configuration;
145
+ const config = ConfigSchema.parse({ ...fields, ...fields.timeout !== void 0 ? { timeoutMs: parseDurationMilliseconds(fields.timeout) } : {} });
146
+ const credentials = {
147
+ async resolve(_call, signal) {
148
+ return decodeCredentials(await loadedProject.resolveCredential("moka", name, signal));
149
+ }
150
+ };
151
+ return new MokaClient(config, credentials);
152
+ });
153
+ }
154
+ function parseDurationMilliseconds(value) {
155
+ if (typeof value === "number") return Math.ceil(value / 1e6);
156
+ if (typeof value !== "string") throw new TypeError("timeout must be a duration");
157
+ let remaining = value;
158
+ let milliseconds = 0;
159
+ const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
160
+ while (remaining) {
161
+ const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
162
+ if (!part) throw new TypeError("timeout must be a positive Go duration");
163
+ milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
164
+ remaining = remaining.slice(part[0].length);
165
+ }
166
+ if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("timeout must resolve to positive whole milliseconds");
167
+ return milliseconds;
168
+ }
169
+ export {
170
+ ConfigSchema,
171
+ Connection,
172
+ ConnectorID,
173
+ CredentialMaterialError,
174
+ JobFunctionSchema,
175
+ ListJobFunctionsBranch,
176
+ ListJobFunctionsBranchDefect,
177
+ ListJobFunctionsBranchFound,
178
+ ListJobFunctionsBranchInvalidResponse,
179
+ ListJobFunctionsBranchProviderRejected,
180
+ ListJobFunctionsDefinition,
181
+ ListJobFunctionsInputSchema,
182
+ ListJobFunctionsMetadata,
183
+ ListJobFunctionsOutputSchema,
184
+ MokaClient,
185
+ ProviderID,
186
+ decodeCredentials,
187
+ isCredentialMaterialError,
188
+ newConnection,
189
+ newConnectionWithOperations,
190
+ newListJobFunctionsStep,
191
+ newProjectConnection2 as newProjectConnection
192
+ };
package/dist/mock.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
2
+ import { Failure } from '@superdurable/connectors-sdk';
3
+ import { O as Operations, C as Connection, L as ListJobFunctionsInput, a as ListJobFunctionsOutput, J as JobFunction } from './connection-BBLPbAP2.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for ListJobFunctionsInput in scripted cases. */
7
+ declare const emptyListJobFunctionsInput: ListJobFunctionsInput;
8
+ /** Go zero value for JobFunction in scripted cases. */
9
+ declare const emptyJobFunction: JobFunction;
10
+ /** Go zero value for ListJobFunctionsOutput in scripted cases. */
11
+ declare const emptyListJobFunctionsOutput: ListJobFunctionsOutput;
12
+ /** Script the found branch. */
13
+ declare function listJobFunctionsFound(value: ListJobFunctionsOutput, failure?: Failure): Case<ListJobFunctionsOutput>;
14
+ /** Script the providerRejected branch. */
15
+ declare function listJobFunctionsProviderRejected(value: ListJobFunctionsOutput, failure?: Failure): Case<ListJobFunctionsOutput>;
16
+ /** Script the invalidResponse branch. */
17
+ declare function listJobFunctionsInvalidResponse(value: ListJobFunctionsOutput, failure?: Failure): Case<ListJobFunctionsOutput>;
18
+ /** Script the defect branch. */
19
+ declare function listJobFunctionsDefect(value: ListJobFunctionsOutput, failure?: Failure): Case<ListJobFunctionsOutput>;
20
+ /** Script a safe retry of listJobFunctions. */
21
+ declare function listJobFunctionsRetry(failure: Failure, retryAfterMs?: number): Case<ListJobFunctionsOutput>;
22
+ /** Manifest scenario twoFunctions for listJobFunctions. */
23
+ declare function listJobFunctionsTwoFunctions(): Case<ListJobFunctionsOutput>;
24
+ /** Default listJobFunctions scenario. */
25
+ declare function listJobFunctionsDefault(): Case<ListJobFunctionsOutput>;
26
+ /** Scripted operations and manifest defaults for this connector. */
27
+ declare class GeneratedMock implements Operations {
28
+ #private;
29
+ constructor(connectionName: string);
30
+ connection(): Connection;
31
+ listJobFunctions(): MockQuery<ListJobFunctionsInput, ListJobFunctionsOutput>;
32
+ assertNoFailures(): void;
33
+ }
34
+
35
+ export { GeneratedMock, emptyJobFunction, emptyListJobFunctionsInput, emptyListJobFunctionsOutput, listJobFunctionsDefault, listJobFunctionsDefect, listJobFunctionsFound, listJobFunctionsInvalidResponse, listJobFunctionsProviderRejected, listJobFunctionsRetry, listJobFunctionsTwoFunctions };
package/dist/mock.js ADDED
@@ -0,0 +1,73 @@
1
+ import {
2
+ JobFunctionSchema,
3
+ ListJobFunctionsDefinition,
4
+ ListJobFunctionsInputSchema,
5
+ ListJobFunctionsOutputSchema,
6
+ ProviderID,
7
+ newConnectionWithOperations
8
+ } from "./chunk-XUFSKQRJ.js";
9
+
10
+ // src/generated/mock.ts
11
+ import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
12
+ var emptyListJobFunctionsInput = ListJobFunctionsInputSchema.parse({});
13
+ var emptyJobFunction = JobFunctionSchema.parse({
14
+ "id": 0,
15
+ "label": "",
16
+ "parentId": 0,
17
+ "jobCount": 0
18
+ });
19
+ var emptyListJobFunctionsOutput = ListJobFunctionsOutputSchema.parse({
20
+ "functions": []
21
+ });
22
+ function listJobFunctionsFound(value, failure) {
23
+ return branchCase("found", value, failure);
24
+ }
25
+ function listJobFunctionsProviderRejected(value, failure) {
26
+ return branchCase("providerRejected", value, failure);
27
+ }
28
+ function listJobFunctionsInvalidResponse(value, failure) {
29
+ return branchCase("invalidResponse", value, failure);
30
+ }
31
+ function listJobFunctionsDefect(value, failure) {
32
+ return branchCase("defect", value, failure);
33
+ }
34
+ function listJobFunctionsRetry(failure, retryAfterMs = 0) {
35
+ return retryCase(failure, retryAfterMs);
36
+ }
37
+ function listJobFunctionsTwoFunctions() {
38
+ const value = ListJobFunctionsOutputSchema.parse({ "functions": [{ "id": 2873, "jobCount": 64, "label": "Technology", "parentId": 0 }, { "id": 2874, "jobCount": 12, "label": "Product", "parentId": 0 }] });
39
+ return branchCase("found", value);
40
+ }
41
+ function listJobFunctionsDefault() {
42
+ return listJobFunctionsTwoFunctions();
43
+ }
44
+ var GeneratedMock = class {
45
+ #listJobFunctions;
46
+ #connection;
47
+ constructor(connectionName) {
48
+ this.#listJobFunctions = newQuery(ListJobFunctionsDefinition).default(listJobFunctionsDefault());
49
+ this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
50
+ }
51
+ connection() {
52
+ return this.#connection;
53
+ }
54
+ listJobFunctions() {
55
+ return this.#listJobFunctions;
56
+ }
57
+ assertNoFailures() {
58
+ this.#listJobFunctions.assertNoFailures();
59
+ }
60
+ };
61
+ export {
62
+ GeneratedMock,
63
+ emptyJobFunction,
64
+ emptyListJobFunctionsInput,
65
+ emptyListJobFunctionsOutput,
66
+ listJobFunctionsDefault,
67
+ listJobFunctionsDefect,
68
+ listJobFunctionsFound,
69
+ listJobFunctionsInvalidResponse,
70
+ listJobFunctionsProviderRejected,
71
+ listJobFunctionsRetry,
72
+ listJobFunctionsTwoFunctions
73
+ };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@superdurable/connector-moka",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "moka connector for Dex TypeScript applications",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/superdurable/dex-connectors-library.git",
9
+ "directory": "connectors/moka/typescript"
10
+ },
11
+ "type": "module",
12
+ "engines": {
13
+ "node": "^22.0.0 || ^24.0.0"
14
+ },
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ },
22
+ "./mock": {
23
+ "types": "./dist/mock.d.ts",
24
+ "import": "./dist/mock.js"
25
+ },
26
+ "./dex-connector.json": "./dex-connector.json"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE",
32
+ "dex-connector.json"
33
+ ],
34
+ "scripts": {
35
+ "prepack": "npm run build",
36
+ "build": "tsup src/index.ts src/mock.ts --format esm --dts --clean",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "eslint src test examples",
39
+ "test": "vitest run --exclude test/integration/**",
40
+ "test:integration": "vitest run test/integration/*.integration.test.ts",
41
+ "example:worker": "tsx examples/basic/worker.ts",
42
+ "example:start": "tsx examples/basic/start.ts",
43
+ "check": "npm run typecheck && npm run lint && npm test && npm run build"
44
+ },
45
+ "dependencies": {
46
+ "@superdurable/connectors-sdk": "0.11.0",
47
+ "@superdurable/dex": ">=1.28.0",
48
+ "zod": "^4.1.0"
49
+ },
50
+ "devDependencies": {
51
+ "@eslint/js": "^9.0.0",
52
+ "@types/node": "^22.0.0",
53
+ "eslint": "^9.0.0",
54
+ "tsup": "^8.0.0",
55
+ "tsx": "^4.23.15",
56
+ "typescript": "^5.9.0",
57
+ "typescript-eslint": "^8.0.0",
58
+ "vitest": "^3.0.0",
59
+ "yaml": "^2.9.1"
60
+ }
61
+ }