Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve some import issues #63

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import SupabaseClient from 'https://esm.sh/v117/@supabase/[email protected]/dist/module/SupabaseClient.d.ts';
import {Database as BASEJUMP_DATABASE_SCHEMA} from '../types/basejump-database.ts';

export type BASEJUMP_BILLING_DATA_UPSERT = {
provider: BASEJUMP_DATABASE_SCHEMA["public"]["Tables"]["billing_providers"]["Row"]["provider"];
provider: BASEJUMP_DATABASE_SCHEMA["basejump"]["Tables"]["billing_subscriptions"]["Row"]["provider"];
customer?: {
id: string;
billing_email?: string;
Expand All @@ -11,7 +12,7 @@ export type BASEJUMP_BILLING_DATA_UPSERT = {
subscription?: {
id: string;
billing_customer_id?: string;
status: BASEJUMP_DATABASE_SCHEMA["public"]["Tables"]["billing_subscriptions"]["Row"]["status"];
status: BASEJUMP_DATABASE_SCHEMA["basejump"]["Tables"]["billing_subscriptions"]["Row"]["status"];
account_id: string;
created_at: Date;
updated_at: Date;
Expand All @@ -34,8 +35,8 @@ export type BASEJUMP_BILLING_DATA_UPSERT = {
};

export async function upsertCustomerSubscription(
supabaseClient,
accountId,
supabaseClient: SupabaseClient,
accountId: string,
upsertData: BASEJUMP_BILLING_DATA_UPSERT
) {
const {data, error} = await supabaseClient.rpc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ type GENERIC_URL_RESPONSE = {
export type GET_BILLING_STATUS_RESPONSE = {
subscription_id: string;
subscription_active: boolean;
status: BASEJUMP_DATABASE_SCHEMA["public"]["Tables"]["billing_subscriptions"]["Row"]["status"];
status: BASEJUMP_DATABASE_SCHEMA["basejump"]["Tables"]["billing_subscriptions"]["Row"]["status"];
billing_email?: string;
account_role: BASEJUMP_DATABASE_SCHEMA["public"]["Tables"]["account_user"]["Row"]["account_role"];
account_role: BASEJUMP_DATABASE_SCHEMA["basejump"]["Tables"]["account_user"]["Row"]["account_role"];
is_primary_owner: boolean;
billing_enabled: boolean;
};
Expand All @@ -70,7 +70,7 @@ type BILLING_FUNCTION_WRAPPER_OPTIONS = {
}

export type BILLING_FUNCTION_WRAPPER_HANDLERS = {
provider: BASEJUMP_DATABASE_SCHEMA["public"]["Tables"]["billing_providers"]["Row"]["provider"];
provider: BASEJUMP_DATABASE_SCHEMA["basejump"]["Tables"]["billing_subscriptions"]["Row"]["provider"];
getPlans: (args: GET_PLANS_ARGS) => Promise<GET_PLANS_RESPONSE>;
getBillingPortalUrl: (
args: GET_BILLING_PORTAL_URL_ARGS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import createSupabaseClient from "../lib/create-supabase-client.ts";
import {BASEJUMP_DATABASE_SCHEMA} from "../mod.ts";
import {Database as BASEJUMP_DATABASE_SCHEMA} from "../types/basejump-database.ts";
import errorResponse from "../lib/error-response.ts";

export type AUTHORIZED_BILLING_USER_INFO = {
account_role: BASEJUMP_DATABASE_SCHEMA["public"]["Tables"]["account_user"]["Row"]["account_role"];
account_role: BASEJUMP_DATABASE_SCHEMA["basejump"]["Tables"]["account_user"]["Row"]["account_role"];
is_primary_owner: boolean;
is_personal_account: boolean;
account_id: string;
Expand Down Expand Up @@ -45,7 +45,9 @@ export async function requireAuthorizedBillingUser(
const supabase = createSupabaseClient(authToken);
const {data, error} = await supabase.rpc("get_account_billing_status", {
account_id: options.accountId,
});
}) as {data: AUTHORIZED_BILLING_USER_INFO | null; error: any};



// means this user isn't a member of this account, block
if (!data || error) {
Expand All @@ -69,9 +71,9 @@ export async function requireAuthorizedBillingUser(
return await options.onBillingDisabled();
}
return new Response(
{
JSON.stringify({
billing_enabled: false,
},
}),
{
headers: {
"Content-Type": "application/json",
Expand All @@ -80,8 +82,12 @@ export async function requireAuthorizedBillingUser(
);
}

if (!options.onBillableAndAuthorized) {
return errorResponse("Config error: No onBillableAndAuthorized function passed in", 400);
}

// means this user is a member of this account, and has the right role, allow
return await options.onBillableAndAuthorized(data);
return await options.onBillableAndAuthorized?.(data);
} catch (e) {
// something went wrong, throw an error
if (options.onError) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createSupabaseClient } from "../deps.ts";
import { BASEJUMP_DATABASE_SCHEMA } from "../mod.ts";
import createSupabaseClient from "../lib/create-supabase-client.ts";
import { Database as BASEJUMP_DATABASE_SCHEMA } from "../types/basejump-database.ts";

type AUTHORIZED_USER_INFO = {
account_role: BASEJUMP_DATABASE_SCHEMA["public"]["Tables"]["account_user"]["Row"]["account_role"];
account_role: BASEJUMP_DATABASE_SCHEMA["basejump"]["Tables"]["account_user"]["Row"]["account_role"];
is_primary_owner: boolean;
is_personal_account: boolean;
};
Expand All @@ -22,7 +22,7 @@ export async function requireAuthorizedUser(
try {
const authToken = req.headers.get("Authorization");
// we don't have what we need. instant block.
if (!authToken || !accountId) {
if (!authToken || !options.accountId) {
if (options.onUnauthorized) {
return await options.onUnauthorized();
}
Expand All @@ -32,7 +32,7 @@ export async function requireAuthorizedUser(
const supabase = createSupabaseClient(authToken);
const { data, error } = await supabase.rpc("current_user_account_role", {
account_id: options.accountId,
});
}) as { data: AUTHORIZED_USER_INFO | null; error: any };
// means this user isn't a member of this account, block
if (!data || error) {
if (options.onUnauthorized) {
Expand Down
Loading
Loading