From ffa359ddbd3799ee841ed8fc3dad36aee4724d25 Mon Sep 17 00:00:00 2001 From: Robert Myers Date: Wed, 9 Feb 2022 13:13:10 -0600 Subject: [PATCH] Update to latest version of sdk (#2) * remove console warn * move to simplifed index.ts --- codegen.yml | 4 +- example.ts | 4 +- index.ts | 329 +------------------------------------ package.json | 1 - src/cookieConsent.ts | 6 +- src/sdk.ts | 375 +++++++++++++++++++++++++++++++++++++++++++ yarn.lock | 8 - 7 files changed, 383 insertions(+), 344 deletions(-) create mode 100644 src/sdk.ts diff --git a/codegen.yml b/codegen.yml index 48f76c5..e6330a7 100644 --- a/codegen.yml +++ b/codegen.yml @@ -2,12 +2,10 @@ overwrite: true schema: "https://apps.stardog.com/api/graphql" documents: "src/**/*.graphql" generates: - index.ts: + src/sdk.ts: plugins: - typescript - typescript-operations - typescript-graphql-request - - add config: - content: "export * from './src/cookieConsent';" documentMode: string diff --git a/example.ts b/example.ts index 1ab16d3..d42b57f 100644 --- a/example.ts +++ b/example.ts @@ -20,8 +20,8 @@ async function main() { console.log(`GraphQL Profile:`, profile); const fakeCookieValue = 'eyJjb25zZW50ZWQiOnRydWUsImlkZW50aXR5IjoiZnJhbmtAYmFyLmNvbSJ9'; - const consent = decodeAnalyticsCookie(fakeCookieValue); - console.log(consent); + console.log(decodeAnalyticsCookie(fakeCookieValue)); + console.log(decodeAnalyticsCookie('not really valid')); } main(); diff --git a/index.ts b/index.ts index 44e210d..b34d3f5 100644 --- a/index.ts +++ b/index.ts @@ -1,329 +1,2 @@ -import { GraphQLClient } from 'graphql-request'; -import * as Dom from 'graphql-request/dist/types.dom'; -export type Maybe = T | null; -export type InputMaybe = Maybe; -export type Exact = { [K in keyof T]: T[K] }; -export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; -export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; export * from './src/cookieConsent'; -/** All built-in and custom scalars, mapped to their actual values */ -export type Scalars = { - ID: string; - String: string; - Boolean: boolean; - Int: number; - Float: number; -}; - -export type AddConnectionInput = { - endpoint: Scalars['String']; - name: Scalars['String']; - token?: InputMaybe; - useSSO?: InputMaybe; - username?: InputMaybe; -}; - -export type BillingPortalUrl = { - __typename?: 'BillingPortalUrl'; - customer?: Maybe; - url?: Maybe; -}; - -export type BillingSession = { - __typename?: 'BillingSession'; - session_id?: Maybe; - url?: Maybe; -}; - -export type BillingSessionInput = { - name?: InputMaybe; -}; - -/** Stardog Cloud Flavor and Size info */ -export type CloudFlavor = { - __typename?: 'CloudFlavor'; - disk?: Maybe; - iops?: Maybe; - is_cluster?: Maybe; - memory?: Maybe; - name?: Maybe; - nodes?: Maybe; - price?: Maybe; - vcpus?: Maybe; -}; - -/** Saved Connection info for a Stardog instance */ -export type Connection = { - __typename?: 'Connection'; - endpoint: Scalars['String']; - id: Scalars['ID']; - isAllocating?: Maybe; - isStardogCloud?: Maybe; - isStardogFree?: Maybe; - name: Scalars['String']; - token?: Maybe; - useSSO?: Maybe; - user?: Maybe; - username?: Maybe; -}; - -/** Generic deletion response type to handle reporting success. */ -export type DeletionResponse = { - __typename?: 'DeletionResponse'; - error?: Maybe; - success: Scalars['Boolean']; -}; - -export type EditConnectionInput = { - endpoint?: InputMaybe; - id: Scalars['ID']; - name?: InputMaybe; - token?: InputMaybe; - useSSO?: InputMaybe; - username?: InputMaybe; -}; - -/** Example Configuration for jwt.yaml and stardog.properties */ -export type ExampleConfig = { - __typename?: 'ExampleConfig'; - id: Scalars['ID']; - jwt_config: Scalars['String']; - properties: Scalars['String']; -}; - -/** Available mutations */ -export type Mutation = { - __typename?: 'Mutation'; - addConnection?: Maybe; - addStardogFree?: Maybe; - deleteConnection?: Maybe; - editConnection?: Maybe; - generateConfiguration?: Maybe; - startBillingSession?: Maybe; - updateProfile?: Maybe; -}; - - -/** Available mutations */ -export type MutationAddConnectionArgs = { - input: AddConnectionInput; -}; - - -/** Available mutations */ -export type MutationDeleteConnectionArgs = { - name: Scalars['String']; -}; - - -/** Available mutations */ -export type MutationEditConnectionArgs = { - input: EditConnectionInput; -}; - - -/** Available mutations */ -export type MutationGenerateConfigurationArgs = { - endpoint: Scalars['String']; -}; - - -/** Available mutations */ -export type MutationStartBillingSessionArgs = { - input: BillingSessionInput; -}; - - -/** Available mutations */ -export type MutationUpdateProfileArgs = { - input?: InputMaybe; -}; - -/** - * An Auth0 auth token stored for the user, do not add secret values here such as - * refresh_token or client_id. - */ -export type OAuthToken = { - __typename?: 'OAuthToken'; - access_token?: Maybe; - id: Scalars['ID']; - id_token?: Maybe; - scope?: Maybe; - user: User; -}; - -export type ProfileInput = { - company: 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'; - checkCloudQueue?: Maybe; - generateToken?: Maybe; - getBillingPortalUrl?: Maybe; - getConnection?: Maybe; - getStardogCloud?: Maybe; - getStardogFree?: Maybe; - getStripeSubscriptionOrderSession?: Maybe; - getStripeSubscriptionStatus?: Maybe; - listConnections?: Maybe>>; - listStardogCloud?: Maybe>>; - profile?: Maybe; -}; - - -/** Available queries */ -export type QueryGenerateTokenArgs = { - endpoint: Scalars['String']; -}; - - -/** Available queries */ -export type QueryGetConnectionArgs = { - name: Scalars['String']; -}; - - -/** Available queries */ -export type QueryGetStardogCloudArgs = { - pk: Scalars['String']; -}; - -/** Contains the counts of available cloud resources to sell. */ -export type QueueCounts = { - __typename?: 'QueueCounts'; - medium_count?: Maybe; - micro_count?: Maybe; - small_count?: Maybe; -}; - -/** Stardog Cloud, represents an instance of Cloud that is owned by the user */ -export type StardogCloud = { - __typename?: 'StardogCloud'; - bi_endpoint?: Maybe; - created?: Maybe; - endpoint?: Maybe; - flavor?: Maybe; - id?: Maybe; - name?: Maybe; - updated?: Maybe; -}; - -/** Stardog Free Installation */ -export type StardogFree = { - __typename?: 'StardogFree'; - company?: Maybe; - email?: Maybe; - expires?: Maybe; - id?: Maybe; - installer?: Maybe; - phone?: Maybe; - title?: Maybe; - use_case?: Maybe; - user?: Maybe; - version?: Maybe; -}; - -export type StardogFreeInstaller = { - __typename?: 'StardogFreeInstaller'; - id?: Maybe; - install_url?: Maybe; - version?: Maybe; -}; - -export type StripeSubscriptionOrderSession = { - __typename?: 'StripeSubscriptionOrderSession'; - status: Scalars['String']; -}; - -export type StripeSubscriptionStatus = { - __typename?: 'StripeSubscriptionStatus'; - status: Scalars['String']; -}; - -/** - * The user model, this represents a user from Auth0. Only fields defined here - * are exposed in the possible GraphQL responses. - */ -export type User = { - __typename?: 'User'; - company?: Maybe; - email?: Maybe; - first_name?: Maybe; - has_updated_profile?: Maybe; - id?: Maybe; - is_authenticated: Scalars['Boolean']; - is_ephemeral?: Maybe; - is_superuser?: Maybe; - last_name?: Maybe; - phone?: Maybe; - sub?: Maybe; - title?: Maybe; - use_case?: Maybe; - username: Scalars['String']; -}; - -export type ListConnectionsQueryVariables = Exact<{ [key: string]: never; }>; - - -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?: { __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 = ` - query listConnections { - listConnections { - id - name - username - endpoint - token - isStardogCloud - isStardogFree - isAllocating - useSSO - } -} - `; -export const ProfileDocument = ` - query profile { - profile { - id - username - email - first_name - last_name - company - use_case - is_authenticated - is_superuser - } -} - `; - -export type SdkFunctionWrapper = (action: (requestHeaders?:Record) => Promise, operationName: string) => Promise; - - -const defaultWrapper: SdkFunctionWrapper = (action, _operationName) => action(); - -export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { - return { - listConnections(variables?: ListConnectionsQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { - return withWrapper((wrappedRequestHeaders) => client.request(ListConnectionsDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'listConnections'); - }, - profile(variables?: ProfileQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { - return withWrapper((wrappedRequestHeaders) => client.request(ProfileDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'profile'); - } - }; -} -export type Sdk = ReturnType; \ No newline at end of file +export * from './src/sdk'; diff --git a/package.json b/package.json index 9b426ce..9f02aa7 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "author": "Stardog Union ", "homepage": "https://github.com/stardog-union/portal-sdk#readme", "devDependencies": { - "@graphql-codegen/add": "3.1.1", "@graphql-codegen/cli": "2.5.0", "@graphql-codegen/introspection": "2.1.1", "@graphql-codegen/typescript": "2.4.3", diff --git a/src/cookieConsent.ts b/src/cookieConsent.ts index 24d62b3..2f1e0dd 100644 --- a/src/cookieConsent.ts +++ b/src/cookieConsent.ts @@ -31,12 +31,14 @@ export const decodeAnalyticsCookie = (rawCookie: string): AnalyticsConsent => { identity } } catch (e) { - console.warn(e); return defaultConsent; } }; -export const getAnalyticsConsentCookie = (): AnalyticsConsent => { +export const getAnalyticsConsentCookie = (): AnalyticsConsent | null => { const rawConsentCookie = getCookieValue(ANALYTICS_COOKIE_NAME); + if (rawConsentCookie === '') { + return null; + } return decodeAnalyticsCookie(rawConsentCookie); }; diff --git a/src/sdk.ts b/src/sdk.ts new file mode 100644 index 0000000..db2de82 --- /dev/null +++ b/src/sdk.ts @@ -0,0 +1,375 @@ +import { GraphQLClient } from 'graphql-request'; +import * as Dom from 'graphql-request/dist/types.dom'; +export type Maybe = T | null; +export type InputMaybe = Maybe; +export type Exact = { [K in keyof T]: T[K] }; +export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; +export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; +/** All built-in and custom scalars, mapped to their actual values */ +export type Scalars = { + ID: string; + String: string; + Boolean: boolean; + Int: number; + Float: number; +}; + +export type AddConnectionInput = { + endpoint: Scalars['String']; + name: Scalars['String']; + token?: InputMaybe; + useSSO?: InputMaybe; + username?: InputMaybe; +}; + +export type BillingSession = { + __typename?: 'BillingSession'; + session_id?: Maybe; + url?: Maybe; +}; + +export type BillingSessionInput = { + name?: InputMaybe; +}; + +export type CloudCleanupInput = { + cloudName?: InputMaybe; + userName?: InputMaybe; +}; + +/** Stardog Cloud Flavor and Size info */ +export type CloudFlavor = { + __typename?: 'CloudFlavor'; + disk?: Maybe; + iops?: Maybe; + is_cluster?: Maybe; + memory?: Maybe; + name?: Maybe; + nodes?: Maybe; + price?: Maybe; + vcpus?: Maybe; +}; + +/** Saved Connection info for a Stardog instance */ +export type Connection = { + __typename?: 'Connection'; + endpoint: Scalars['String']; + id: Scalars['ID']; + isAllocating?: Maybe; + isStardogCloud?: Maybe; + isStardogFree?: Maybe; + isWaitingForPayment?: Maybe; + name: Scalars['String']; + shouldShowDesigner?: Maybe; + stripeSubscription?: Maybe; + token?: Maybe; + useSSO?: Maybe; + user?: Maybe; + username?: Maybe; +}; + +/** Generic deletion response type to handle reporting success. */ +export type DeletionResponse = { + __typename?: 'DeletionResponse'; + error?: Maybe; + success: Scalars['Boolean']; +}; + +export type EditConnectionInput = { + endpoint?: InputMaybe; + id: Scalars['ID']; + name?: InputMaybe; + token?: InputMaybe; + useSSO?: InputMaybe; + username?: InputMaybe; +}; + +/** Example Configuration for jwt.yaml and stardog.properties */ +export type ExampleConfig = { + __typename?: 'ExampleConfig'; + id: Scalars['ID']; + jwt_config: Scalars['String']; + properties: Scalars['String']; +}; + +/** Available mutations */ +export type Mutation = { + __typename?: 'Mutation'; + addConnection?: Maybe; + addStardogFree?: Maybe; + deleteCloud?: Maybe; + deleteConnection?: Maybe; + editConnection?: Maybe; + generateConfiguration?: Maybe; + startBillingSession?: Maybe; + updateProfile?: Maybe; +}; + + +/** Available mutations */ +export type MutationAddConnectionArgs = { + input: AddConnectionInput; +}; + + +/** Available mutations */ +export type MutationDeleteCloudArgs = { + input: CloudCleanupInput; +}; + + +/** Available mutations */ +export type MutationDeleteConnectionArgs = { + name: Scalars['String']; +}; + + +/** Available mutations */ +export type MutationEditConnectionArgs = { + input: EditConnectionInput; +}; + + +/** Available mutations */ +export type MutationGenerateConfigurationArgs = { + endpoint: Scalars['String']; +}; + + +/** Available mutations */ +export type MutationStartBillingSessionArgs = { + input: BillingSessionInput; +}; + + +/** Available mutations */ +export type MutationUpdateProfileArgs = { + input?: InputMaybe; +}; + +/** + * An Auth0 auth token stored for the user, do not add secret values here such as + * refresh_token or client_id. + */ +export type OAuthToken = { + __typename?: 'OAuthToken'; + access_token?: Maybe; + id: Scalars['ID']; + id_token?: Maybe; + scope?: Maybe; + user: User; +}; + +export type ProfileInput = { + company: Scalars['String']; + first_name: Scalars['String']; + last_name: Scalars['String']; + phone: Scalars['String']; + title: Scalars['String']; + use_case: Scalars['String']; +}; + +export type PurchaseSession = { + __typename?: 'PurchaseSession'; + isWaitingForPayment?: Maybe; + status?: Maybe; + url?: Maybe; +}; + +/** Available queries */ +export type Query = { + __typename?: 'Query'; + checkCloudQueue?: Maybe; + generateToken?: Maybe; + getConnection?: Maybe; + getConnectionByIndex?: Maybe; + getStardogCloud?: Maybe; + getStardogFree?: Maybe; + getStripeSubscriptionOrderSession?: Maybe; + getStripeSubscriptionStatus?: Maybe; + listConnections?: Maybe>>; + listStardogCloud?: Maybe>>; + profile?: Maybe; +}; + + +/** Available queries */ +export type QueryGenerateTokenArgs = { + endpoint: Scalars['String']; +}; + + +/** Available queries */ +export type QueryGetConnectionArgs = { + name: Scalars['String']; +}; + + +/** Available queries */ +export type QueryGetConnectionByIndexArgs = { + index: Scalars['Int']; +}; + + +/** Available queries */ +export type QueryGetStardogCloudArgs = { + pk: Scalars['String']; +}; + + +/** Available queries */ +export type QueryGetStripeSubscriptionOrderSessionArgs = { + cloudName: Scalars['String']; +}; + + +/** Available queries */ +export type QueryGetStripeSubscriptionStatusArgs = { + cloudName: Scalars['String']; +}; + +/** Contains the counts of available cloud resources to sell. */ +export type QueueCounts = { + __typename?: 'QueueCounts'; + medium_count?: Maybe; + micro_count?: Maybe; + small_count?: Maybe; +}; + +/** Quota limits and usage for a given user. */ +export type Quota = { + __typename?: 'Quota'; + available?: Maybe; + total?: Maybe; +}; + +/** Stardog Cloud, represents an instance of Cloud that is owned by the user */ +export type StardogCloud = { + __typename?: 'StardogCloud'; + bi_endpoint?: Maybe; + created?: Maybe; + endpoint?: Maybe; + flavor?: Maybe; + id?: Maybe; + name?: Maybe; + updated?: Maybe; +}; + +/** Stardog Free Installation */ +export type StardogFree = { + __typename?: 'StardogFree'; + company?: Maybe; + email?: Maybe; + expires?: Maybe; + id?: Maybe; + installer?: Maybe; + phone?: Maybe; + title?: Maybe; + use_case?: Maybe; + user?: Maybe; + version?: Maybe; +}; + +export type StardogFreeInstaller = { + __typename?: 'StardogFreeInstaller'; + id?: Maybe; + install_url?: Maybe; + version?: Maybe; +}; + +/** Stripe Customer: If the user is a paying customer */ +export type StripeCustomer = { + __typename?: 'StripeCustomer'; + cloud_quota?: Maybe; + customer_id?: Maybe; + customer_portal_url?: Maybe; + is_cloud_quota_breached?: Maybe; +}; + +export type StripeSubscriptionStatus = { + __typename?: 'StripeSubscriptionStatus'; + status: Scalars['String']; +}; + +/** + * The user model, this represents a user from Auth0. Only fields defined here + * are exposed in the possible GraphQL responses. + */ +export type User = { + __typename?: 'User'; + company?: Maybe; + email?: Maybe; + first_name?: Maybe; + has_updated_profile?: Maybe; + id?: Maybe; + is_authenticated: Scalars['Boolean']; + is_ephemeral?: Maybe; + is_superuser?: Maybe; + is_verified?: Maybe; + last_name?: Maybe; + phone?: Maybe; + stripe_customer?: Maybe; + sub?: Maybe; + title?: Maybe; + use_case?: Maybe; + username: Scalars['String']; +}; + +export type ListConnectionsQueryVariables = Exact<{ [key: string]: never; }>; + + +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?: { __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 = ` + query listConnections { + listConnections { + id + name + username + endpoint + token + isStardogCloud + isStardogFree + isAllocating + useSSO + } +} + `; +export const ProfileDocument = ` + query profile { + profile { + id + username + email + first_name + last_name + company + use_case + is_authenticated + is_superuser + } +} + `; + +export type SdkFunctionWrapper = (action: (requestHeaders?:Record) => Promise, operationName: string) => Promise; + + +const defaultWrapper: SdkFunctionWrapper = (action, _operationName) => action(); + +export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) { + return { + listConnections(variables?: ListConnectionsQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { + return withWrapper((wrappedRequestHeaders) => client.request(ListConnectionsDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'listConnections'); + }, + profile(variables?: ProfileQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise { + return withWrapper((wrappedRequestHeaders) => client.request(ProfileDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'profile'); + } + }; +} +export type Sdk = ReturnType; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index bfdcec0..a56f01f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -503,14 +503,6 @@ ts-node "^9" tslib "^2" -"@graphql-codegen/add@3.1.1": - version "3.1.1" - resolved "https://registry.yarnpkg.com/@graphql-codegen/add/-/add-3.1.1.tgz#e161ff1c7cdf74ce20b32f75f640f9592b9a18ca" - integrity sha512-XkVwcqosa0CVBlL1HaQT0gp+EUfhuQE3LzrEpzMQLwchxaj/NPVYtOJL6MUHaYDsHzLqxWrufjfbeB3y2NQgRw== - dependencies: - "@graphql-codegen/plugin-helpers" "^2.3.2" - tslib "~2.3.0" - "@graphql-codegen/cli@2.5.0": version "2.5.0" resolved "https://registry.yarnpkg.com/@graphql-codegen/cli/-/cli-2.5.0.tgz#a8d3be7b15159d2549af8f76bebba708231727b2"