Skip to content

Commit

Permalink
Adding types for cookie consent and helper utils (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmyers authored Feb 7, 2022
1 parent 5ce0b78 commit 86cc541
Show file tree
Hide file tree
Showing 6 changed files with 512 additions and 867 deletions.
2 changes: 2 additions & 0 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ generates:
- typescript
- typescript-operations
- typescript-graphql-request
- add
config:
content: "export * from './src/cookieConsent';"
documentMode: string
13 changes: 12 additions & 1 deletion example.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { GraphQLClient } from 'graphql-request';
import { getSdk } from '.';
import { getSdk, decodeAnalyticsCookie } from '.';

const defaultEndpoint = 'https://apps.stardog.com/api/graphql';

// This is just because node.js does not have atob and browsers do not have Buffer!!
if (typeof atob === 'undefined') {
global.atob = function (b64Encoded) {
return Buffer.from(b64Encoded, 'base64').toString('binary');
};
}

async function main() {
const client = new GraphQLClient(defaultEndpoint);
const sdk = getSdk(client);
Expand All @@ -11,6 +18,10 @@ async function main() {

console.log(`GraphQL Connections:`, listConnections);
console.log(`GraphQL Profile:`, profile);

const fakeCookieValue = 'eyJjb25zZW50ZWQiOnRydWUsImlkZW50aXR5IjoiZnJhbmtAYmFyLmNvbSJ9';
const consent = decodeAnalyticsCookie(fakeCookieValue);
console.log(consent);
}

main();
152 changes: 71 additions & 81 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { GraphQLClient } from 'graphql-request';
import * as Dom from 'graphql-request/dist/types.dom';
export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
export * from './src/cookieConsent';
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string;
Expand All @@ -14,71 +16,71 @@ export type Scalars = {
};

export type AddConnectionInput = {
name: Scalars['String'];
endpoint: Scalars['String'];
username?: Maybe<Scalars['String']>;
token?: Maybe<Scalars['String']>;
useSSO?: Maybe<Scalars['Boolean']>;
name: Scalars['String'];
token?: InputMaybe<Scalars['String']>;
useSSO?: InputMaybe<Scalars['Boolean']>;
username?: InputMaybe<Scalars['String']>;
};

export type BillingPortalUrl = {
__typename?: 'BillingPortalUrl';
url?: Maybe<Scalars['String']>;
customer?: Maybe<Scalars['String']>;
url?: Maybe<Scalars['String']>;
};

export type BillingSession = {
__typename?: 'BillingSession';
url?: Maybe<Scalars['String']>;
session_id?: Maybe<Scalars['String']>;
url?: Maybe<Scalars['String']>;
};

export type BillingSessionInput = {
name?: Maybe<Scalars['String']>;
name?: InputMaybe<Scalars['String']>;
};

/** Stardog Cloud Flavor and Size info */
export type CloudFlavor = {
__typename?: 'CloudFlavor';
name?: Maybe<Scalars['String']>;
memory?: Maybe<Scalars['String']>;
vcpus?: Maybe<Scalars['Float']>;
iops?: Maybe<Scalars['Float']>;
disk?: Maybe<Scalars['String']>;
nodes?: Maybe<Scalars['Float']>;
iops?: Maybe<Scalars['Float']>;
is_cluster?: Maybe<Scalars['Boolean']>;
memory?: Maybe<Scalars['String']>;
name?: Maybe<Scalars['String']>;
nodes?: Maybe<Scalars['Float']>;
price?: Maybe<Scalars['Float']>;
vcpus?: Maybe<Scalars['Float']>;
};

/** Saved Connection info for a Stardog instance */
export type Connection = {
__typename?: 'Connection';
endpoint: Scalars['String'];
id: Scalars['ID'];
user?: Maybe<User>;
isAllocating?: Maybe<Scalars['Boolean']>;
isStardogCloud?: Maybe<Scalars['Boolean']>;
isStardogFree?: Maybe<Scalars['Boolean']>;
name: Scalars['String'];
endpoint: Scalars['String'];
username?: Maybe<Scalars['String']>;
token?: Maybe<Scalars['String']>;
useSSO?: Maybe<Scalars['Boolean']>;
isStardogFree?: Maybe<Scalars['Boolean']>;
isStardogCloud?: Maybe<Scalars['Boolean']>;
isAllocating?: Maybe<Scalars['Boolean']>;
user?: Maybe<User>;
username?: Maybe<Scalars['String']>;
};

/** Generic deletion response type to handle reporting success. */
export type DeletionResponse = {
__typename?: 'DeletionResponse';
success: Scalars['Boolean'];
error?: Maybe<Scalars['String']>;
success: Scalars['Boolean'];
};

export type EditConnectionInput = {
endpoint?: InputMaybe<Scalars['String']>;
id: Scalars['ID'];
name?: Maybe<Scalars['String']>;
endpoint?: Maybe<Scalars['String']>;
username?: Maybe<Scalars['String']>;
token?: Maybe<Scalars['String']>;
useSSO?: Maybe<Scalars['Boolean']>;
name?: InputMaybe<Scalars['String']>;
token?: InputMaybe<Scalars['String']>;
useSSO?: InputMaybe<Scalars['Boolean']>;
username?: InputMaybe<Scalars['String']>;
};

/** Example Configuration for jwt.yaml and stardog.properties */
Expand All @@ -93,12 +95,12 @@ export type ExampleConfig = {
export type Mutation = {
__typename?: 'Mutation';
addConnection?: Maybe<Connection>;
editConnection?: Maybe<Connection>;
deleteConnection?: Maybe<DeletionResponse>;
addStardogFree?: Maybe<StardogFree>;
deleteConnection?: Maybe<DeletionResponse>;
editConnection?: Maybe<Connection>;
generateConfiguration?: Maybe<ExampleConfig>;
updateProfile?: Maybe<User>;
startBillingSession?: Maybe<BillingSession>;
updateProfile?: Maybe<User>;
};


Expand All @@ -109,14 +111,14 @@ export type MutationAddConnectionArgs = {


/** Available mutations */
export type MutationEditConnectionArgs = {
input: EditConnectionInput;
export type MutationDeleteConnectionArgs = {
name: Scalars['String'];
};


/** Available mutations */
export type MutationDeleteConnectionArgs = {
name: Scalars['String'];
export type MutationEditConnectionArgs = {
input: EditConnectionInput;
};


Expand All @@ -127,14 +129,14 @@ export type MutationGenerateConfigurationArgs = {


/** Available mutations */
export type MutationUpdateProfileArgs = {
input?: Maybe<ProfileInput>;
export type MutationStartBillingSessionArgs = {
input: BillingSessionInput;
};


/** Available mutations */
export type MutationStartBillingSessionArgs = {
input: BillingSessionInput;
export type MutationUpdateProfileArgs = {
input?: InputMaybe<ProfileInput>;
};

/**
Expand All @@ -143,48 +145,48 @@ export type MutationStartBillingSessionArgs = {
*/
export type OAuthToken = {
__typename?: 'OAuthToken';
id: Scalars['ID'];
user: User;
access_token?: Maybe<Scalars['String']>;
id: Scalars['ID'];
id_token?: Maybe<Scalars['String']>;
scope?: Maybe<Scalars['String']>;
user: User;
};

export type ProfileInput = {
company: Scalars['String'];
title: Scalars['String'];
phone: Scalars['String'];
use_case: Scalars['String'];
first_name: Scalars['String'];
last_name: Scalars['String'];
phone: Scalars['String'];
title: Scalars['String'];
use_case: Scalars['String'];
};

/** Available queries */
export type Query = {
__typename?: 'Query';
getConnection?: Maybe<Connection>;
listConnections?: Maybe<Array<Maybe<Connection>>>;
getStardogFree?: Maybe<StardogFree>;
checkCloudQueue?: Maybe<QueueCounts>;
generateToken?: Maybe<OAuthToken>;
profile?: Maybe<User>;
getBillingPortalUrl?: Maybe<BillingPortalUrl>;
getConnection?: Maybe<Connection>;
getStardogCloud?: Maybe<StardogCloud>;
listStardogCloud?: Maybe<Array<Maybe<StardogCloud>>>;
checkCloudQueue?: Maybe<QueueCounts>;
getStardogFree?: Maybe<StardogFree>;
getStripeSubscriptionOrderSession?: Maybe<StripeSubscriptionOrderSession>;
getStripeSubscriptionStatus?: Maybe<StripeSubscriptionStatus>;
getBillingPortalUrl?: Maybe<BillingPortalUrl>;
listConnections?: Maybe<Array<Maybe<Connection>>>;
listStardogCloud?: Maybe<Array<Maybe<StardogCloud>>>;
profile?: Maybe<User>;
};


/** Available queries */
export type QueryGetConnectionArgs = {
name: Scalars['String'];
export type QueryGenerateTokenArgs = {
endpoint: Scalars['String'];
};


/** Available queries */
export type QueryGenerateTokenArgs = {
endpoint: Scalars['String'];
export type QueryGetConnectionArgs = {
name: Scalars['String'];
};


Expand All @@ -196,30 +198,30 @@ export type QueryGetStardogCloudArgs = {
/** Contains the counts of available cloud resources to sell. */
export type QueueCounts = {
__typename?: 'QueueCounts';
small_count?: Maybe<Scalars['Float']>;
micro_count?: Maybe<Scalars['Float']>;
medium_count?: Maybe<Scalars['Float']>;
micro_count?: Maybe<Scalars['Float']>;
small_count?: Maybe<Scalars['Float']>;
};

/** Stardog Cloud, represents an instance of Cloud that is owned by the user */
export type StardogCloud = {
__typename?: 'StardogCloud';
id?: Maybe<Scalars['ID']>;
name?: Maybe<Scalars['String']>;
bi_endpoint?: Maybe<Scalars['String']>;
created?: Maybe<Scalars['String']>;
endpoint?: Maybe<Scalars['String']>;
bi_endpoint?: Maybe<Scalars['String']>;
flavor?: Maybe<CloudFlavor>;
id?: Maybe<Scalars['ID']>;
name?: Maybe<Scalars['String']>;
updated?: Maybe<Scalars['String']>;
};

/** Stardog Free Installation */
export type StardogFree = {
__typename?: 'StardogFree';
id?: Maybe<Scalars['ID']>;
company?: Maybe<Scalars['String']>;
email?: Maybe<Scalars['String']>;
expires?: Maybe<Scalars['String']>;
id?: Maybe<Scalars['ID']>;
installer?: Maybe<StardogFreeInstaller>;
phone?: Maybe<Scalars['String']>;
title?: Maybe<Scalars['String']>;
Expand All @@ -231,8 +233,8 @@ export type StardogFree = {
export type StardogFreeInstaller = {
__typename?: 'StardogFreeInstaller';
id?: Maybe<Scalars['ID']>;
version?: Maybe<Scalars['String']>;
install_url?: Maybe<Scalars['String']>;
version?: Maybe<Scalars['String']>;
};

export type StripeSubscriptionOrderSession = {
Expand All @@ -251,43 +253,31 @@ export type StripeSubscriptionStatus = {
*/
export type User = {
__typename?: 'User';
company?: Maybe<Scalars['String']>;
email?: Maybe<Scalars['String']>;
first_name?: Maybe<Scalars['String']>;
has_updated_profile?: Maybe<Scalars['Boolean']>;
id?: Maybe<Scalars['ID']>;
sub?: Maybe<Scalars['String']>;
username: Scalars['String'];
is_authenticated: Scalars['Boolean'];
email?: Maybe<Scalars['String']>;
is_superuser?: Maybe<Scalars['Boolean']>;
is_ephemeral?: Maybe<Scalars['Boolean']>;
has_updated_profile?: Maybe<Scalars['Boolean']>;
company?: Maybe<Scalars['String']>;
title?: Maybe<Scalars['String']>;
is_superuser?: Maybe<Scalars['Boolean']>;
last_name?: Maybe<Scalars['String']>;
phone?: Maybe<Scalars['String']>;
sub?: Maybe<Scalars['String']>;
title?: Maybe<Scalars['String']>;
use_case?: Maybe<Scalars['String']>;
first_name?: Maybe<Scalars['String']>;
last_name?: Maybe<Scalars['String']>;
username: Scalars['String'];
};

export type ListConnectionsQueryVariables = Exact<{ [key: string]: never; }>;


export type ListConnectionsQuery = (
{ __typename?: 'Query' }
& { listConnections?: Maybe<Array<Maybe<(
{ __typename?: 'Connection' }
& Pick<Connection, 'id' | 'name' | 'username' | 'endpoint' | 'token' | 'isStardogCloud' | 'isStardogFree' | 'isAllocating' | 'useSSO'>
)>>> }
);
export type ListConnectionsQuery = { __typename?: 'Query', listConnections?: Array<{ __typename?: 'Connection', id: string, name: string, username?: string | null, endpoint: string, token?: string | null, isStardogCloud?: boolean | null, isStardogFree?: boolean | null, isAllocating?: boolean | null, useSSO?: boolean | null } | null> | null };

export type ProfileQueryVariables = Exact<{ [key: string]: never; }>;


export type ProfileQuery = (
{ __typename?: 'Query' }
& { profile?: Maybe<(
{ __typename?: 'User' }
& Pick<User, 'id' | 'username' | 'email' | 'first_name' | 'last_name' | 'company' | 'use_case' | 'is_authenticated' | 'is_superuser'>
)> }
);
export type ProfileQuery = { __typename?: 'Query', profile?: { __typename?: 'User', id?: string | null, username: string, email?: string | null, first_name?: string | null, last_name?: string | null, company?: string | null, use_case?: string | null, is_authenticated: boolean, is_superuser?: boolean | null } | null };


export const ListConnectionsDocument = `
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"author": "Stardog Union <[email protected]>",
"homepage": "https://github.com/stardog-union/portal-sdk#readme",
"devDependencies": {
"@graphql-codegen/add": "1.17.7",
"@graphql-codegen/cli": "1.21.7",
"@graphql-codegen/introspection": "1.18.2",
"@graphql-codegen/typescript": "1.23.0",
"@graphql-codegen/typescript-graphql-files-modules": "1.18.1",
"@graphql-codegen/typescript-graphql-request": "^3.2.5",
"@graphql-codegen/typescript-operations": "1.18.4",
"@graphql-codegen/typescript-react-query": "^1.3.5",
"@graphql-codegen/add": "3.1.1",
"@graphql-codegen/cli": "2.5.0",
"@graphql-codegen/introspection": "2.1.1",
"@graphql-codegen/typescript": "2.4.3",
"@graphql-codegen/typescript-graphql-files-modules": "2.1.1",
"@graphql-codegen/typescript-graphql-request": "^4.3.4",
"@graphql-codegen/typescript-operations": "2.2.4",
"@types/node": "^17.0.14",
"node-ts": "^5.1.2",
"typescript": "^4.0.5"
},
Expand Down
Loading

0 comments on commit 86cc541

Please sign in to comment.