@jokio/sdk 0.1.5 → 0.1.7

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@jokio/sdk",
3
3
  "description": "pure js/ts sdk for building decentralised localfirst web apps. Provides tts ai model integrations, realtime p2p communication & crypto encryptions.",
4
- "version": "0.1.5",
4
+ "version": "0.1.7",
5
5
  "license": "MIT",
6
6
  "main": "dist/jokio.sdk.umd.js",
7
7
  "keywords": [
@@ -38,14 +38,23 @@ export class AuthService {
38
38
  }
39
39
 
40
40
  async requestPasskeyLogin(
41
- displayName: string = '',
42
- addAsAdditionalDevice = false,
41
+ opts: {
42
+ displayName?: string
43
+ isRegistration?: boolean
44
+ addAsAdditionalDevice?: boolean
45
+ } = {},
43
46
  ) {
47
+ const {
48
+ displayName = '',
49
+ isRegistration = false,
50
+ addAsAdditionalDevice = false,
51
+ } = opts
52
+
44
53
  // 1. get challenge options
45
- const opts = await fetch(
54
+ const passkeyOpts = await fetch(
46
55
  this.config.authUrl +
47
56
  `/webauth-challenge-request?registration=${
48
- !!displayName ? 'true' : ''
57
+ isRegistration ? 'true' : ''
49
58
  }&displayName=${displayName}`,
50
59
  { credentials: 'include' },
51
60
  ).then(processResponse)
@@ -53,10 +62,14 @@ export class AuthService {
53
62
  // 2. ask user to register
54
63
  let attResp
55
64
  try {
56
- if (!opts.user?.id) {
57
- attResp = await startAuthentication({ optionsJSON: opts })
65
+ if (!passkeyOpts.user?.id) {
66
+ attResp = await startAuthentication({
67
+ optionsJSON: passkeyOpts,
68
+ })
58
69
  } else {
59
- attResp = await startRegistration({ optionsJSON: opts })
70
+ attResp = await startRegistration({
71
+ optionsJSON: passkeyOpts,
72
+ })
60
73
  }
61
74
  } catch (error: any) {
62
75
  if (error.name === 'InvalidStateError') {
@@ -91,7 +104,7 @@ export class AuthService {
91
104
  return res as IdentityUser
92
105
  }
93
106
 
94
- async guestSignIn() {
107
+ async guestLogin() {
95
108
  const res = await fetch(this.config.authUrl + `/sign-out`, {
96
109
  credentials: 'include',
97
110
  }).then(processResponse)
@@ -29,11 +29,13 @@ export class NatsService<TApi> {
29
29
 
30
30
  constructor(private config: Config) {}
31
31
 
32
- async connect(opts: {
33
- natsWsServerUrls?: string[]
34
- user?: IdentityUser
35
- prefix?: string
36
- }) {
32
+ async connect(
33
+ opts: {
34
+ natsWsServerUrls?: string[]
35
+ user?: IdentityUser
36
+ prefix?: string
37
+ } = {},
38
+ ) {
37
39
  const { natsWsServerUrls, user, prefix } = opts
38
40
 
39
41
  const finalNatsServerUrls = natsWsServerUrls ?? [
package/test/index.html CHANGED
@@ -68,7 +68,7 @@
68
68
 
69
69
  window.natsSubscribe = async function () {
70
70
  await jok.nats.on('dev.test', (data, ctx) => {
71
- console.lg({ data, ctx })
71
+ console.log({ data, ctx })
72
72
  })
73
73
  }
74
74
 
@@ -1,21 +0,0 @@
1
- type Config = {
2
- authUrl: string;
3
- };
4
- export declare class AuthService {
5
- private config;
6
- constructor(config: Config);
7
- requestEmailLogin(email: string, returnUrl?: string): Promise<boolean>;
8
- completeEmailLogin(email: string, otpCode: string): Promise<IdentityUser>;
9
- requestPasskeyLogin(displayName?: string, addAsAdditionalDevice?: boolean): Promise<IdentityUser>;
10
- guestSignIn(): Promise<IdentityUser>;
11
- clearLoginData(): Promise<void>;
12
- getLastLoginData(): any;
13
- }
14
- export type IdentityUser = {
15
- name: string;
16
- email: string;
17
- userId: string;
18
- sessionId: string;
19
- verified: boolean;
20
- };
21
- export {};
@@ -1 +0,0 @@
1
- export declare function playAudioFromBuffer(buffer: ArrayBuffer): HTMLAudioElement;
@@ -1,9 +0,0 @@
1
- export declare class CryptoService {
2
- createSessionKeyPair(): Promise<CryptoKeyPair>;
3
- exportPublicKey(publicKey: CryptoKey): Promise<string>;
4
- deriveAESKey(privateKey: CryptoKey, publicKeyString: string): Promise<CryptoKey>;
5
- exportRawKey(key: CryptoKey): Promise<string>;
6
- encrypt(text: string, key: CryptoKey): Promise<string>;
7
- decrypt(encryptedText: string, key: CryptoKey): Promise<string>;
8
- hashString(text: string): Promise<string>;
9
- }
package/dist/index.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import { AuthService } from './auth.service';
2
- import { CryptoService } from './crypto.service';
3
- import { NatsService } from './nats.service';
4
- import { EdgeTtsService } from './tts.service';
5
- export { NatsService } from './nats.service';
6
- export { VoicevoxTtsService } from './voicevoxTts';
7
- type Config = {
8
- debug: boolean;
9
- authUrl: string;
10
- natsUrl: string;
11
- };
12
- export declare const jok: {
13
- setup(config: Partial<Config>): void;
14
- auth: AuthService;
15
- tts: EdgeTtsService;
16
- nats: NatsService<unknown>;
17
- crypto: CryptoService;
18
- };
package/dist/index.html DELETED
@@ -1,106 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <title>MyLibrary Test</title>
7
- </head>
8
-
9
- <body>
10
- <h1>Library Test</h1>
11
-
12
- <button onclick="playAudio()">TTS</button>
13
- <button onclick="playAudio2()">Voicevox TTS</button>
14
-
15
- <script type="module">
16
- // import { jok } from 'https://esm.run/@jokio/sdk';
17
- import { jok, VoicevoxTtsService } from './dist/jokio.sdk.es.js';
18
-
19
- window.jok = jok
20
-
21
- window.getVoicevoxVoices = async function () {
22
- const voices = await jok.voicevoxTts.getVoices()
23
-
24
- console.log(voices)
25
- }
26
-
27
- window.getVoices = async function () {
28
- const voices = await jok.tts.getVoices()
29
-
30
- console.log(voices)
31
- }
32
-
33
- window.playAudio = async function () {
34
- const audio = await jok.tts.getAudio("Hello there, how are you?", "en-US-AvaNeural")
35
-
36
- audio.play()
37
- }
38
-
39
- window.playAudio2 = async function () {
40
- const tts = new VoicevoxTtsService({ voicevoxUrl: 'https://voicevox.fly.dev' })
41
-
42
- const audio = await tts.getAudio("こんにちわ、おげんきですか?あなたはあたまがいいですね。", 3)
43
-
44
- audio.play()
45
- }
46
-
47
- window.requestEmailLogin = async function (email) {
48
- const res = await jok.auth.requestEmailLogin(email, 'https://localhost:5173')
49
-
50
- return res
51
- }
52
-
53
- window.completeEmailLogin = async function (email, otpCode) {
54
- const res = await jok.auth.completeEmailLogin(email, otpCode)
55
-
56
- return res
57
- }
58
-
59
- window.passkeyLogin = async function (displayName) {
60
- const res = await jok.auth.requestPasskeyLogin(displayName)
61
-
62
- return res
63
- }
64
-
65
- window.natsConnect = async function () {
66
- await jok.nats.connect()
67
- }
68
-
69
- window.natsSubscribe = async function () {
70
- await jok.nats.on('dev.test', (data, ctx) => {
71
- console.lg({ data, ctx })
72
- })
73
- }
74
-
75
- window.natsPublish = async function () {
76
- await jok.nats.publish('dev.test', { name: 'User', age: 11 })
77
- }
78
-
79
- window.p2pChat = async function () {
80
- const kp1 = await jok.crypto.createSessionKeyPair()
81
- const kp2 = await jok.crypto.createSessionKeyPair()
82
-
83
- const p1 = await jok.crypto.exportPublicKey(kp1.publicKey)
84
- const p2 = await jok.crypto.exportPublicKey(kp2.publicKey)
85
-
86
- console.log({ p1, p2 })
87
-
88
- const shared1 = await jok.crypto.deriveAESKey(kp1.privateKey, p2)
89
- const shared2 = await jok.crypto.deriveAESKey(kp2.privateKey, p1)
90
-
91
- const originalText = "Hello World"
92
-
93
- const encrypted = await jok.crypto.encrypt(originalText, shared1)
94
- const decrypted = await jok.crypto.decrypt(encrypted, shared2)
95
-
96
- console.log({
97
- match: originalText === decrypted,
98
- originalText,
99
- decrypted,
100
- })
101
- }
102
- </script>
103
-
104
- </body>
105
-
106
- </html>