@viyv/account-client 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2026 viyv. All Rights Reserved.
2
+
3
+ PROPRIETARY AND CONFIDENTIAL
4
+
5
+ This software and its source code (the "Software") are the proprietary and
6
+ confidential property of viyv. Unauthorized copying, distribution,
7
+ modification, public display, public performance, reverse engineering, or
8
+ commercial use of the Software, in whole or in part, via any medium, is
9
+ strictly prohibited without the express prior written permission of viyv.
10
+
11
+ No license, express or implied, by estoppel or otherwise, to any intellectual
12
+ property rights is granted by this document. The receipt or possession of the
13
+ Software does not convey or imply any right to use, reproduce, disclose, or
14
+ distribute its contents.
15
+
16
+ Separately published SDK packages (e.g. @viyv/account-client,
17
+ @viyv/license-verify) may be distributed as compiled artifacts under their own
18
+ published package terms; that distribution does not grant any rights to this
19
+ repository's source code.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ // src/entitlement.ts
2
+ function parseEntitlement(wire) {
3
+ return {
4
+ organizationId: wire.organization_id,
5
+ plan: wire.plan,
6
+ addons: wire.addons ?? [],
7
+ products: wire.products ?? [],
8
+ features: wire.features
9
+ };
10
+ }
11
+ function entitlementForProduct(entitlement, product) {
12
+ if (!entitlement) return null;
13
+ return {
14
+ enabled: entitlement.products.includes(product),
15
+ plan: entitlement.plan,
16
+ addons: entitlement.addons,
17
+ features: entitlement.features
18
+ };
19
+ }
20
+
21
+ export { entitlementForProduct, parseEntitlement };
22
+ //# sourceMappingURL=chunk-UX6UAFIF.js.map
23
+ //# sourceMappingURL=chunk-UX6UAFIF.js.map
@@ -0,0 +1,47 @@
1
+ import { PlanTier, ProductSlug, EntitlementFeatures } from '@viyv/shared';
2
+
3
+ /** The signed-in user as returned by better-auth's get-session. */
4
+ interface AccountUser {
5
+ id: string;
6
+ email: string;
7
+ name?: string | null;
8
+ image?: string | null;
9
+ }
10
+ /** Active organization, when the session carries one. */
11
+ interface AccountOrg {
12
+ id: string;
13
+ slug?: string | null;
14
+ name?: string | null;
15
+ }
16
+ /** Shape of GET /v1/license/entitlement (docs/09 A-4). */
17
+ interface Entitlement {
18
+ organizationId: string;
19
+ plan: PlanTier;
20
+ addons: string[];
21
+ /** Product slugs this org may use (free-start lists the agent family). */
22
+ products: ProductSlug[];
23
+ features: EntitlementFeatures;
24
+ }
25
+ /** Per-product entitlement view returned by useEntitlement(slug). */
26
+ interface ProductEntitlement {
27
+ /** Whether the product is enabled for this org. */
28
+ enabled: boolean;
29
+ plan: PlanTier;
30
+ addons: string[];
31
+ /** The full feature map (callers branch on the flags they care about). */
32
+ features: EntitlementFeatures;
33
+ }
34
+ /** Raw JSON from GET /v1/license/entitlement (snake_case wire form). */
35
+ interface EntitlementWire {
36
+ organization_id: string;
37
+ plan: PlanTier;
38
+ addons: string[];
39
+ products: ProductSlug[];
40
+ features: EntitlementFeatures;
41
+ }
42
+ /** Normalize the wire payload into the camelCase {@link Entitlement}. */
43
+ declare function parseEntitlement(wire: EntitlementWire): Entitlement;
44
+ /** Project a full entitlement down to a single product's view. */
45
+ declare function entitlementForProduct(entitlement: Entitlement | null, product: ProductSlug): ProductEntitlement | null;
46
+
47
+ export { type AccountOrg as A, type Entitlement as E, type ProductEntitlement as P, type AccountUser as a, entitlementForProduct as e, parseEntitlement as p };
@@ -0,0 +1,47 @@
1
+ import { PlanTier, ProductSlug, EntitlementFeatures } from '@viyv/shared';
2
+
3
+ /** The signed-in user as returned by better-auth's get-session. */
4
+ interface AccountUser {
5
+ id: string;
6
+ email: string;
7
+ name?: string | null;
8
+ image?: string | null;
9
+ }
10
+ /** Active organization, when the session carries one. */
11
+ interface AccountOrg {
12
+ id: string;
13
+ slug?: string | null;
14
+ name?: string | null;
15
+ }
16
+ /** Shape of GET /v1/license/entitlement (docs/09 A-4). */
17
+ interface Entitlement {
18
+ organizationId: string;
19
+ plan: PlanTier;
20
+ addons: string[];
21
+ /** Product slugs this org may use (free-start lists the agent family). */
22
+ products: ProductSlug[];
23
+ features: EntitlementFeatures;
24
+ }
25
+ /** Per-product entitlement view returned by useEntitlement(slug). */
26
+ interface ProductEntitlement {
27
+ /** Whether the product is enabled for this org. */
28
+ enabled: boolean;
29
+ plan: PlanTier;
30
+ addons: string[];
31
+ /** The full feature map (callers branch on the flags they care about). */
32
+ features: EntitlementFeatures;
33
+ }
34
+ /** Raw JSON from GET /v1/license/entitlement (snake_case wire form). */
35
+ interface EntitlementWire {
36
+ organization_id: string;
37
+ plan: PlanTier;
38
+ addons: string[];
39
+ products: ProductSlug[];
40
+ features: EntitlementFeatures;
41
+ }
42
+ /** Normalize the wire payload into the camelCase {@link Entitlement}. */
43
+ declare function parseEntitlement(wire: EntitlementWire): Entitlement;
44
+ /** Project a full entitlement down to a single product's view. */
45
+ declare function entitlementForProduct(entitlement: Entitlement | null, product: ProductSlug): ProductEntitlement | null;
46
+
47
+ export { type AccountOrg as A, type Entitlement as E, type ProductEntitlement as P, type AccountUser as a, entitlementForProduct as e, parseEntitlement as p };
package/dist/index.cjs ADDED
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ var client = require('better-auth/client');
4
+
5
+ // src/index.ts
6
+
7
+ // src/device.ts
8
+ var DEFAULT_DEVICE_CLIENT_ID = "viyv-browser-macapp";
9
+ var DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
10
+ function createDeviceFlowClient(config) {
11
+ const f = config.fetchImpl ?? fetch;
12
+ const clientId = config.clientId ?? DEFAULT_DEVICE_CLIENT_ID;
13
+ const base = config.apiBase.replace(/\/$/, "");
14
+ async function postJson(path, body, extraHeaders) {
15
+ const headers = { "content-type": "application/json" };
16
+ if (extraHeaders) {
17
+ for (const [k, v] of Object.entries(extraHeaders)) headers[k] = v;
18
+ }
19
+ const res = await f(`${base}${path}`, {
20
+ method: "POST",
21
+ headers,
22
+ body: JSON.stringify(body)
23
+ });
24
+ return await res.json();
25
+ }
26
+ async function postForm(path, params) {
27
+ const res = await f(`${base}${path}`, {
28
+ method: "POST",
29
+ headers: { "content-type": "application/x-www-form-urlencoded" },
30
+ body: new URLSearchParams(params).toString()
31
+ });
32
+ return await res.json();
33
+ }
34
+ return {
35
+ start: () => postJson("/v1/auth/device/start", { client_id: clientId }),
36
+ poll: (deviceCode) => postForm("/v1/auth/device/poll", {
37
+ grant_type: DEVICE_CODE_GRANT_TYPE,
38
+ device_code: deviceCode,
39
+ client_id: clientId
40
+ }),
41
+ refresh: (refreshToken) => postJson("/v1/auth/device/refresh", {
42
+ refresh_token: refreshToken
43
+ }),
44
+ revoke: (accessToken) => postJson(
45
+ "/v1/auth/device/revoke",
46
+ {},
47
+ { authorization: `Bearer ${accessToken}` }
48
+ ),
49
+ fetchLicense: async (accessToken) => {
50
+ const res = await f(`${base}/v1/license/current`, {
51
+ headers: { authorization: `Bearer ${accessToken}` }
52
+ });
53
+ return await res.json();
54
+ },
55
+ userinfo: async (accessToken) => {
56
+ const res = await f(`${base}/v1/auth/device/userinfo`, {
57
+ headers: { authorization: `Bearer ${accessToken}` }
58
+ });
59
+ if (res.status === 401) return { error: "invalid_token" };
60
+ return await res.json();
61
+ }
62
+ };
63
+ }
64
+
65
+ // src/entitlement.ts
66
+ function parseEntitlement(wire) {
67
+ return {
68
+ organizationId: wire.organization_id,
69
+ plan: wire.plan,
70
+ addons: wire.addons ?? [],
71
+ products: wire.products ?? [],
72
+ features: wire.features
73
+ };
74
+ }
75
+ function entitlementForProduct(entitlement, product) {
76
+ if (!entitlement) return null;
77
+ return {
78
+ enabled: entitlement.products.includes(product),
79
+ plan: entitlement.plan,
80
+ addons: entitlement.addons,
81
+ features: entitlement.features
82
+ };
83
+ }
84
+
85
+ // src/index.ts
86
+ var ACCOUNT_CLIENT_PACKAGE = "@viyv/account-client";
87
+ function createAccountClient(config) {
88
+ const client$1 = client.createAuthClient({
89
+ baseURL: config.apiBase,
90
+ basePath: "/v1/auth",
91
+ fetchOptions: { credentials: "include" }
92
+ });
93
+ return {
94
+ raw: client$1,
95
+ signUp: (params) => client$1.signUp.email({
96
+ email: params.email,
97
+ password: params.password,
98
+ name: params.name ?? params.email.split("@")[0] ?? params.email
99
+ }),
100
+ signIn: (params) => client$1.signIn.email({
101
+ email: params.email,
102
+ password: params.password
103
+ }),
104
+ signOut: () => client$1.signOut(),
105
+ getSession: () => client$1.getSession()
106
+ };
107
+ }
108
+
109
+ exports.ACCOUNT_CLIENT_PACKAGE = ACCOUNT_CLIENT_PACKAGE;
110
+ exports.DEFAULT_DEVICE_CLIENT_ID = DEFAULT_DEVICE_CLIENT_ID;
111
+ exports.DEVICE_CODE_GRANT_TYPE = DEVICE_CODE_GRANT_TYPE;
112
+ exports.createAccountClient = createAccountClient;
113
+ exports.createDeviceFlowClient = createDeviceFlowClient;
114
+ exports.entitlementForProduct = entitlementForProduct;
115
+ exports.parseEntitlement = parseEntitlement;
116
+ //# sourceMappingURL=index.cjs.map
117
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,115 @@
1
+ import { createAuthClient } from 'better-auth/client';
2
+ import { DeviceUserinfoResponse } from '@viyv/shared';
3
+ export { DeviceUserinfoResponse, EntitlementFeatures, PlanTier, ProductSlug } from '@viyv/shared';
4
+ export { A as AccountOrg, a as AccountUser, E as Entitlement, P as ProductEntitlement, e as entitlementForProduct, p as parseEntitlement } from './entitlement-B3pXM2vO.cjs';
5
+
6
+ declare const DEFAULT_DEVICE_CLIENT_ID: "viyv-browser-macapp";
7
+ /** RFC 8628 §3.4 device_code grant type (token endpoint `grant_type`). */
8
+ declare const DEVICE_CODE_GRANT_TYPE: "urn:ietf:params:oauth:grant-type:device_code";
9
+ interface DeviceStartResponse {
10
+ device_code: string;
11
+ user_code: string;
12
+ verification_uri: string;
13
+ verification_uri_complete: string;
14
+ expires_in: number;
15
+ interval: number;
16
+ }
17
+ interface DeviceTokenResponse {
18
+ access_token: string;
19
+ refresh_token: string;
20
+ token_type: "Bearer";
21
+ expires_in: number;
22
+ scope: string;
23
+ }
24
+ /** Poll error codes per RFC 8628 / docs/03. */
25
+ type DevicePollError = "authorization_pending" | "slow_down" | "expired_token" | "access_denied";
26
+ interface LicenseCurrentResponse {
27
+ license_jwt: string;
28
+ expires_in: number;
29
+ }
30
+ interface DeviceFlowClientConfig {
31
+ /** e.g. "https://api.viyv.io". */
32
+ apiBase: string;
33
+ /** Device client id (default viyv-browser-macapp). */
34
+ clientId?: string;
35
+ /** Injectable fetch (Node/Electron). Defaults to global fetch. */
36
+ fetchImpl?: typeof fetch;
37
+ }
38
+ interface DeviceFlowClient {
39
+ start(): Promise<DeviceStartResponse>;
40
+ /**
41
+ * Poll once. Resolves to a token pair when approved, or
42
+ * `{ error }` (authorization_pending / expired_token / ...) while waiting.
43
+ */
44
+ poll(deviceCode: string): Promise<DeviceTokenResponse | {
45
+ error: DevicePollError;
46
+ }>;
47
+ refresh(refreshToken: string): Promise<DeviceTokenResponse | {
48
+ error: string;
49
+ }>;
50
+ revoke(accessToken: string): Promise<{
51
+ revoked: boolean;
52
+ }>;
53
+ /** Fetch the current license JWT using a Bearer access token. */
54
+ fetchLicense(accessToken: string): Promise<LicenseCurrentResponse>;
55
+ /**
56
+ * Read the signed-in identity for a device access token (OIDC-style userinfo,
57
+ * GET /v1/auth/device/userinfo). Returns `{ error: "invalid_token" }` on 401.
58
+ */
59
+ userinfo(accessToken: string): Promise<DeviceUserinfoResponse | {
60
+ error: string;
61
+ }>;
62
+ }
63
+ /**
64
+ * Create a Device Flow client bound to an api.viyv.io base. Non-browser clients
65
+ * (the Mac app) call these directly with Bearer auth — CORS does not apply.
66
+ */
67
+ declare function createDeviceFlowClient(config: DeviceFlowClientConfig): DeviceFlowClient;
68
+
69
+ declare const ACCOUNT_CLIENT_PACKAGE: "@viyv/account-client";
70
+ interface AccountClientConfig {
71
+ /** e.g. "https://api.viyv.io" */
72
+ apiBase: string;
73
+ /**
74
+ * e.g. ".viyv.io". Cross-subdomain cookies are set server-side; this is kept
75
+ * for parity with docs/04 <AccountProvider cookieDomain> and future hooks.
76
+ */
77
+ cookieDomain?: string;
78
+ }
79
+ /** Result envelope returned by better-auth client calls (data or error). */
80
+ interface AuthResult<T = unknown> {
81
+ data: T | null;
82
+ error: {
83
+ message?: string;
84
+ status?: number;
85
+ statusText?: string;
86
+ } | null;
87
+ }
88
+ /**
89
+ * Public surface of the account client. Methods are typed explicitly (rather
90
+ * than inferred) so the published `.d.ts` does not reference better-auth's
91
+ * internal module paths (TS2742 portability).
92
+ */
93
+ interface AccountClient {
94
+ /** Raw better-auth client (escape hatch for org/session methods). */
95
+ raw: ReturnType<typeof createAuthClient>;
96
+ signUp(params: {
97
+ email: string;
98
+ password: string;
99
+ name?: string;
100
+ }): Promise<AuthResult>;
101
+ signIn(params: {
102
+ email: string;
103
+ password: string;
104
+ }): Promise<AuthResult>;
105
+ signOut(): Promise<AuthResult>;
106
+ getSession(): Promise<AuthResult>;
107
+ }
108
+ /**
109
+ * Create an account client bound to a viyv-account API base. The underlying
110
+ * better-auth client sends credentials so the `.viyv.io` session cookie flows
111
+ * cross-subdomain.
112
+ */
113
+ declare function createAccountClient(config: AccountClientConfig): AccountClient;
114
+
115
+ export { ACCOUNT_CLIENT_PACKAGE, type AccountClient, type AccountClientConfig, type AuthResult, DEFAULT_DEVICE_CLIENT_ID, DEVICE_CODE_GRANT_TYPE, type DeviceFlowClient, type DeviceFlowClientConfig, type DevicePollError, type DeviceStartResponse, type DeviceTokenResponse, type LicenseCurrentResponse, createAccountClient, createDeviceFlowClient };
@@ -0,0 +1,115 @@
1
+ import { createAuthClient } from 'better-auth/client';
2
+ import { DeviceUserinfoResponse } from '@viyv/shared';
3
+ export { DeviceUserinfoResponse, EntitlementFeatures, PlanTier, ProductSlug } from '@viyv/shared';
4
+ export { A as AccountOrg, a as AccountUser, E as Entitlement, P as ProductEntitlement, e as entitlementForProduct, p as parseEntitlement } from './entitlement-B3pXM2vO.js';
5
+
6
+ declare const DEFAULT_DEVICE_CLIENT_ID: "viyv-browser-macapp";
7
+ /** RFC 8628 §3.4 device_code grant type (token endpoint `grant_type`). */
8
+ declare const DEVICE_CODE_GRANT_TYPE: "urn:ietf:params:oauth:grant-type:device_code";
9
+ interface DeviceStartResponse {
10
+ device_code: string;
11
+ user_code: string;
12
+ verification_uri: string;
13
+ verification_uri_complete: string;
14
+ expires_in: number;
15
+ interval: number;
16
+ }
17
+ interface DeviceTokenResponse {
18
+ access_token: string;
19
+ refresh_token: string;
20
+ token_type: "Bearer";
21
+ expires_in: number;
22
+ scope: string;
23
+ }
24
+ /** Poll error codes per RFC 8628 / docs/03. */
25
+ type DevicePollError = "authorization_pending" | "slow_down" | "expired_token" | "access_denied";
26
+ interface LicenseCurrentResponse {
27
+ license_jwt: string;
28
+ expires_in: number;
29
+ }
30
+ interface DeviceFlowClientConfig {
31
+ /** e.g. "https://api.viyv.io". */
32
+ apiBase: string;
33
+ /** Device client id (default viyv-browser-macapp). */
34
+ clientId?: string;
35
+ /** Injectable fetch (Node/Electron). Defaults to global fetch. */
36
+ fetchImpl?: typeof fetch;
37
+ }
38
+ interface DeviceFlowClient {
39
+ start(): Promise<DeviceStartResponse>;
40
+ /**
41
+ * Poll once. Resolves to a token pair when approved, or
42
+ * `{ error }` (authorization_pending / expired_token / ...) while waiting.
43
+ */
44
+ poll(deviceCode: string): Promise<DeviceTokenResponse | {
45
+ error: DevicePollError;
46
+ }>;
47
+ refresh(refreshToken: string): Promise<DeviceTokenResponse | {
48
+ error: string;
49
+ }>;
50
+ revoke(accessToken: string): Promise<{
51
+ revoked: boolean;
52
+ }>;
53
+ /** Fetch the current license JWT using a Bearer access token. */
54
+ fetchLicense(accessToken: string): Promise<LicenseCurrentResponse>;
55
+ /**
56
+ * Read the signed-in identity for a device access token (OIDC-style userinfo,
57
+ * GET /v1/auth/device/userinfo). Returns `{ error: "invalid_token" }` on 401.
58
+ */
59
+ userinfo(accessToken: string): Promise<DeviceUserinfoResponse | {
60
+ error: string;
61
+ }>;
62
+ }
63
+ /**
64
+ * Create a Device Flow client bound to an api.viyv.io base. Non-browser clients
65
+ * (the Mac app) call these directly with Bearer auth — CORS does not apply.
66
+ */
67
+ declare function createDeviceFlowClient(config: DeviceFlowClientConfig): DeviceFlowClient;
68
+
69
+ declare const ACCOUNT_CLIENT_PACKAGE: "@viyv/account-client";
70
+ interface AccountClientConfig {
71
+ /** e.g. "https://api.viyv.io" */
72
+ apiBase: string;
73
+ /**
74
+ * e.g. ".viyv.io". Cross-subdomain cookies are set server-side; this is kept
75
+ * for parity with docs/04 <AccountProvider cookieDomain> and future hooks.
76
+ */
77
+ cookieDomain?: string;
78
+ }
79
+ /** Result envelope returned by better-auth client calls (data or error). */
80
+ interface AuthResult<T = unknown> {
81
+ data: T | null;
82
+ error: {
83
+ message?: string;
84
+ status?: number;
85
+ statusText?: string;
86
+ } | null;
87
+ }
88
+ /**
89
+ * Public surface of the account client. Methods are typed explicitly (rather
90
+ * than inferred) so the published `.d.ts` does not reference better-auth's
91
+ * internal module paths (TS2742 portability).
92
+ */
93
+ interface AccountClient {
94
+ /** Raw better-auth client (escape hatch for org/session methods). */
95
+ raw: ReturnType<typeof createAuthClient>;
96
+ signUp(params: {
97
+ email: string;
98
+ password: string;
99
+ name?: string;
100
+ }): Promise<AuthResult>;
101
+ signIn(params: {
102
+ email: string;
103
+ password: string;
104
+ }): Promise<AuthResult>;
105
+ signOut(): Promise<AuthResult>;
106
+ getSession(): Promise<AuthResult>;
107
+ }
108
+ /**
109
+ * Create an account client bound to a viyv-account API base. The underlying
110
+ * better-auth client sends credentials so the `.viyv.io` session cookie flows
111
+ * cross-subdomain.
112
+ */
113
+ declare function createAccountClient(config: AccountClientConfig): AccountClient;
114
+
115
+ export { ACCOUNT_CLIENT_PACKAGE, type AccountClient, type AccountClientConfig, type AuthResult, DEFAULT_DEVICE_CLIENT_ID, DEVICE_CODE_GRANT_TYPE, type DeviceFlowClient, type DeviceFlowClientConfig, type DevicePollError, type DeviceStartResponse, type DeviceTokenResponse, type LicenseCurrentResponse, createAccountClient, createDeviceFlowClient };
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ export { entitlementForProduct, parseEntitlement } from './chunk-UX6UAFIF.js';
2
+ import { createAuthClient } from 'better-auth/client';
3
+
4
+ // src/device.ts
5
+ var DEFAULT_DEVICE_CLIENT_ID = "viyv-browser-macapp";
6
+ var DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
7
+ function createDeviceFlowClient(config) {
8
+ const f = config.fetchImpl ?? fetch;
9
+ const clientId = config.clientId ?? DEFAULT_DEVICE_CLIENT_ID;
10
+ const base = config.apiBase.replace(/\/$/, "");
11
+ async function postJson(path, body, extraHeaders) {
12
+ const headers = { "content-type": "application/json" };
13
+ if (extraHeaders) {
14
+ for (const [k, v] of Object.entries(extraHeaders)) headers[k] = v;
15
+ }
16
+ const res = await f(`${base}${path}`, {
17
+ method: "POST",
18
+ headers,
19
+ body: JSON.stringify(body)
20
+ });
21
+ return await res.json();
22
+ }
23
+ async function postForm(path, params) {
24
+ const res = await f(`${base}${path}`, {
25
+ method: "POST",
26
+ headers: { "content-type": "application/x-www-form-urlencoded" },
27
+ body: new URLSearchParams(params).toString()
28
+ });
29
+ return await res.json();
30
+ }
31
+ return {
32
+ start: () => postJson("/v1/auth/device/start", { client_id: clientId }),
33
+ poll: (deviceCode) => postForm("/v1/auth/device/poll", {
34
+ grant_type: DEVICE_CODE_GRANT_TYPE,
35
+ device_code: deviceCode,
36
+ client_id: clientId
37
+ }),
38
+ refresh: (refreshToken) => postJson("/v1/auth/device/refresh", {
39
+ refresh_token: refreshToken
40
+ }),
41
+ revoke: (accessToken) => postJson(
42
+ "/v1/auth/device/revoke",
43
+ {},
44
+ { authorization: `Bearer ${accessToken}` }
45
+ ),
46
+ fetchLicense: async (accessToken) => {
47
+ const res = await f(`${base}/v1/license/current`, {
48
+ headers: { authorization: `Bearer ${accessToken}` }
49
+ });
50
+ return await res.json();
51
+ },
52
+ userinfo: async (accessToken) => {
53
+ const res = await f(`${base}/v1/auth/device/userinfo`, {
54
+ headers: { authorization: `Bearer ${accessToken}` }
55
+ });
56
+ if (res.status === 401) return { error: "invalid_token" };
57
+ return await res.json();
58
+ }
59
+ };
60
+ }
61
+
62
+ // src/index.ts
63
+ var ACCOUNT_CLIENT_PACKAGE = "@viyv/account-client";
64
+ function createAccountClient(config) {
65
+ const client = createAuthClient({
66
+ baseURL: config.apiBase,
67
+ basePath: "/v1/auth",
68
+ fetchOptions: { credentials: "include" }
69
+ });
70
+ return {
71
+ raw: client,
72
+ signUp: (params) => client.signUp.email({
73
+ email: params.email,
74
+ password: params.password,
75
+ name: params.name ?? params.email.split("@")[0] ?? params.email
76
+ }),
77
+ signIn: (params) => client.signIn.email({
78
+ email: params.email,
79
+ password: params.password
80
+ }),
81
+ signOut: () => client.signOut(),
82
+ getSession: () => client.getSession()
83
+ };
84
+ }
85
+
86
+ export { ACCOUNT_CLIENT_PACKAGE, DEFAULT_DEVICE_CLIENT_ID, DEVICE_CODE_GRANT_TYPE, createAccountClient, createDeviceFlowClient };
87
+ //# sourceMappingURL=index.js.map
88
+ //# sourceMappingURL=index.js.map