-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.ts
128 lines (109 loc) · 3.23 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import {Octokit} from '@octokit/rest'
import Twilio from 'twilio'
import {initSDK} from '@opensdks/core'
import {apolloSdkDef} from '@opensdks/sdk-apollo'
import {discordSdkDef} from '@opensdks/sdk-discord'
import {githubSdkDef} from '@opensdks/sdk-github'
import {openaiSdkDef} from '@opensdks/sdk-openai'
import {plaidSdkDef} from '@opensdks/sdk-plaid'
import {slackSdkDef} from '@opensdks/sdk-slack'
import {twilio_api_v2010SdkDef} from '@opensdks/sdk-twilio_api_v2010'
import {veniceSdkDef} from '@opensdks/sdk-venice'
// Helper function for type guard
function ensureString(value: unknown): string {
if (typeof value !== 'string') {
throw new TypeError('Expected a string')
}
return value
}
// Comparison between GitHub vanilla octokit client and openSDKs client
const github = initSDK(githubSdkDef, {
headers: {
authorization: `Bearer ${process.env['GITHUB_TOKEN']}`,
'X-GitHub-Api-Version': '2022-11-28',
},
})
void github
.GET('/repos/{owner}/{repo}/commits', {
params: {path: {owner: 'useVenice', repo: 'openSDKs'}},
})
.then((r) => {
r.data.forEach((data) => {
console.log(data.commit)
})
})
const octokit = new Octokit() as Octokit
void octokit.rest.repos
.listCommits({
owner: 'useVenice',
repo: 'openSDKs',
})
.then((r) => {
r.data.forEach((data) => {
console.log(data.commit)
})
})
// Comparison between Twilio vanilla API and openSDKs client
// highlighting type safety
const accountSid = ensureString(process.env['TWILIO_ACCOUNT_SID'])
const authToken = ensureString(process.env['TWILIO_AUTH_TOKEN'])
const twilio = initSDK(twilio_api_v2010SdkDef, {
headers: {
accountSid,
authToken,
},
})
void twilio
.POST('/2010-04-01/Accounts/{AccountSid}/Messages.json', {
params: {
path: {
AccountSid: accountSid,
},
},
body: {
Body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
From: '+15017122661',
To: '+15558675310',
},
})
.then((r) => console.log(r.data))
// ^?
.catch(console.log)
const client = Twilio(accountSid, authToken)
client.messages
.create({
body: 'This is the ship that made the Kessel Run in fourteen parsecs?',
from: '+15017122661',
to: '+15558675310',
})
.then((message) => console.log(message.sid))
// ^?
.catch(console.log)
// Other examples
export const plaid = initSDK(plaidSdkDef, {
headers: {
'PLAID-CLIENT-ID': '',
'PLAID-SECRET': '',
},
}) // Need clientId & secret
export const discord = initSDK(discordSdkDef)
export const openai = initSDK(openaiSdkDef)
export const slack = initSDK(slackSdkDef)
const apolloKey = process.env['APOLLO_API_KEY']
if (typeof apolloKey !== 'string') {
throw new TypeError('APOLLO_API_KEY is not set')
}
export const apollo = initSDK(apolloSdkDef, {
api_key: apolloKey,
})
export const venice = initSDK(veniceSdkDef, {
headers: {'x-apikey': process.env['VENICE_API_KEY']},
})
void github
.GET('/orgs/{org}/actions/secrets', {params: {path: {org: 'usevenice'}}})
.then((r) => {
console.log(r.data.secrets[0]?.selected_repositories_url)
})
void venice.GET('/core/resource').then((r) => console.log(r.data))
void apollo.GET('/v1/email_accounts').then((r) => console.log(r.data))
apollo.hello