shoal-web-sdk 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
- {
2
- "name": "shoal-web-sdk",
3
- "version": "0.0.2",
4
- "main": "index.js",
5
- "scripts": {
6
- "build-hooks": "npx tsx tanstack-codegen/generator.ts",
7
- "build-sdk": "npx openapi-ts",
8
- "build": "npm run build-sdk && npm run build-hooks"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/shoal-platform/shoal-web-sdk.git"
13
- },
14
- "keywords": [],
15
- "author": "",
16
- "license": "ISC",
17
- "bugs": {
18
- "url": "https://github.com/shoal-platform/shoal-web-sdk/issues"
19
- },
20
- "homepage": "https://github.com/shoal-platform/shoal-web-sdk#readme",
21
- "description": "",
22
- "devDependencies": {
23
- "@hey-api/openapi-ts": "0.86.11",
24
- "@types/node": "^24.10.0"
25
- },
26
- "dependencies": {
27
- "@tanstack/react-query": "^5.90.7"
28
- },
29
- "files": [
30
- "sdk/**/*",
31
- "tanstack-codegen/generated/generated.ts"
32
- ],
33
- "exports": {
34
- "./sdk/*": "./sdk/*",
35
- "./hooks": "./tanstack-codegen/generated/generated.ts",
36
- "./client": "./sdk/client.gen.ts"
37
- }
38
- }
1
+ {
2
+ "name": "shoal-web-sdk",
3
+ "version": "0.0.5",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "build-hooks": "npx tsx tanstack-codegen/generator.ts",
7
+ "build-sdk": "npx openapi-ts",
8
+ "build": "npm run build-sdk && npm run build-hooks"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/shoal-platform/shoal-web-sdk.git"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "bugs": {
18
+ "url": "https://github.com/shoal-platform/shoal-web-sdk/issues"
19
+ },
20
+ "homepage": "https://github.com/shoal-platform/shoal-web-sdk#readme",
21
+ "description": "",
22
+ "devDependencies": {
23
+ "@hey-api/openapi-ts": "0.86.11",
24
+ "@types/node": "^24.10.0"
25
+ },
26
+ "dependencies": {
27
+ "@tanstack/react-query": "^5.90.7"
28
+ },
29
+ "files": [
30
+ "sdk/**/*",
31
+ "tanstack-codegen/generated/generated.ts"
32
+ ],
33
+ "exports": {
34
+ "./sdk/*": "./sdk/*",
35
+ "./hooks": "./tanstack-codegen/generated/generated.ts",
36
+ "./client": "./sdk/client.gen.ts"
37
+ }
38
+ }
package/sdk/client.gen.ts CHANGED
@@ -14,5 +14,5 @@ import type { ClientOptions as ClientOptions2 } from './types.gen';
14
14
  export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
15
15
 
16
16
  export const client = createClient(createConfig<ClientOptions2>({
17
- baseUrl: 'http://localhost:8080/core-service/v1'
17
+ baseUrl: 'http://localhost:8080/core-service'
18
18
  }));
package/sdk/sdk.gen.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type { Client, Options as Options2, TDataShape } from './client';
4
4
  import { client } from './client.gen';
5
- import type { GetHelloData, GetHelloResponses } from './types.gen';
5
+ import type { GetServiceHealthData, GetServiceHealthResponses, RegisterAccountData, RegisterAccountErrors, RegisterAccountResponses } from './types.gen';
6
6
 
