orgnote-api 0.40.0 → 0.40.9

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.
@@ -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
  };
@@ -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 = {}));
@@ -1,5 +1,5 @@
1
1
  export declare const RoutePaths: {
2
- readonly AUTH_LOGIN: "auth/login";
2
+ readonly AUTH_LOGIN: "auth";
3
3
  readonly AUTH_ACTIVATE: "auth/activate";
4
4
  };
5
5
  export type RoutePath = (typeof RoutePaths)[keyof typeof RoutePaths];
@@ -1,4 +1,4 @@
1
1
  export const RoutePaths = {
2
- AUTH_LOGIN: 'auth/login',
2
+ AUTH_LOGIN: 'auth',
3
3
  AUTH_ACTIVATE: 'auth/activate',
4
4
  };
@@ -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
- // Helper function to generate a NoteInfo object
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 = faker.lorem.paragraphs();
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, // Используем armoredPublicKey
43
- privateKey: armoredPrivateKey, // Используем armoredPrivateKey
44
- privateKeyPassphrase, // Используем 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 encryptedNoteText = `-----BEGIN PGP MESSAGE-----
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, // Используем armoredPublicKey
59
- privateKey: armoredPrivateKey, // Используем armoredPrivateKey
60
- privateKeyPassphrase, // Используем 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/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";
@@ -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<T = unknown> {
4
+ export interface MenuActionBase {
5
5
  icon?: string;
6
6
  title?: string;
7
7
  }
8
- export interface ManualMenuAction<T = unknown> extends MenuActionBase<T> {
8
+ export interface ManualMenuAction<T = unknown> extends MenuActionBase {
9
9
  handler: (data: T) => void;
10
10
  }
11
11
  export interface CommandMenuAction extends MenuActionBase {
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 interface User extends PublicUser {
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.0",
3
+ "version": "0.40.9",
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 && bun publish",
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": "git+https://github.com/artawower/orgnote-api.git"
24
+ "url": "https://github.com/Artawower/orgnote-api"
25
25
  },
26
26
  "exports": {
27
27
  ".": "./index.js",
@@ -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
- wsV1EventsGet: (token?: string, options?: RawAxiosRequestConfig) => Promise<RequestArgs>;
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
- wsV1EventsGet(token?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>>;
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
- wsV1EventsGet(token?: string, options?: any): AxiosPromise<void>;
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
- wsV1EventsGet(token?: string, options?: RawAxiosRequestConfig): Promise<import("axios").AxiosResponse<void, any>>;
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
- wsV1EventsGet: async (token, options = {}) => {
608
- const localVarPath = `/ws/v1/events`;
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 wsV1EventsGet(token, options) {
646
- const localVarAxiosArgs = await localVarAxiosParamCreator.wsV1EventsGet(token, options);
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.wsV1EventsGet']?.[localVarOperationServerIndex]?.url;
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
- wsV1EventsGet(token, options) {
668
- return localVarFp.wsV1EventsGet(token, options).then((request) => request(axios, basePath));
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
- wsV1EventsGet(token, options) {
688
- return EventsApiFp(this.configuration).wsV1EventsGet(token, options).then((request) => request(this.axios, this.basePath));
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
  /**
@@ -9,5 +9,5 @@
9
9
  * https://openapi-generator.tech
10
10
  * Do not edit the class manually.
11
11
  */
12
- export * from "./api.js";
13
- export * from "./configuration.js";
12
+ export * from './api.js';
13
+ export * from './configuration.js';
@@ -1,5 +1,4 @@
1
1
  /* tslint:disable */
2
- /* eslint-disable */
3
2
  /**
4
3
  * Org Note API
5
4
  * List of methods for work with Org Note.
@@ -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
@@ -9,4 +9,5 @@ export * from './get-parent-dir.js';
9
9
  export * from './toml.js';
10
10
  export * from './to-absolute-path.js';
11
11
  export * from './to-error.js';
12
+ export * from './auth-state.js';
12
13
  export * from './nullable-guards.js';
package/utils/index.js CHANGED
@@ -9,4 +9,5 @@ export * from "./get-parent-dir.js";
9
9
  export * from "./toml.js";
10
10
  export * from "./to-absolute-path.js";
11
11
  export * from "./to-error.js";
12
+ export * from "./auth-state.js";
12
13
  export * from "./nullable-guards.js";
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, any> | undefined = undefined>(content: string, schema?: S): S extends BaseSchema<unknown, unknown, any> ? InferOutput<S> : T;
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;