Compare commits

..

12 Commits

Author SHA1 Message Date
Johan Eliasson
1a4a061284 Merge pull request #1674 from nhost/changeset-release/main
chore: update versions
2023-02-27 11:55:28 +01:00
github-actions[bot]
78555c7e85 chore: update versions 2023-02-27 08:22:19 +00:00
Johan Eliasson
01ded8ffff Merge pull request #1670 from nhost/functions-tests
Functions fix + tests
2023-02-27 09:21:05 +01:00
Johan Eliasson
3c7cf92edf Create .changeset/eighty-mugs-flash.md 2023-02-27 09:20:49 +01:00
Johan Eliasson
bb4301fd34 more tests 2023-02-26 17:49:19 +01:00
Szilárd Dóró
c8c8948755 Merge pull request #1667 from nhost/changeset-release/main
chore: update versions
2023-02-24 12:45:06 +01:00
github-actions[bot]
17e9e5899e chore: update versions 2023-02-24 11:44:31 +00:00
Szilárd Dóró
bd22c48131 Merge pull request #1666 from nhost/fix/workspace-invitation
fix(nhost-js): use correct URL for functions requests
2023-02-24 12:43:02 +01:00
Szilárd Dóró
89a239ff3a fix(nhost-js): improve code readability 2023-02-24 12:22:54 +01:00
Szilárd Dóró
0131886011 fix(nhost-js): use correct URL for functions requests 2023-02-24 12:06:30 +01:00
Szilárd Dóró
340c014fe8 Merge pull request #1664 from nhost/update-codeowners
chore: update codeowners
2023-02-24 11:06:07 +01:00
Szilárd Dóró
bc9c8b9456 chore: update codeowners 2023-02-24 11:05:35 +01:00
51 changed files with 449 additions and 55 deletions

18
.github/CODEOWNERS vendored
View File

@@ -1,14 +1,14 @@
# Documentation # Documentation
# https://help.github.com/en/articles/about-code-owners # https://help.github.com/en/articles/about-code-owners
/packages @plmercereau @szilarddoro /packages @szilarddoro
/packages/docgen @szilarddoro /packages/docgen @szilarddoro
/integrations/stripe-graphql-js @elitan /integrations/stripe-graphql-js @elitan
/.github @plmercereau /.github @szilarddoro
/dashboard/ @szilarddoro @guicurcio /dashboard/ @szilarddoro
/docs/ @guicurcio @elitan /docs/ @elitan
/config/ @plmercereau @szilarddoro /config/ @szilarddoro
/examples/ @plmercereau /examples/ @szilarddoro
/examples/codegen-react-apollo @elitan @plmercereau /examples/codegen-react-apollo @elitan @szilarddoro
/examples/codegen-react-query @elitan @plmercereau /examples/codegen-react-query @elitan @szilarddoro
/examples/react-apollo-crm @elitan @plmercereau /examples/react-apollo-crm @elitan @szilarddoro

View File

