-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4806bc5
commit f424f61
Showing
141 changed files
with
3,688 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Specify files that shouldn't be modified by Fern |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: ci | ||
|
||
on: [push] | ||
|
||
jobs: | ||
compile: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up node | ||
uses: actions/setup-node@v3 | ||
|
||
- name: Compile | ||
run: yarn && yarn build | ||
|
||
publish: | ||
needs: [ compile ] | ||
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up node | ||
uses: actions/setup-node@v3 | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Build | ||
run: yarn build | ||
|
||
- name: Publish to npm | ||
run: | | ||
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} | ||
npm publish --access public | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
node_modules | ||
.DS_Store | ||
/dist | ||
/Client.d.ts | ||
/Client.js | ||
/environments.d.ts | ||
/environments.js | ||
/index.d.ts | ||
/index.js | ||
/api | ||
/core | ||
/errors | ||
/serialization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
node_modules | ||
src | ||
.gitignore | ||
.github | ||
.fernignore | ||
.prettierrc.yml | ||
tsconfig.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tabWidth: 4 | ||
printWidth: 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@syndicateio/syndicate-node", | ||
"version": "1.0.0", | ||
"private": false, | ||
"repository": "https://github.com/SyndicateProtocol/syndicate-node", | ||
"main": "./index.js", | ||
"types": "./index.d.ts", | ||
"scripts": { | ||
"format": "prettier --write 'src/**/*.ts'", | ||
"build": "tsc", | ||
"prepack": "cp -rv dist/. ." | ||
}, | ||
"dependencies": { | ||
"url-join": "4.0.1", | ||
"@types/url-join": "4.0.1", | ||
"@ungap/url-search-params": "0.2.2", | ||
"js-base64": "3.7.2", | ||
"axios": "0.27.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "17.0.33", | ||
"prettier": "2.7.1", | ||
"typescript": "4.6.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as core from "./core"; | ||
import { Transact } from "./api/resources/transact/client/Client"; | ||
import { Wallet } from "./api/resources/wallet/client/Client"; | ||
|
||
export declare namespace SyndicateClient { | ||
interface Options { | ||
token: core.Supplier<core.BearerToken>; | ||
} | ||
|
||
interface RequestOptions { | ||
timeoutInSeconds?: number; | ||
} | ||
} | ||
|
||
export class SyndicateClient { | ||
constructor(protected readonly _options: SyndicateClient.Options) {} | ||
|
||
protected _transact: Transact | undefined; | ||
|
||
public get transact(): Transact { | ||
return (this._transact ??= new Transact(this._options)); | ||
} | ||
|
||
protected _wallet: Wallet | undefined; | ||
|
||
public get wallet(): Wallet { | ||
return (this._wallet ??= new Wallet(this._options)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./resources"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * as transact from "./transact"; | ||
export * as wallet from "./wallet"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as core from "../../../../core"; | ||
import * as Syndicate from "../../.."; | ||
import * as serializers from "../../../../serialization"; | ||
import * as environments from "../../../../environments"; | ||
import urlJoin from "url-join"; | ||
import * as errors from "../../../../errors"; | ||
|
||
export declare namespace Transact { | ||
interface Options { | ||
token: core.Supplier<core.BearerToken>; | ||
} | ||
|
||
interface RequestOptions { | ||
timeoutInSeconds?: number; | ||
} | ||
} | ||
|
||
export class Transact { | ||
constructor(protected readonly _options: Transact.Options) {} | ||
|
||
/** | ||
* Send transaction to blockchain | ||
* @throws {@link Syndicate.transact.MalformedFunctionDataError} | ||
* @throws {@link Syndicate.transact.ImATeapotError} | ||
* @throws {@link Syndicate.transact.InternalError} | ||
* @throws {@link Syndicate.transact.InvalidRequestIdError} | ||
*/ | ||
public async sendTransaction( | ||
request: Syndicate.transact.SendTransactionRequest, | ||
requestOptions?: Transact.RequestOptions | ||
): Promise<Syndicate.transact.SendTransactionResponse> { | ||
const _response = await core.fetcher({ | ||
url: urlJoin(environments.SyndicateEnvironment.Production, "/transact/sendTransaction"), | ||
method: "POST", | ||
headers: { | ||
Authorization: await this._getAuthorizationHeader(), | ||
"X-Fern-Language": "JavaScript", | ||
"X-Fern-SDK-Name": "@syndicateio/syndicate-node", | ||
"X-Fern-SDK-Version": "1.0.0", | ||
}, | ||
contentType: "application/json", | ||
body: await serializers.transact.SendTransactionRequest.jsonOrThrow(request, { | ||
unrecognizedObjectKeys: "strip", | ||
}), | ||
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, | ||
}); | ||
if (_response.ok) { | ||
return await serializers.transact.SendTransactionResponse.parseOrThrow(_response.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}); | ||
} | ||
|
||
if (_response.error.reason === "status-code") { | ||
switch (_response.error.statusCode) { | ||
case 400: | ||
throw new Syndicate.transact.MalformedFunctionDataError( | ||
await serializers.transact.ErrorWithMessage.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case 418: | ||
throw new Syndicate.transact.ImATeapotError(); | ||
case 500: | ||
throw new Syndicate.transact.InternalError(); | ||
case 422: | ||
throw new Syndicate.transact.InvalidRequestIdError( | ||
await serializers.transact.ErrorWithMessage.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
default: | ||
throw new errors.SyndicateError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.body, | ||
}); | ||
} | ||
} | ||
|
||
switch (_response.error.reason) { | ||
case "non-json": | ||
throw new errors.SyndicateError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.rawBody, | ||
}); | ||
case "timeout": | ||
throw new errors.SyndicateTimeoutError(); | ||
case "unknown": | ||
throw new errors.SyndicateError({ | ||
message: _response.error.errorMessage, | ||
}); | ||
} | ||
} | ||
|
||
protected async _getAuthorizationHeader() { | ||
return `Bearer ${await core.Supplier.get(this._options.token)}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../../../errors"; | ||
|
||
export class ImATeapotError extends errors.SyndicateError { | ||
constructor() { | ||
super({ | ||
statusCode: 418, | ||
}); | ||
Object.setPrototypeOf(this, ImATeapotError.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../../../errors"; | ||
|
||
export class InternalError extends errors.SyndicateError { | ||
constructor() { | ||
super({ | ||
statusCode: 500, | ||
}); | ||
Object.setPrototypeOf(this, InternalError.prototype); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/api/resources/transact/errors/InvalidRequestIdError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../../../errors"; | ||
import * as Syndicate from "../../.."; | ||
|
||
export class InvalidRequestIdError extends errors.SyndicateError { | ||
constructor(body: Syndicate.transact.ErrorWithMessage) { | ||
super({ | ||
statusCode: 422, | ||
body: body, | ||
}); | ||
Object.setPrototypeOf(this, InvalidRequestIdError.prototype); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/api/resources/transact/errors/MalformedFunctionDataError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as errors from "../../../../errors"; | ||
import * as Syndicate from "../../.."; | ||
|
||
export class MalformedFunctionDataError extends errors.SyndicateError { | ||
constructor(body: Syndicate.transact.ErrorWithMessage) { | ||
super({ | ||
statusCode: 400, | ||
body: body, | ||
}); | ||
Object.setPrototypeOf(this, MalformedFunctionDataError.prototype); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./ImATeapotError"; | ||
export * from "./InternalError"; | ||
export * from "./MalformedFunctionDataError"; | ||
export * from "./InvalidRequestIdError"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./types"; | ||
export * from "./errors"; | ||
export * from "./client"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
export interface ErrorWithMessage { | ||
message: string; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/api/resources/transact/types/SendTransactionRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
export interface SendTransactionRequest { | ||
/** (Optional) ID of the request. Needs to be a valid UUID. If provided, it will be saved and returned as the transactionId of the response. If not provided, we will generate one for you and return it as the transactionId. */ | ||
requestId?: string; | ||
/** ID of the project you want this request to be sent from */ | ||
projectId: string; | ||
/** The contract address to send request to */ | ||
contractAddress: string; | ||
/** The chain ID for the network (e.g. 1 for Ethereum Mainnet, 137 for Polygon Mainnet, 80001 for Polygon Mumbai). For a complete list of chain IDs, see [ChainList](https://chainlist.org/?search=&testnets=true). */ | ||
chainId: number; | ||
/** The human readable signature to call on the contract */ | ||
functionSignature: string; | ||
/** (Optional) The function arguments for the transaction if any. The keys are the argument names or index from the provided function signature and the values are the argument values. */ | ||
args?: Record<string, unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
export interface SendTransactionResponse { | ||
transactionId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./ErrorWithMessage"; | ||
export * from "./SendTransactionRequest"; | ||
export * from "./SendTransactionResponse"; |
Oops, something went wrong.