orgnote-api 0.40.0 → 0.40.11
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/constants/i18n-keys.d.ts +0 -2
- package/constants/i18n-keys.js +0 -1
- package/constants/route-paths.d.ts +1 -1
- package/constants/route-paths.js +1 -1
- package/encryption/__tests__/note-encryption.spec.js +23 -12
- package/models/auth-state.d.ts +9 -0
- package/models/auth-state.js +12 -0
- package/models/encryption.d.ts +5 -5
- package/models/index.d.ts +1 -0
- package/models/index.js +1 -0
- package/models/menu-action.d.ts +2 -2
- package/models/orgnote-config.d.ts +4 -4
- package/models/user.d.ts +2 -4
- package/package.json +4 -4
- package/remote-api/api.d.ts +4 -4
- package/remote-api/api.js +9 -9
- package/remote-api/index.d.ts +2 -2
- package/remote-api/index.js +0 -1
- package/utils/auth-state.d.ts +5 -0
- package/utils/auth-state.js +18 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/toml.d.ts +2 -2
- package/package-lock.json +0 -5553
package/constants/i18n-keys.d.ts
CHANGED
|
@@ -143,7 +143,6 @@ export declare enum i18n {
|
|
|
143
143
|
AUTH_LOGIN = "login",
|
|
144
144
|
AUTH_LOGIN_DESCRIPTION = "sign in to your account",
|
|
145
145
|
AUTH_INVALID_CALLBACK_PARAMS = "invalid authentication callback parameters",
|
|
146
|
-
AUTH_REMOVE_ACCOUNT = "remove account",
|
|
147
146
|
AUTH_REMOVE_ACCOUNT_DESCRIPTION = "permanently delete your account",
|
|
148
147
|
AUTH_GROUP = "auth"
|
|
149
148
|
}
|
|
@@ -364,7 +363,6 @@ export declare const I18N: {
|
|
|
364
363
|
AUTH_LOGIN: i18n.AUTH_LOGIN;
|
|
365
364
|
AUTH_LOGIN_DESCRIPTION: i18n.AUTH_LOGIN_DESCRIPTION;
|
|
366
365
|
AUTH_INVALID_CALLBACK_PARAMS: i18n.AUTH_INVALID_CALLBACK_PARAMS;
|
|
367
|
-
AUTH_REMOVE_ACCOUNT: i18n.REMOVE_ACCOUNT;
|
|
368
366
|
AUTH_REMOVE_ACCOUNT_DESCRIPTION: i18n.AUTH_REMOVE_ACCOUNT_DESCRIPTION;
|
|
369
367
|
AUTH_GROUP: i18n.AUTH_GROUP;
|
|
370
368
|
};
|
package/constants/i18n-keys.js
CHANGED
|
@@ -148,7 +148,6 @@ export var i18n;
|
|
|
148
148
|
i18n["AUTH_LOGIN"] = "login";
|
|
149
149
|
i18n["AUTH_LOGIN_DESCRIPTION"] = "sign in to your account";
|
|
150
150
|
i18n["AUTH_INVALID_CALLBACK_PARAMS"] = "invalid authentication callback parameters";
|
|
151
|
-
i18n["AUTH_REMOVE_ACCOUNT"] = "remove account";
|
|
152
151
|
i18n["AUTH_REMOVE_ACCOUNT_DESCRIPTION"] = "permanently delete your account";
|
|
153
152
|
i18n["AUTH_GROUP"] = "auth";
|
|
154
153
|
})(i18n || (i18n = {}));
|
package/constants/route-paths.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
1
|
+
import { beforeEach, expect, test } from 'vitest';
|
|
2
2
|
import { decryptNote, encryptNote } from "../note-encryption.js";
|
|
3
3
|
import { armoredPublicKey, armoredPrivateKey, privateKeyPassphrase, } from "./encryption-keys.js";
|
|
4
4
|
import { EncryptionType } from "../../models/encryption.js";
|
|
5
5
|
import { faker } from '@faker-js/faker';
|
|
6
|
-
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
faker.seed(1);
|
|
8
|
+
faker.setDefaultRefDate(new Date('2024-01-01T00:00:00.000Z'));
|
|
9
|
+
});
|
|
7
10
|
function generateNoteInfo(overrides = {}) {
|
|
8
11
|
return {
|
|
9
12
|
id: faker.string.uuid(),
|
|
@@ -34,30 +37,38 @@ function generateNoteInfo(overrides = {}) {
|
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
test('Should encrypt note via keys', async () => {
|
|
37
|
-
const noteText =
|
|
40
|
+
const noteText = '#+title: Test note\n\nBody text';
|
|
38
41
|
const note = generateNoteInfo();
|
|
42
|
+
note.meta.published = false;
|
|
39
43
|
const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
|
|
40
44
|
content: noteText,
|
|
41
45
|
type: EncryptionType.GpgKeys,
|
|
42
|
-
publicKey: armoredPublicKey,
|
|
43
|
-
privateKey: armoredPrivateKey,
|
|
44
|
-
privateKeyPassphrase,
|
|
46
|
+
publicKey: armoredPublicKey,
|
|
47
|
+
privateKey: armoredPrivateKey,
|
|
48
|
+
privateKeyPassphrase,
|
|
45
49
|
format: 'armored',
|
|
46
50
|
});
|
|
47
51
|
expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(true);
|
|
48
52
|
expect(encryptedNote).toMatchSnapshot();
|
|
49
53
|
});
|
|
50
54
|
test('Should decrypt note via keys', async () => {
|
|
51
|
-
const
|
|
52
|
-
${faker.lorem.paragraphs()}
|
|
53
|
-
-----END PGP MESSAGE-----`;
|
|
55
|
+
const noteText = '#+title: Test note\n\nBody text';
|
|
54
56
|
const note = generateNoteInfo();
|
|
57
|
+
note.meta.published = false;
|
|
58
|
+
const [, encryptedNoteText] = await encryptNote(note, {
|
|
59
|
+
content: noteText,
|
|
60
|
+
type: EncryptionType.GpgKeys,
|
|
61
|
+
publicKey: armoredPublicKey,
|
|
62
|
+
privateKey: armoredPrivateKey,
|
|
63
|
+
privateKeyPassphrase,
|
|
64
|
+
format: 'armored',
|
|
65
|
+
});
|
|
55
66
|
const decryptedNote = await decryptNote(note, {
|
|
56
67
|
content: encryptedNoteText,
|
|
57
68
|
type: EncryptionType.GpgKeys,
|
|
58
|
-
publicKey: armoredPublicKey,
|
|
59
|
-
privateKey: armoredPrivateKey,
|
|
60
|
-
privateKeyPassphrase,
|
|
69
|
+
publicKey: armoredPublicKey,
|
|
70
|
+
privateKey: armoredPrivateKey,
|
|
71
|
+
privateKeyPassphrase,
|
|
61
72
|
});
|
|
62
73
|
expect(decryptedNote).toMatchSnapshot();
|
|
63
74
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type InferOutput } from 'valibot';
|
|
2
|
+
export declare const AUTH_ENVIRONMENTS: readonly ["web", "mobile", "electron", "desktop"];
|
|
3
|
+
export type AuthEnvironment = (typeof AUTH_ENVIRONMENTS)[number];
|
|
4
|
+
export declare const AUTH_ENVIRONMENT_SCHEMA: import("valibot").UnionSchema<[import("valibot").LiteralSchema<"web", undefined>, import("valibot").LiteralSchema<"mobile", undefined>, import("valibot").LiteralSchema<"electron", undefined>, import("valibot").LiteralSchema<"desktop", undefined>], undefined>;
|
|
5
|
+
export declare const AUTH_STATE_SCHEMA: import("valibot").ObjectSchema<{
|
|
6
|
+
readonly environment: import("valibot").UnionSchema<[import("valibot").LiteralSchema<"web", undefined>, import("valibot").LiteralSchema<"mobile", undefined>, import("valibot").LiteralSchema<"electron", undefined>, import("valibot").LiteralSchema<"desktop", undefined>], undefined>;
|
|
7
|
+
readonly redirectUrl: import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>;
|
|
8
|
+
}, undefined>;
|
|
9
|
+
export type AuthState = InferOutput<typeof AUTH_STATE_SCHEMA>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { literal, object, optional, string, union, } from 'valibot';
|
|
2
|
+
export const AUTH_ENVIRONMENTS = ['web', 'mobile', 'electron', 'desktop'];
|
|
3
|
+
export const AUTH_ENVIRONMENT_SCHEMA = union([
|
|
4
|
+
literal('web'),
|
|
5
|
+
literal('mobile'),
|
|
6
|
+
literal('electron'),
|
|
7
|
+
literal('desktop'),
|
|
8
|
+
]);
|
|
9
|
+
export const AUTH_STATE_SCHEMA = object({
|
|
10
|
+
environment: AUTH_ENVIRONMENT_SCHEMA,
|
|
11
|
+
redirectUrl: optional(string()),
|
|
12
|
+
});
|
package/models/encryption.d.ts
CHANGED
|
@@ -14,11 +14,11 @@ export interface BaseOrgNoteDecryption {
|
|
|
14
14
|
}
|
|
15
15
|
declare const OrgNoteGpgEncryptionSchema: import("valibot").ObjectSchema<{
|
|
16
16
|
readonly type: import("valibot").LiteralSchema<"gpgKeys", undefined>;
|
|
17
|
-
readonly privateKey: import("valibot").SchemaWithPipe<
|
|
17
|
+
readonly privateKey: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").MetadataAction<string, {
|
|
18
18
|
readonly textarea: true;
|
|
19
19
|
readonly upload: true;
|
|
20
20
|
}>]>;
|
|
21
|
-
readonly publicKey: import("valibot").SchemaWithPipe<
|
|
21
|
+
readonly publicKey: import("valibot").SchemaWithPipe<[import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>, import("valibot").MetadataAction<string, {
|
|
22
22
|
readonly textarea: true;
|
|
23
23
|
readonly upload: true;
|
|
24
24
|
}>]>;
|
|
@@ -30,13 +30,13 @@ declare const OrgNotePasswordEncryptionSchema: import("valibot").ObjectSchema<{
|
|
|
30
30
|
}, undefined>;
|
|
31
31
|
export declare const OrgNoteEncryptionSchema: import("valibot").IntersectSchema<[import("valibot").ObjectSchema<{
|
|
32
32
|
readonly encryptFilesByDefault: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
|
|
33
|
-
}, undefined>, import("valibot").SchemaWithPipe<
|
|
33
|
+
}, undefined>, import("valibot").SchemaWithPipe<[import("valibot").UnionSchema<[import("valibot").ObjectSchema<{
|
|
34
34
|
readonly type: import("valibot").LiteralSchema<"gpgKeys", undefined>;
|
|
35
|
-
readonly privateKey: import("valibot").SchemaWithPipe<
|
|
35
|
+
readonly privateKey: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").MetadataAction<string, {
|
|
36
36
|
readonly textarea: true;
|
|
37
37
|
readonly upload: true;
|
|
38
38
|
}>]>;
|
|
39
|
-
readonly publicKey: import("valibot").SchemaWithPipe<
|
|
39
|
+
readonly publicKey: import("valibot").SchemaWithPipe<[import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>, import("valibot").MetadataAction<string, {
|
|
40
40
|
readonly textarea: true;
|
|
41
41
|
readonly upload: true;
|
|
42
42
|
}>]>;
|
package/models/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './file-info.js';
|
|
|
15
15
|
export * from './file-path.js';
|
|
16
16
|
export * from './user.js';
|
|
17
17
|
export * from './oauth-provider.js';
|
|
18
|
+
export * from './auth-state.js';
|
|
18
19
|
export * from './orgnote-config.js';
|
|
19
20
|
export * from './platform-specific.js';
|
|
20
21
|
export * from './css-utils.js';
|
package/models/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./file-info.js";
|
|
|
15
15
|
export * from "./file-path.js";
|
|
16
16
|
export * from "./user.js";
|
|
17
17
|
export * from "./oauth-provider.js";
|
|
18
|
+
export * from "./auth-state.js";
|
|
18
19
|
export * from "./orgnote-config.js";
|
|
19
20
|
export * from "./platform-specific.js";
|
|
20
21
|
export * from "./css-utils.js";
|
package/models/menu-action.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CommandName } from './command.js';
|
|
2
2
|
type DefinedMenuGroup = 'file' | 'dir' | 'tab';
|
|
3
3
|
export type MenuGroup = DefinedMenuGroup | (string & {});
|
|
4
|
-
export interface MenuActionBase
|
|
4
|
+
export interface MenuActionBase {
|
|
5
5
|
icon?: string;
|
|
6
6
|
title?: string;
|
|
7
7
|
}
|
|
8
|
-
export interface ManualMenuAction<T = unknown> extends MenuActionBase
|
|
8
|
+
export interface ManualMenuAction<T = unknown> extends MenuActionBase {
|
|
9
9
|
handler: (data: T) => void;
|
|
10
10
|
}
|
|
11
11
|
export interface CommandMenuAction extends MenuActionBase {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InferOutput } from 'valibot';
|
|
2
|
-
export declare const ORG_NOTE_CONFIG_SCHEMA: import("valibot").SchemaWithPipe<
|
|
2
|
+
export declare const ORG_NOTE_CONFIG_SCHEMA: import("valibot").SchemaWithPipe<[import("valibot").ObjectWithRestSchema<{
|
|
3
3
|
readonly editor: import("valibot").ObjectSchema<{
|
|
4
4
|
readonly showSpecialSymbols: import("valibot").BooleanSchema<undefined>;
|
|
5
5
|
readonly showPropertyDrawer: import("valibot").BooleanSchema<undefined>;
|
|
@@ -39,13 +39,13 @@ export declare const ORG_NOTE_CONFIG_SCHEMA: import("valibot").SchemaWithPipe<re
|
|
|
39
39
|
}, undefined>;
|
|
40
40
|
readonly encryption: import("valibot").IntersectSchema<[import("valibot").ObjectSchema<{
|
|
41
41
|
readonly encryptFilesByDefault: import("valibot").OptionalSchema<import("valibot").BooleanSchema<undefined>, undefined>;
|
|
42
|
-
}, undefined>, import("valibot").SchemaWithPipe<
|
|
42
|
+
}, undefined>, import("valibot").SchemaWithPipe<[import("valibot").UnionSchema<[import("valibot").ObjectSchema<{
|
|
43
43
|
readonly type: import("valibot").LiteralSchema<"gpgKeys", undefined>;
|
|
44
|
-
readonly privateKey: import("valibot").SchemaWithPipe<
|
|
44
|
+
readonly privateKey: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").MetadataAction<string, {
|
|
45
45
|
readonly textarea: true;
|
|
46
46
|
readonly upload: true;
|
|
47
47
|
}>]>;
|
|
48
|
-
readonly publicKey: import("valibot").SchemaWithPipe<
|
|
48
|
+
readonly publicKey: import("valibot").SchemaWithPipe<[import("valibot").OptionalSchema<import("valibot").StringSchema<undefined>, undefined>, import("valibot").MetadataAction<string, {
|
|
49
49
|
readonly textarea: true;
|
|
50
50
|
readonly upload: true;
|
|
51
51
|
}>]>;
|
package/models/user.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { ModelsUserPersonalInfo } from "../remote-api/index.js";
|
|
2
2
|
import { PublicUser } from './note.js';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export interface PersonalInfo extends ModelsUserPersonalInfo {
|
|
6
|
-
}
|
|
3
|
+
export type User = PublicUser;
|
|
4
|
+
export type PersonalInfo = ModelsUserPersonalInfo;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orgnote-api",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.11",
|
|
4
4
|
"description": "Official API for creating extensions for OrgNote app",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"codegen:css-types": "node collect-css-variables.cjs --types",
|
|
17
17
|
"fix-esm-imports": "fix-esm-import-path ./dist",
|
|
18
18
|
"prepub": "bun run build && bun run fix-esm-imports && cp -rf package.json package-lock.json README.md dist/",
|
|
19
|
-
"pub": "bun run prepub && cd dist &&
|
|
19
|
+
"pub": "bun run prepub && cd dist && npm publish",
|
|
20
20
|
"pub:yalc": "bun run prepub && cd dist && yalc publish --push"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "
|
|
24
|
+
"url": "https://github.com/Artawower/orgnote-api"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": "./index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"axios": "1.8.4",
|
|
47
47
|
"neverthrow": "^8.2.0",
|
|
48
|
-
"openpgp": "6.
|
|
48
|
+
"openpgp": "6.3.0",
|
|
49
49
|
"org-mode-ast": "0.11.8",
|
|
50
50
|
"partysocket": "1.1.6",
|
|
51
51
|
"smol-toml": "1.5.2"
|
package/remote-api/api.d.ts
CHANGED
|
@@ -886,7 +886,7 @@ export declare const EventsApiAxiosParamCreator: (configuration?: Configuration)
|
|
|
886
886
|
* @param {*} [options] Override http request option.
|
|
887
887
|
* @throws {RequiredError}
|
|
888
888
|
*/
|
|
889
|
-
|
|
889
|
+
wsEventsGet: (token?: string, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
|
|
890
890
|
};
|
|
891
891
|
/**
|
|
892
892
|
* EventsApi - functional programming interface
|
|
@@ -900,7 +900,7 @@ export declare const EventsApiFp: (configuration?: Configuration) => {
|
|
|
900
900
|
* @param {*} [options] Override http request option.
|
|
901
901
|
* @throws {RequiredError}
|
|
902
902
|
*/
|
|
903
|
-
|
|
903
|
+
wsEventsGet(token?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
|
|
904
904
|
};
|
|
905
905
|
/**
|
|
906
906
|
* EventsApi - factory interface
|
|
@@ -914,7 +914,7 @@ export declare const EventsApiFactory: (configuration?: Configuration, basePath?
|
|
|
914
914
|
* @param {*} [options] Override http request option.
|
|
915
915
|
* @throws {RequiredError}
|
|
916
916
|
*/
|
|
917
|
-
|
|
917
|
+
wsEventsGet(token?: string, options?: any): AxiosPromise<void>;
|
|
918
918
|
};
|
|
919
919
|
/**
|
|
920
920
|
* EventsApi - object-oriented interface
|
|
@@ -931,7 +931,7 @@ export declare class EventsApi extends BaseAPI {
|
|
|
931
931
|
* @throws {RequiredError}
|
|
932
932
|
* @memberof EventsApi
|
|
933
933
|
*/
|
|
934
|
-
|
|
934
|
+
wsEventsGet(token?: string, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
|
|
935
935
|
}
|
|
936
936
|
/**
|
|
937
937
|
* SyncApi - axios parameter creator
|
package/remote-api/api.js
CHANGED
|
@@ -604,8 +604,8 @@ export const EventsApiAxiosParamCreator = function (configuration) {
|
|
|
604
604
|
* @param {*} [options] Override http request option.
|
|
605
605
|
* @throws {RequiredError}
|
|
606
606
|
*/
|
|
607
|
-
|
|
608
|
-
const localVarPath = `/ws/
|
|
607
|
+
wsEventsGet: async (token, options = {}) => {
|
|
608
|
+
const localVarPath = `/ws/events`;
|
|
609
609
|
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
|
610
610
|
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
|
611
611
|
let baseOptions;
|
|
@@ -642,10 +642,10 @@ export const EventsApiFp = function (configuration) {
|
|
|
642
642
|
* @param {*} [options] Override http request option.
|
|
643
643
|
* @throws {RequiredError}
|
|
644
644
|
*/
|
|
645
|
-
async
|
|
646
|
-
const localVarAxiosArgs = await localVarAxiosParamCreator.
|
|
645
|
+
async wsEventsGet(token, options) {
|
|
646
|
+
const localVarAxiosArgs = await localVarAxiosParamCreator.wsEventsGet(token, options);
|
|
647
647
|
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
|
648
|
-
const localVarOperationServerBasePath = operationServerMap['EventsApi.
|
|
648
|
+
const localVarOperationServerBasePath = operationServerMap['EventsApi.wsEventsGet']?.[localVarOperationServerIndex]?.url;
|
|
649
649
|
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
|
650
650
|
},
|
|
651
651
|
};
|
|
@@ -664,8 +664,8 @@ export const EventsApiFactory = function (configuration, basePath, axios) {
|
|
|
664
664
|
* @param {*} [options] Override http request option.
|
|
665
665
|
* @throws {RequiredError}
|
|
666
666
|
*/
|
|
667
|
-
|
|
668
|
-
return localVarFp.
|
|
667
|
+
wsEventsGet(token, options) {
|
|
668
|
+
return localVarFp.wsEventsGet(token, options).then((request) => request(axios, basePath));
|
|
669
669
|
},
|
|
670
670
|
};
|
|
671
671
|
};
|
|
@@ -684,8 +684,8 @@ export class EventsApi extends BaseAPI {
|
|
|
684
684
|
* @throws {RequiredError}
|
|
685
685
|
* @memberof EventsApi
|
|
686
686
|
*/
|
|
687
|
-
|
|
688
|
-
return EventsApiFp(this.configuration).
|
|
687
|
+
wsEventsGet(token, options) {
|
|
688
|
+
return EventsApiFp(this.configuration).wsEventsGet(token, options).then((request) => request(this.axios, this.basePath));
|
|
689
689
|
}
|
|
690
690
|
}
|
|
691
691
|
/**
|
package/remote-api/index.d.ts
CHANGED
package/remote-api/index.js
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AuthEnvironment, type AuthState } from '../models/auth-state.js';
|
|
2
|
+
export declare const DEFAULT_AUTH_STATE: AuthState;
|
|
3
|
+
export declare const isAuthEnvironment: (value: string | undefined) => value is AuthEnvironment;
|
|
4
|
+
export declare const decodeAuthState: (rawState: string) => AuthState;
|
|
5
|
+
export declare const encodeAuthState: (state: AuthState) => string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { safeParse } from 'valibot';
|
|
2
|
+
import { AUTH_ENVIRONMENTS, AUTH_STATE_SCHEMA } from "../models/auth-state.js";
|
|
3
|
+
import { to } from "./to-error.js";
|
|
4
|
+
export const DEFAULT_AUTH_STATE = { environment: 'web' };
|
|
5
|
+
export const isAuthEnvironment = (value) => Boolean(value && AUTH_ENVIRONMENTS.includes(value));
|
|
6
|
+
export const decodeAuthState = (rawState) => {
|
|
7
|
+
if (!rawState)
|
|
8
|
+
return DEFAULT_AUTH_STATE;
|
|
9
|
+
const safeJsonParse = to(() => JSON.parse(rawState));
|
|
10
|
+
const parsed = safeJsonParse();
|
|
11
|
+
if (parsed.isErr())
|
|
12
|
+
return DEFAULT_AUTH_STATE;
|
|
13
|
+
const validated = safeParse(AUTH_STATE_SCHEMA, parsed.value);
|
|
14
|
+
if (!validated.success)
|
|
15
|
+
return DEFAULT_AUTH_STATE;
|
|
16
|
+
return validated.output;
|
|
17
|
+
};
|
|
18
|
+
export const encodeAuthState = (state) => JSON.stringify(state);
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
package/utils/toml.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BaseSchema, InferOutput } from 'valibot';
|
|
2
|
-
export declare function parseToml<T = unknown, S extends BaseSchema<unknown, unknown,
|
|
1
|
+
import { BaseIssue, BaseSchema, InferOutput } from 'valibot';
|
|
2
|
+
export declare function parseToml<T = unknown, S extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | undefined = undefined>(content: string, schema?: S): S extends BaseSchema<unknown, unknown, BaseIssue<unknown>> ? InferOutput<S> : T;
|
|
3
3
|
export declare function stringifyToml(data: unknown): string;
|