@@ -1,5 +1,21 @@
# @nhost/dashboard # @nhost/dashboard
## 0.11.19
### Patch Changes
- @nhost/react-apollo@5.0.6
- @nhost/nextjs@1.13.11
## 0.11.18
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react-apollo@5.0.5
- @nhost/nextjs@1.13.10
## 0.11.17 ## 0.11.17
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/dashboard", "name": "@nhost/dashboard",
"version": "0.11.17", "version": "0.11.19",
"private": true, "private": true,
"scripts": { "scripts": {
"preinstall": "npx only-allow pnpm", "preinstall": "npx only-allow pnpm",

View File

@@ -58,16 +58,19 @@ export function InviteAnnounce() {
error: null, error: null,
loading: true, loading: true,
}); });
const res = await nhost.functions.call('/accept-workspace-invite', { const { res, error: acceptError } = await nhost.functions.call(
workspaceMemberInviteId: invite.id, '/accept-workspace-invite',
isAccepted: true, {
}); workspaceMemberInviteId: invite.id,
isAccepted: true,
},
);
if (res?.res?.status !== 200) { if (res?.status !== 200) {
triggerToast('An error occurred when trying to accept the invitation.'); triggerToast('An error occurred when trying to accept the invitation.');
return setSubmitState({ return setSubmitState({
error: new Error(res.error.message), error: new Error(acceptError.message),
loading: false, loading: false,
}); });
} }
@@ -90,7 +93,7 @@ export function InviteAnnounce() {
error: null, error: null,
}); });
const res = await nhost.functions.call( const { error: ignoreError } = await nhost.functions.call(
'/accept-workspace-invite', '/accept-workspace-invite',
{ {
workspaceMemberInviteId: inviteId, workspaceMemberInviteId: inviteId,
@@ -99,12 +102,12 @@ export function InviteAnnounce() {
{ useAxios: false }, { useAxios: false },
); );
if (res?.error) { if (ignoreError) {
triggerToast('An error occurred when trying to ignore the invitation.'); triggerToast('An error occurred when trying to ignore the invitation.');
setIgnoreState({ setIgnoreState({
loading: false, loading: false,
error: new Error(res.error.message), error: new Error(ignoreError.message),
}); });
return; return;

View File

@@ -1,5 +1,14 @@
# @nhost-examples/codegen-react-apollo # @nhost-examples/codegen-react-apollo
## 0.1.7
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react-apollo@5.0.5
- @nhost/react@2.0.4
## 0.1.6 ## 0.1.6
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost-examples/codegen-react-apollo", "name": "@nhost-examples/codegen-react-apollo",
"version": "0.1.6", "version": "0.1.7",
"private": true, "private": true,
"scripts": { "scripts": {
"codegen": "graphql-codegen", "codegen": "graphql-codegen",

View File

@@ -1,5 +1,13 @@
# @nhost-examples/codegen-react-query # @nhost-examples/codegen-react-query
## 0.1.7
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react@2.0.4
## 0.1.6 ## 0.1.6
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost-examples/codegen-react-query", "name": "@nhost-examples/codegen-react-query",
"version": "0.1.6", "version": "0.1.7",
"private": true, "private": true,
"scripts": { "scripts": {
"codegen": "graphql-codegen", "codegen": "graphql-codegen",

View File

@@ -1,5 +1,14 @@
# @nhost-examples/react-urql # @nhost-examples/react-urql
## 0.0.4
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react-urql@2.0.4
- @nhost/react@2.0.4
## 0.0.3 ## 0.0.3
### Patch Changes ### Patch Changes

View File

@@ -1,7 +1,7 @@
{ {
"name": "@nhost-examples/codegen-react-urql", "name": "@nhost-examples/codegen-react-urql",
"private": true, "private": true,
"version": "0.0.3", "version": "0.0.4",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc && vite build", "build": "tsc && vite build",

View File

@@ -1,5 +1,11 @@
# @nhost-examples/docker-compose # @nhost-examples/docker-compose
## 0.0.5
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
## 0.0.4 ## 0.0.4
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost-examples/docker-compose", "name": "@nhost-examples/docker-compose",
"version": "0.0.4", "version": "0.0.5",
"private": true, "private": true,
"scripts": { "scripts": {
"e2e": "vitest run" "e2e": "vitest run"

View File

@@ -1,5 +1,13 @@
# @nhost-examples/multi-tenant-one-to-many # @nhost-examples/multi-tenant-one-to-many
## 1.0.3
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/nhost-js@2.0.4
## 1.0.2 ## 1.0.2
### Patch Changes ### Patch Changes

View File

@@ -1,7 +1,7 @@
{ {
"name": "@nhost-examples/multi-tenant-one-to-many", "name": "@nhost-examples/multi-tenant-one-to-many",
"private": true, "private": true,
"version": "1.0.2", "version": "1.0.3",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": {}, "scripts": {},

View File

@@ -1,5 +1,15 @@
# @nhost-examples/nextjs # @nhost-examples/nextjs
## 0.1.7
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react-apollo@5.0.5
- @nhost/nextjs@1.13.10
- @nhost/react@2.0.4
## 0.1.6 ## 0.1.6
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost-examples/nextjs", "name": "@nhost-examples/nextjs",
"version": "0.1.6", "version": "0.1.7",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",

View File

@@ -1,5 +1,14 @@
# @nhost-examples/react-apollo # @nhost-examples/react-apollo
## 0.1.9
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react-apollo@5.0.5
- @nhost/react@2.0.4
## 0.1.8 ## 0.1.8
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost-examples/react-apollo", "name": "@nhost-examples/react-apollo",
"version": "0.1.8", "version": "0.1.9",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@apollo/client": "^3.6.9", "@apollo/client": "^3.6.9",

View File

@@ -1,5 +1,13 @@
# @nhost-examples/react-gqty # @nhost-examples/react-gqty
## 0.0.6
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react@2.0.4
## 0.0.5 ## 0.0.5
### Patch Changes ### Patch Changes

View File

@@ -1,7 +1,7 @@
{ {
"name": "@nhost-examples/react-gqty", "name": "@nhost-examples/react-gqty",
"private": true, "private": true,
"version": "0.0.5", "version": "0.0.6",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -0,0 +1,7 @@
# @nhost-examples/seed-data-storage
## 0.0.2
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests

View File

@@ -1,7 +1,7 @@
{ {
"name": "@nhost-examples/seed-data-storage", "name": "@nhost-examples/seed-data-storage",
"private": true, "private": true,
"version": "0.0.1", "version": "0.0.2",
"scripts": { "scripts": {
"seed-storage": "./seed-storage.sh" "seed-storage": "./seed-storage.sh"
} }

View File

@@ -1,5 +1,13 @@
# @nhost-examples/serverless-functions # @nhost-examples/serverless-functions
## 0.0.7
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/stripe-graphql-js@1.0.2
## 0.0.6 ## 0.0.6
### Patch Changes ### Patch Changes

View File

@@ -1,13 +1,13 @@
{ {
"name": "@nhost-examples/serverless-functions", "name": "@nhost-examples/serverless-functions",
"private": true, "private": true,
"version": "0.0.6", "version": "0.0.7",
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.13" "@types/express": "^4.17.13"
}, },
"dependencies": { "dependencies": {
"@graphql-yoga/node": "^2.13.13", "@graphql-yoga/node": "^2.13.13",
"@nhost/stripe-graphql-js": "^1.0.1", "@nhost/stripe-graphql-js": "^1.0.2",
"@pothos/core": "^3.21.0", "@pothos/core": "^3.21.0",
"cross-fetch": "^3.1.5", "cross-fetch": "^3.1.5",
"graphql": "15.7.2", "graphql": "15.7.2",

View File

@@ -1,5 +1,14 @@
# @nhost-examples/vue-apollo # @nhost-examples/vue-apollo
## 0.0.7
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/apollo@5.0.4
- @nhost/vue@1.13.10
## 0.0.6 ## 0.0.6
### Patch Changes ### Patch Changes

View File

@@ -1,7 +1,7 @@
{ {
"name": "@nhost-examples/vue-apollo", "name": "@nhost-examples/vue-apollo",
"private": true, "private": true,
"version": "0.0.6", "version": "0.0.7",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",

View File

@@ -1,5 +1,14 @@
# @nhost-examples/vue-quickstart # @nhost-examples/vue-quickstart
## 0.0.6
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/apollo@5.0.4
- @nhost/vue@1.13.10
## 0.0.5 ## 0.0.5
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost-examples/vue-quickstart", "name": "@nhost-examples/vue-quickstart",
"version": "0.0.5", "version": "0.0.6",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "vite build", "build": "vite build",

View File

@@ -1,5 +1,20 @@
# @nhost/apollo # @nhost/apollo
## 5.0.5
### Patch Changes
- Updated dependencies [3c7cf92e]
- @nhost/nhost-js@2.0.5
## 5.0.4
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/nhost-js@2.0.4
## 5.0.3 ## 5.0.3
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/apollo", "name": "@nhost/apollo",
"version": "5.0.3", "version": "5.0.5",
"description": "Nhost Apollo Client library", "description": "Nhost Apollo Client library",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [

View File

@@ -1,5 +1,11 @@
# @nhost/google-translation # @nhost/google-translation
## 0.0.3
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
## 0.0.2 ## 0.0.2
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/google-translation", "name": "@nhost/google-translation",
"version": "0.0.2", "version": "0.0.3",
"description": "Google Translation GraphQL API", "description": "Google Translation GraphQL API",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [

View File

@@ -1,5 +1,21 @@
# @nhost/react-apollo # @nhost/react-apollo
## 5.0.6
### Patch Changes
- @nhost/apollo@5.0.5
- @nhost/react@2.0.5
## 5.0.5
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/apollo@5.0.4
- @nhost/react@2.0.4
## 5.0.4 ## 5.0.4
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/react-apollo", "name": "@nhost/react-apollo",
"version": "5.0.4", "version": "5.0.6",
"description": "Nhost React Apollo client", "description": "Nhost React Apollo client",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [

View File

@@ -1,5 +1,19 @@
# @nhost/react-urql # @nhost/react-urql
## 2.0.5
### Patch Changes
- @nhost/react@2.0.5
## 2.0.4
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react@2.0.4
## 2.0.3 ## 2.0.3
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/react-urql", "name": "@nhost/react-urql",
"version": "2.0.3", "version": "2.0.5",
"description": "Nhost React URQL client", "description": "Nhost React URQL client",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [

View File

@@ -1,5 +1,11 @@
# @nhost/stripe-graphql-js # @nhost/stripe-graphql-js
## 1.0.2
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
## 1.0.1 ## 1.0.1
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/stripe-graphql-js", "name": "@nhost/stripe-graphql-js",
"version": "1.0.1", "version": "1.0.2",
"description": "Stripe GraphQL API", "description": "Stripe GraphQL API",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [

View File

@@ -1,5 +1,19 @@
# @nhost/nextjs # @nhost/nextjs
## 1.13.11
### Patch Changes
- @nhost/react@2.0.5
## 1.13.10
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/react@2.0.4
## 1.13.9 ## 1.13.9
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/nextjs", "name": "@nhost/nextjs",
"version": "1.13.9", "version": "1.13.11",
"description": "Nhost NextJS library", "description": "Nhost NextJS library",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [

View File

@@ -1,5 +1,17 @@
# @nhost/nhost-js # @nhost/nhost-js
## 2.0.5
### Patch Changes
- 3c7cf92e: fixing generating the correct URL for function calls
## 2.0.4
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
## 2.0.3 ## 2.0.3
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/nhost-js", "name": "@nhost/nhost-js",
"version": "2.0.3", "version": "2.0.5",
"description": "Nhost JavaScript SDK", "description": "Nhost JavaScript SDK",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [
@@ -58,14 +58,13 @@
"verify:fix": "run-p prettier:fix lint:fix" "verify:fix": "run-p prettier:fix lint:fix"
}, },
"dependencies": { "dependencies": {
"@nhost/graphql-js": "workspace:*",
"@nhost/hasura-auth-js": "workspace:*", "@nhost/hasura-auth-js": "workspace:*",
"@nhost/hasura-storage-js": "workspace:*", "@nhost/hasura-storage-js": "workspace:*",
"@nhost/graphql-js": "workspace:*",
"cross-fetch": "^3.1.5" "cross-fetch": "^3.1.5"
}, },
"devDependencies": { "devDependencies": {
"graphql": "16.6.0", "graphql": "16.6.0"
"start-server-and-test": "^1.15.2"
}, },
"peerDependencies": { "peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"

View File

@@ -1,5 +1,5 @@
import fetch from 'cross-fetch' import fetch from 'cross-fetch'
import { urlFromSubdomain } from '../../utils/helpers' import { buildUrl, urlFromSubdomain } from '../../utils/helpers'
import { NhostClientConstructorParams } from '../../utils/types' import { NhostClientConstructorParams } from '../../utils/types'
import { import {
NhostFunctionCallConfig, NhostFunctionCallConfig,
@@ -65,21 +65,27 @@ export class NhostFunctionsClient {
...config?.headers ...config?.headers
} }
const fullUrl = buildUrl(this.url, url)
try { try {
const result = await fetch(url, { const result = await fetch(fullUrl, {
body: JSON.stringify(body), body: JSON.stringify(body),
headers, headers,
method: 'POST' method: 'POST'
}) })
if (!result.ok) { if (!result.ok) {
throw new Error(result.statusText) throw new Error(result.statusText)
} }
let data: T let data: T
try {
if (result.headers.get('content-type') === 'application/json') {
data = await result.json() data = await result.json()
} catch { } else {
data = (await result.text()) as unknown as T data = (await result.text()) as unknown as T
} }
return { return {
res: { data, status: result.status, statusText: result.statusText }, res: { data, status: result.status, statusText: result.statusText },
error: null error: null
@@ -116,7 +122,7 @@ export class NhostFunctionsClient {
this.accessToken = accessToken this.accessToken = accessToken
} }
private generateAccessTokenHeaders(): NhostFunctionCallConfig['headers'] { generateAccessTokenHeaders(): NhostFunctionCallConfig['headers'] {
if (this.adminSecret) { if (this.adminSecret) {
return { return {
'x-hasura-admin-secret': this.adminSecret 'x-hasura-admin-secret': this.adminSecret

View File

@@ -1,7 +1,8 @@
import { NhostClientConstructorParams } from './types' import { NhostClientConstructorParams } from './types'
// a port can be a number or a placeholder string with leading and trailing double underscores, f.e. "8080" or "__PLACEHOLDER_NAME__" // a port can be a number or a placeholder string with leading and trailing double underscores, f.e. "8080" or "__PLACEHOLDER_NAME__"
const LOCALHOST_REGEX = /^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/ export const LOCALHOST_REGEX =
/^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/
/** /**
* `backendUrl` should now be used only when self-hosting * `backendUrl` should now be used only when self-hosting
@@ -73,3 +74,16 @@ function getValueFromEnv(service: string) {
return process.env[`NHOST_${service.toUpperCase()}_URL`] return process.env[`NHOST_${service.toUpperCase()}_URL`]
} }
/**
* Combines a base URL and a path into a single URL string.
*
* @param baseUrl - The base URL to use.
* @param path - The path to append to the base URL.
* @returns The combined URL string.
*/
export function buildUrl(baseUrl: string, path: string) {
const hasLeadingSlash = path.startsWith('/')
const urlPath = hasLeadingSlash ? path : `/${path}`
return baseUrl + urlPath
}

View File

@@ -0,0 +1,79 @@
import { describe, it, expect, afterEach, beforeEach } from 'vitest'
import { urlFromSubdomain } from '../src/utils/helpers'
import { createFunctionsClient, NhostFunctionsClient } from '../src/clients/functions'
describe('createFunctionsClient', () => {
it('should throw an error if neither subdomain nor functionsUrl are provided', () => {
expect(() => {
createFunctionsClient({})
}).toThrow()
})
it('should throw an error if a non localhost subdomain is used without a region', () => {
const subdomain = 'test-subdomain'
expect(() => {
createFunctionsClient({ subdomain })
}).toThrow()
})
it('should create a client with localhost as a subdomain without a region subdomain', () => {
const subdomain = 'localhost'
const client = createFunctionsClient({ subdomain })
expect(client).toBeInstanceOf(NhostFunctionsClient)
expect(client.url).toEqual(urlFromSubdomain({ subdomain }, 'functions'))
})
it('should create a client with non localhost subdomain and any region', () => {
const subdomain = 'localhost'
const region = 'eu-central-1'
const client = createFunctionsClient({ subdomain, region })
expect(client).toBeInstanceOf(NhostFunctionsClient)
expect(client.url).toEqual(urlFromSubdomain({ subdomain, region }, 'functions'))
})
it('should create a client with functionsUrl', () => {
const functionsUrl = 'http://test-functions-url'
const client = createFunctionsClient({ functionsUrl })
expect(client).toBeInstanceOf(NhostFunctionsClient)
expect(client.url).toEqual(functionsUrl)
})
})
describe('NhostFunctionsClient', () => {
let client: NhostFunctionsClient
beforeEach(() => {
client = new NhostFunctionsClient({ url: 'http://test-url' })
})
it('should set the access token', () => {
const accessToken = 'test-access-token'
client.setAccessToken(accessToken)
expect(client.generateAccessTokenHeaders()).toEqual({
Authorization: `Bearer ${accessToken}`
})
})
it('should clear the access token', () => {
const accessToken = 'test-access-token'
client.setAccessToken(accessToken)
client.setAccessToken(undefined)
expect(client.generateAccessTokenHeaders()).toEqual({})
})
it('should generate headers with admin secret', () => {
const adminSecret = 'test-admin-secret'
const clientWithAdminSecret = new NhostFunctionsClient({ url: 'http://test-url', adminSecret })
expect(clientWithAdminSecret.generateAccessTokenHeaders()).toEqual({
'x-hasura-admin-secret': adminSecret
})
})
})

View File

@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest' import { describe, it, expect } from 'vitest'
import { urlFromSubdomain } from '../src/utils/helpers' import { buildUrl, LOCALHOST_REGEX, urlFromSubdomain } from '../src/utils/helpers'
describe('urlFromParams', () => { describe('urlFromParams', () => {
describe('when using backendUrl', () => { describe('when using backendUrl', () => {
@@ -81,3 +81,69 @@ describe('urlFromParams', () => {
}) })
}) })
}) })
describe('buildUrl', () => {
it('should combine base URL and path', () => {
const baseUrl = 'https://example.com'
const path = '/api/users'
expect(buildUrl(baseUrl, path)).toBe('https://example.com/api/users')
})
it('should add missing leading slash to path', () => {
const baseUrl = 'https://example.com'
const path = 'api/users'
expect(buildUrl(baseUrl, path)).toBe('https://example.com/api/users')
})
it('should handle empty base URL', () => {
const baseUrl = ''
const path = '/api/users'
expect(buildUrl(baseUrl, path)).toBe('/api/users')
})
it('should handle empty path', () => {
const baseUrl = 'https://example.com'
const path = ''
expect(buildUrl(baseUrl, path)).toBe('https://example.com/')
})
it('should handle missing parameters', () => {
expect(() => buildUrl()).toThrow()
expect(() => buildUrl('https://example.com')).toThrow()
})
})
describe('LOCALHOST_REGEX', () => {
it('should match localhost without protocol or port', () => {
const input = 'localhost'
const match = input.match(LOCALHOST_REGEX)
expect(match?.groups).toEqual({ host: 'localhost', protocol: undefined, port: undefined })
})
it('should match localhost with http protocol', () => {
const input = 'http://localhost'
const match = input.match(LOCALHOST_REGEX)
expect(match?.groups).toEqual({ host: 'localhost', protocol: 'http', port: undefined })
})
it('should match localhost with https protocol and port', () => {
const input = 'https://localhost:8443'
const match = input.match(LOCALHOST_REGEX)
expect(match?.groups).toEqual({ host: 'localhost', protocol: 'https', port: '8443' })
})
it('should match localhost with named port placeholder', () => {
const input = 'http://localhost:__PORT_NAME__'
const match = input.match(LOCALHOST_REGEX)
expect(match?.groups).toEqual({ host: 'localhost', protocol: 'http', port: '__PORT_NAME__' })
})
it('should not match other URLs', () => {
const input1 = 'https://www.example.com'
const input2 = 'http://127.0.0.1:3000'
const match1 = input1.match(LOCALHOST_REGEX)
const match2 = input2.match(LOCALHOST_REGEX)
expect(match1).toBeNull()
expect(match2).toBeNull()
})
})

View File

@@ -1,5 +1,20 @@
# @nhost/react # @nhost/react
## 2.0.5
### Patch Changes
- Updated dependencies [3c7cf92e]
- @nhost/nhost-js@2.0.5
## 2.0.4
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/nhost-js@2.0.4
## 2.0.3 ## 2.0.3
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/react", "name": "@nhost/react",
"version": "2.0.3", "version": "2.0.5",
"description": "Nhost React library", "description": "Nhost React library",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [

View File

@@ -1,5 +1,20 @@
# @nhost/vue # @nhost/vue
## 1.13.11
### Patch Changes
- Updated dependencies [3c7cf92e]
- @nhost/nhost-js@2.0.5
## 1.13.10
### Patch Changes
- 01318860: fix(nhost-js): use correct URL for functions requests
- Updated dependencies [01318860]
- @nhost/nhost-js@2.0.4
## 1.13.9 ## 1.13.9
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@nhost/vue", "name": "@nhost/vue",
"version": "1.13.9", "version": "1.13.11",
"description": "Nhost Vue library", "description": "Nhost Vue library",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [

6
pnpm-lock.yaml generated
View File

@@ -684,7 +684,7 @@ importers:
examples/serverless-functions: examples/serverless-functions:
specifiers: specifiers:
'@graphql-yoga/node': ^2.13.13 '@graphql-yoga/node': ^2.13.13
'@nhost/stripe-graphql-js': ^1.0.1 '@nhost/stripe-graphql-js': ^1.0.2
'@pothos/core': ^3.21.0 '@pothos/core': ^3.21.0
'@types/express': ^4.17.13 '@types/express': ^4.17.13
cross-fetch: ^3.1.5 cross-fetch: ^3.1.5
@@ -1027,7 +1027,6 @@ importers:
'@nhost/hasura-storage-js': workspace:* '@nhost/hasura-storage-js': workspace:*
cross-fetch: ^3.1.5 cross-fetch: ^3.1.5
graphql: 16.6.0 graphql: 16.6.0
start-server-and-test: ^1.15.2
dependencies: dependencies:
'@nhost/graphql-js': link:../graphql-js '@nhost/graphql-js': link:../graphql-js
'@nhost/hasura-auth-js': link:../hasura-auth-js '@nhost/hasura-auth-js': link:../hasura-auth-js
@@ -1035,7 +1034,6 @@ importers:
cross-fetch: 3.1.5 cross-fetch: 3.1.5
devDependencies: devDependencies:
graphql: 16.6.0 graphql: 16.6.0
start-server-and-test: 1.15.2
packages/react: packages/react:
specifiers: specifiers:
@@ -12817,7 +12815,7 @@ packages:
'@babel/plugin-transform-react-jsx-source': 7.19.6_@babel+core@7.20.5 '@babel/plugin-transform-react-jsx-source': 7.19.6_@babel+core@7.20.5
magic-string: 0.27.0 magic-string: 0.27.0
react-refresh: 0.14.0 react-refresh: 0.14.0
vite: 4.0.2_@types+node@18.11.17 vite: 4.0.2_@types+node@16.18.11
transitivePeerDependencies: transitivePeerDependencies:
- supports-color - supports-color
dev: true dev: true