Adding native property to get access to underlying client in local auth only integrations
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@trigger.dev/supabase": patch
|
||||
"@trigger.dev/openai": patch
|
||||
"@trigger.dev/stripe": patch
|
||||
---
|
||||
|
||||
Adding `native` property to get access to underlying client in local auth only integrations
|
||||
@@ -8,20 +8,39 @@ export class OpenAI
|
||||
{
|
||||
client: IntegrationClient<OpenAIApi, typeof tasks>;
|
||||
|
||||
/**
|
||||
* The native OpenAIApi client. This is exposed for use outside of Trigger.dev jobs
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { OpenAI } from "@trigger.dev/openai";
|
||||
*
|
||||
* const openAI = new OpenAI({
|
||||
* id: "my-openai",
|
||||
* apiKey: process.env.OPENAI_API_KEY!,
|
||||
* });
|
||||
*
|
||||
* const response = await openAI.native.completions.create({}); // ...
|
||||
* ```
|
||||
*/
|
||||
public readonly native: OpenAIApi;
|
||||
|
||||
constructor(private options: OpenAIIntegrationOptions) {
|
||||
if (Object.keys(options).includes("apiKey") && !options.apiKey) {
|
||||
throw `Can't create OpenAI integration (${options.id}) as apiKey was undefined`;
|
||||
}
|
||||
|
||||
this.native = new OpenAIApi(
|
||||
new Configuration({
|
||||
apiKey: options.apiKey,
|
||||
organization: options.organization,
|
||||
})
|
||||
);
|
||||
|
||||
this.client = {
|
||||
tasks,
|
||||
usesLocalAuth: true,
|
||||
client: new OpenAIApi(
|
||||
new Configuration({
|
||||
apiKey: options.apiKey,
|
||||
organization: options.organization,
|
||||
})
|
||||
),
|
||||
client: this.native,
|
||||
auth: {
|
||||
apiKey: options.apiKey,
|
||||
organization: options.organization,
|
||||
|
||||
@@ -26,22 +26,41 @@ type StripeIntegration = TriggerIntegration<StripeIntegrationClient>;
|
||||
export class Stripe implements StripeIntegration {
|
||||
client: StripeIntegrationClient;
|
||||
|
||||
/**
|
||||
* The native Stripe client. This is exposed for use outside of Trigger.dev jobs
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Stripe } from "@trigger.dev/stripe";
|
||||
*
|
||||
* const stripe = new Stripe({
|
||||
* id: "stripe",
|
||||
* apiKey: process.env.STRIPE_API_KEY!,
|
||||
* });
|
||||
*
|
||||
* const customer = await stripe.native.customers.create({}); // etc.
|
||||
* ```
|
||||
*/
|
||||
public readonly native: StripeClient;
|
||||
|
||||
constructor(private options: StripeIntegrationOptions) {
|
||||
this.native = new StripeClient(options.apiKey, {
|
||||
apiVersion: "2022-11-15",
|
||||
typescript: true,
|
||||
timeout: 10000,
|
||||
maxNetworkRetries: 0,
|
||||
stripeAccount: options.stripeAccount,
|
||||
appInfo: {
|
||||
name: "Trigger.dev Stripe Integration",
|
||||
version: "0.1.0",
|
||||
url: "https://trigger.dev",
|
||||
},
|
||||
});
|
||||
|
||||
this.client = {
|
||||
tasks,
|
||||
usesLocalAuth: true,
|
||||
client: new StripeClient(options.apiKey, {
|
||||
apiVersion: "2022-11-15",
|
||||
typescript: true,
|
||||
timeout: 10000,
|
||||
maxNetworkRetries: 0,
|
||||
stripeAccount: options.stripeAccount,
|
||||
appInfo: {
|
||||
name: "Trigger.dev Stripe Integration",
|
||||
version: "0.1.0",
|
||||
url: "https://trigger.dev",
|
||||
},
|
||||
}),
|
||||
client: this.native,
|
||||
auth: {
|
||||
apiKey: options.apiKey,
|
||||
},
|
||||
|
||||
@@ -62,6 +62,25 @@ export class Supabase<
|
||||
typeof tasks
|
||||
>;
|
||||
|
||||
/**
|
||||
* The native Supabase client. This is exposed for use outside of Trigger.dev jobs
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Supabase } from "@trigger.dev/supabase";
|
||||
* import { Database } from "@/supabase.types";
|
||||
*
|
||||
* const supabase = new Supabase<Database>({
|
||||
* id: "my-supabase",
|
||||
* projectId: process.env.SUPABASE_ID!,
|
||||
* supabaseKey: process.env.SUPABASE_API_KEY!,
|
||||
* });
|
||||
*
|
||||
* const { data, error } = await supabase.native.from("users").select("*");
|
||||
* ```
|
||||
*/
|
||||
public readonly native: SupabaseClient<Database, SchemaName, Schema>;
|
||||
|
||||
constructor(private options: SupabaseIntegrationOptions<SchemaName>) {
|
||||
const supabaseOptions = options.options || {};
|
||||
|
||||
@@ -70,7 +89,7 @@ export class Supabase<
|
||||
? `https://${options.projectId}.supabase.co`
|
||||
: options.supabaseUrl;
|
||||
|
||||
const supabaseClient = createClient(supabaseUrl, options.supabaseKey, {
|
||||
this.native = createClient(supabaseUrl, options.supabaseKey, {
|
||||
...supabaseOptions,
|
||||
auth: {
|
||||
...supabaseOptions.auth,
|
||||
@@ -81,7 +100,7 @@ export class Supabase<
|
||||
this.client = {
|
||||
tasks,
|
||||
usesLocalAuth: true,
|
||||
client: supabaseClient,
|
||||
client: this.native,
|
||||
auth: {
|
||||
supabaseUrl,
|
||||
supabaseKey: options.supabaseKey,
|
||||
|
||||
Reference in New Issue
Block a user