7
7
  export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = Options2<TData, ThrowOnError> & {
8
8
  /**
@@ -19,19 +19,37 @@ export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends
19
19
  };
20
20
 
21
21
  /**
22
- * Hello world
23
- *
24
- * Simple health / sanity endpoint
22
+ * Get service health.
25
23
  */
26
- export const getHello = <ThrowOnError extends boolean = false>(options?: Options<GetHelloData, ThrowOnError>) => {
27
- return (options?.client ?? client).get<GetHelloResponses, unknown, ThrowOnError>({
24
+ export const getServiceHealth = <ThrowOnError extends boolean = false>(options?: Options<GetServiceHealthData, ThrowOnError>) => {
25
+ return (options?.client ?? client).get<GetServiceHealthResponses, unknown, ThrowOnError>({
28
26
  security: [
29
27
  {
30
28
  scheme: 'bearer',
31
29
  type: 'http'
32
30
  }
33
31
  ],
34
- url: '/hello',
32
+ url: '/heath',
35
33
  ...options
36
34
  });
37
35
  };
36
+
37
+ /**
38
+ * Registers an account through kinde's webhook.
39
+ */
40
+ export const registerAccount = <ThrowOnError extends boolean = false>(options?: Options<RegisterAccountData, ThrowOnError>) => {
41
+ return (options?.client ?? client).post<RegisterAccountResponses, RegisterAccountErrors, ThrowOnError>({
42
+ security: [
43
+ {
44
+ scheme: 'bearer',
45
+ type: 'http'
46
+ }
47
+ ],
48
+ url: '/register',
49
+ ...options,
50
+ headers: {
51
+ 'Content-Type': 'application/json',
52
+ ...options?.headers
53
+ }
54
+ });
55
+ };
package/sdk/types.gen.ts CHANGED
@@ -1,23 +1,116 @@
1
1
  // This file is auto-generated by @hey-api/openapi-ts
2
2
 
3
3
  export type ClientOptions = {
4
- baseUrl: 'http://localhost:8080/core-service/v1' | (string & {});
4
+ baseUrl: 'http://localhost:8080/core-service' | (string & {});
5
5
  };
6
6
 
7
- export type GetHelloData = {
7
+ export type HealthResponse = {
8
+ status: string;
9
+ };
10
+
11
+ export type ErrorResponse = {
12
+ message: string;
13
+ internalCode: unknown;
14
+ };
15
+
16
+ /**
17
+ * The request body that kinde attaches during callback account creation.
18
+ */
19
+ export type CallBackClaims = {
20
+ data: {
21
+ user: {
22
+ email?: string;
23
+ first_name?: string;
24
+ id: string;
25
+ is_password_reset_requested?: boolean;
26
+ is_suspended?: boolean;
27
+ last_name?: string;
28
+ organizations?: Array<{
29
+ code?: string;
30
+ /**
31
+ * Arbitrary JSON
32
+ */
33
+ permissions?: unknown;
34
+ /**
35
+ * Arbitrary JSON
36
+ */
37
+ roles?: unknown;
38
+ }>;
39
+ /**
40
+ * Arbitrary JSON
41
+ */
42
+ phone?: unknown;
43
+ /**
44
+ * Arbitrary JSON
45
+ */
46
+ username?: unknown;
47
+ };
48
+ };
49
+ event_id: string;
50
+ event_timestamp: string;
51
+ source: string;
52
+ timestamp: string;
53
+ type: string;
54
+ };
55
+
56
+ export type AccountDetails = {
57
+ id: string;
58
+ kindeSub: string;
59
+ preferredEmail: string;
60
+ phone: string;
61
+ username: string;
62
+ firstName: string;
63
+ lastName: string;
64
+ isSuspended: unknown;
65
+ picture: string;
66
+ totalSignIns: unknown;
67
+ failedSignIns: unknown;
68
+ lastSignedIn: string;
69
+ createdAt: string;
70
+ };
71
+
72
+ export type GetServiceHealthData = {
8
73
  body?: never;
9
74
  path?: never;
10
75
  query?: never;
11
- url: '/hello';
76
+ url: '/heath';
12
77
  };
13
78
 
14
- export type GetHelloResponses = {
79
+ export type GetServiceHealthResponses = {
15
80
  /**
16
- * Hello world response
81
+ * Service is healthy!
17
82
  */
18
- 200: {
19
- message?: string;
20
- };
83
+ 200: HealthResponse;
21
84
  };
22
85
 
23
- export type GetHelloResponse = GetHelloResponses[keyof GetHelloResponses];
86
+ export type GetServiceHealthResponse = GetServiceHealthResponses[keyof GetServiceHealthResponses];
87
+
88
+ export type RegisterAccountData = {
89
+ /**
90
+ * Kinde account creation callback.
91
+ */
92
+ body?: CallBackClaims;
93
+ path?: never;
94
+ query?: never;
95
+ url: '/register';
96
+ };
97
+
98
+ export type RegisterAccountErrors = {
99
+ /**
100
+ * When creating the account or parsing the claims fails.
101
+ */
102
+ 403: ErrorResponse;
103
+ /**
104
+ * If parsing json fails, or an unknown error occurs.
105
+ */
106
+ 500: ErrorResponse;
107
+ };
108
+
109
+ export type RegisterAccountError = RegisterAccountErrors[keyof RegisterAccountErrors];
110
+
111
+ export type RegisterAccountResponses = {
112
+ /**
113
+ * An account is registered in our system.
114
+ */
115
+ 201: unknown;
116
+ };
@@ -5,19 +5,19 @@ import { useAccessToken } from "@/lib/hooks/auth"
5
5
 
6
6
  import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
7
7
  import { isPromise } from "../util"
8
- import { GetHelloData } from "../../sdk/types.gen"
9
- import { getHello } from "../../sdk/sdk.gen"
8
+ import { GetServiceHealthData, RegisterAccountData } from "../../sdk/types.gen"
9
+ import { getServiceHealth, registerAccount } from "../../sdk/sdk.gen"
10
10
 
11
- export const useGetHello = (options?:Omit<GetHelloData, "url"> & {enabled?:boolean}) =>
11
+ export const useGetServiceHealth = (options?:Omit<GetServiceHealthData, "url"> & {enabled?:boolean}) =>
12
12
  {
13
13
  const token = useAccessToken();
14
14
  let {enabled, ...rest} = options || { enabled: true };
15
- const opts = { throwOnError: true, url: "/hello" }
15
+ const opts = { throwOnError: true, url: "/heath" }
16
16
  const funcer = async () =>
17
17
  {
18
18
  const auth = isPromise(token) ? (await token) || "" : token || "";
19
19
  if(isPromise(token) && !token) return;
20
- const res = await getHello({ ...opts, ...rest, auth })
20
+ const res = await getServiceHealth({ ...opts, ...rest, auth })
21
21
  return res.data;
22
22
  }
23
23
 
@@ -25,9 +25,34 @@ export const useGetHello = (options?:Omit<GetHelloData, "url"> & {enabled?:boole
25
25
 
26
26
  return useQuery(
27
27
  {
28
- queryKey: ["hello", options?.query ?? {}],
28
+ queryKey: ["heath", options?.query ?? {}],
29
29
  queryFn: funcer,
30
30
  enabled,
31
31
  retry: false
32
32
  })
33
+ }
34
+
35
+ export const useRegisterAccount = (config?:{onSuccess?: Parameters<typeof useMutation>["0"]["onSuccess"], onError?: Parameters<typeof useMutation>["0"]["onError"], retry?:boolean}) =>
36
+ {
37
+ const token = useAccessToken();
38
+ const queryClient = useQueryClient();
39
+ const opts = { throwOnError: true, url: "/register" }
40
+ const funcer = async (options?: Omit<RegisterAccountData, "url">) =>
41
+ {
42
+ const auth = isPromise(token) ? (await token) || "" : token || "";
43
+ const res = await registerAccount({ ...opts, ...options, auth })
44
+ return res?.data
45
+ }
46
+
47
+ return useMutation(
48
+ {
49
+ mutationFn: funcer,
50
+ onSuccess: (res, options, c, ctx) =>
51
+ {
52
+ queryClient.invalidateQueries({ queryKey: ["register"] });
53
+ config?.onSuccess && config.onSuccess(res, options, c, ctx);
54
+ },
55
+ onError: config?.onError,
56
+ retry: config?.retry
57
+ })
33
58
  }