@strivacity/sdk-vue 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # 1.0.0 (2024-09-20)
2
+
3
+
4
+ ### 🚀 Features
5
+
6
+ - @strivacity/sdk-vue package implemented
7
+
8
+
9
+ ### 🧱 Updated Dependencies
10
+
11
+ - Updated sdk-core to 1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Strivacity Inc. <info@strivacity.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # @strivacity/sdk-vue
2
+
3
+ > **The SDK supports Vue version 3 and above**
4
+
5
+ ### Install
6
+
7
+ ```bash
8
+ npm install @strivacity/sdk-vue
9
+ ```
10
+
11
+ ### Usage
12
+
13
+ #### Add this to your main file:
14
+
15
+ ```js
16
+ import { createApp } from 'vue';
17
+ import App from './App.vue';
18
+ import { createStrivacitySDK } from '@strivacity/sdk-vue';
19
+
20
+ const app = createApp(AppComponent);
21
+ const sdk = createStrivacitySDK({
22
+ issuer: 'https://<YOUR_DOMAIN>',
23
+ scopes: ['openid', 'profile'],
24
+ clientId: '<YOUR_CLIENT_ID>',
25
+ redirectUri: '<YOUR_REDIRECT_URI>',
26
+ });
27
+
28
+ app.use(sdk);
29
+ app.mount('#app');
30
+ ```
31
+
32
+ #### How to use the SDK in your components:
33
+
34
+ ```js
35
+ <script setup>
36
+ import { computed } from 'vue';
37
+ import { useStrivacity } from '@strivacity/sdk-vue';
38
+
39
+ const { isAuthenticated, idTokenClaims, login, logout } = useStrivacity();
40
+ const name = computed(() => `${idTokenClaims.value?.given_name} ${idTokenClaims.value?.family_name}`);
41
+ </script>
42
+
43
+ <template>
44
+ <template v-if="isAuthenticated">
45
+ <div>Welcome, {{ name }}!</div>
46
+ <button @click="logout()">Logout</button>
47
+ </template>
48
+
49
+ <template v-else>
50
+ <div>Not logged in</div>
51
+ <button @click="login()">Log in</button>
52
+ </template>
53
+ </template>
54
+ ```
55
+
56
+ ### API Documentation
57
+
58
+ #### `useStrivacity` hook
59
+
60
+ ```typescript
61
+ useStrivacity<T extends PopupContext | RedirectContext>(): T;
62
+ ```
63
+
64
+ You can choose between `PopupContext` or `RedirectContext` with the `mode` option when you configure the sdk options.
65
+
66
+ **Properties**
67
+
68
+ - **`loading: boolean`**: Indicates if the session is being loaded.
69
+ - **`isAuthenticated: boolean`**: Indicates whether the user is authenticated.
70
+ - **`idTokenClaims: IdTokenClaims | null`**: Claims from the ID token or null if not available.
71
+ - **`accessToken: string | null`**: The access token or null if not available.
72
+ - **`refreshToken: string | null`**: The refresh token or null if not available.
73
+ - **`accessTokenExpired: boolean`**: Indicates if the access token has expired.
74
+ - **`accessTokenExpirationDate: number | null`**: Expiration date of the access token or null if not set.
75
+
76
+ ---
77
+
78
+ Type: `RedirectContext`
79
+ Represents the available methods for Redirect-based interactions.
80
+
81
+ - **`login(options?: LoginOptions): Promise<void>`**: Initiates the login process by redirecting the user to the identity provider.
82
+ - `options` (optional): Configuration options for login.
83
+ - **`register(options?: RegisterOptions): Promise<void>`**: Registers a new user using a redirect flow.
84
+ - `options` (optional): Configuration options for registration.
85
+ - **`refresh(): Promise<void>`**: Refreshes the user's session using a redirect flow.
86
+ - **`revoke(): Promise<void>`**: Revokes the current session tokens using a redirect flow.
87
+ - **`logout(options?: LogoutOptions): Promise<void>`**: Logs out the user by redirecting to the logout page.
88
+ - `options` (optional): Configuration options for logout.
89
+ - **`handleCallback(url?: string): Promise<void>`**: Handles the callback after a redirect-based authentication or token exchange.
90
+ - `url` (optional): The URL to handle for the callback.
91
+
92
+ ---
93
+
94
+ Type: `PopupContext`
95
+ Represents the available methods for Popup-based interactions.
96
+
97
+ - **`login(options?: LoginOptions): Promise<void>`**: Initiates the login process using a popup window.
98
+ - `options` (optional): Configuration options for login.
99
+ - **`register(options?: RegisterOptions): Promise<void>`**: Registers a new user using a popup flow.
100
+ - `options` (optional): Configuration options for registration.
101
+ - **`refresh(): Promise<void>`**: Refreshes the user's session using a popup.
102
+ - **`revoke(): Promise<void>`**: Revokes the current session tokens using a popup flow.
103
+ - **`logout(options?: LogoutOptions): Promise<void>`**: Logs out the user using a popup window.
104
+ - `options` (optional): Configuration options for logout.
105
+ - **`handleCallback(url?: string): Promise<void>`**: Handles the callback after a popup-based authentication or token exchange.
106
+ - `url` (optional): The URL to handle for the callback.
107
+
108
+ ### Links
109
+
110
+ - [Example app](https://github.com/Strivacity/sdk-js/tree/main/apps/vue)
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue"),k=require("@strivacity/sdk-core"),T=require("@strivacity/sdk-core/storages/LocalStorage"),b=require("@strivacity/sdk-core/storages/SessionStorage"),f=Symbol("sty");exports.isAuthenticated=()=>Promise.resolve(!1);const g=()=>{const n=s.inject(f);if(!n)throw Error("Missing Strivacity SDK context");return n},S=n=>{const e=k.initFlow(n);return{install:v=>{const i=s.ref(!0),o=s.ref(!1),r=s.ref(null),c=s.ref(null),l=s.ref(null),u=s.ref(!0),d=s.ref(null),t=async()=>{o.value=await e.isAuthenticated,r.value=e.idTokenClaims||null,c.value=e.accessToken||null,l.value=e.refreshToken||null,u.value=e.accessTokenExpired,d.value=e.accessTokenExpirationDate||null,i.value&&(i.value=!1)};exports.isAuthenticated=()=>e.isAuthenticated,e.subscribeToEvent("init",t),e.subscribeToEvent("loggedIn",t),e.subscribeToEvent("sessionLoaded",t),e.subscribeToEvent("tokenRefreshed",t),e.subscribeToEvent("tokenRefreshFailed",t),e.subscribeToEvent("logoutInitiated",t),e.subscribeToEvent("tokenRevoked",t),e.subscribeToEvent("tokenRevokeFailed",t),v.provide(f,{loading:i,isAuthenticated:o,idTokenClaims:r,accessToken:c,refreshToken:l,accessTokenExpired:u,accessTokenExpirationDate:d,login:async a=>{await e.login(a),await t()},register:async a=>{await e.register(a),await t()},refresh:async()=>{await e.refresh(),await t()},revoke:async()=>{await e.revoke(),await t()},logout:async a=>{await e.logout(a),await t()},handleCallback:async a=>{await e.handleCallback(a),await t()}})}}};Object.defineProperty(exports,"LocalStorage",{enumerable:!0,get:()=>T.LocalStorage});Object.defineProperty(exports,"SessionStorage",{enumerable:!0,get:()=>b.SessionStorage});exports.createStrivacitySDK=S;exports.useStrivacity=g;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { type App, inject, ref } from 'vue';\nimport { initFlow, type SDKOptions, type SDKStorage, type IdTokenClaims } from '@strivacity/sdk-core';\nimport type { PopupFlow } from '@strivacity/sdk-core/flows/PopupFlow';\nimport type { RedirectFlow } from '@strivacity/sdk-core/flows/RedirectFlow';\nimport { LocalStorage } from '@strivacity/sdk-core/storages/LocalStorage';\nimport { SessionStorage } from '@strivacity/sdk-core/storages/SessionStorage';\nimport type { Session, PopupContext, PopupSDK, RedirectContext, RedirectSDK } from './types';\n\nexport type { SDKOptions, SDKStorage, Session, IdTokenClaims, PopupFlow, RedirectFlow, PopupContext, RedirectContext, PopupSDK, RedirectSDK };\nexport { LocalStorage, SessionStorage };\n\nconst STRIVACITY_SDK = Symbol('sty');\n\n/**\n * Checks if the user is authenticated.\n *\n * @returns {Promise<boolean>} A promise that resolves to `true` if the user is authenticated, otherwise `false`.\n */\nexport let isAuthenticated: () => Promise<boolean> = () => Promise.resolve(false);\n\n/**\n * Retrieves the Strivacity SDK context for Popup or Redirect flows.\n *\n * @template T The type of context, either PopupContext or RedirectContext.\n *\n * @throws {Error} If the Strivacity SDK context is not found.\n *\n * @returns {T} The Strivacity SDK context, typed as either PopupContext or RedirectContext.\n */\nexport const useStrivacity = <T extends PopupContext | RedirectContext>() => {\n\tconst context = inject(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow Error('Missing Strivacity SDK context');\n\t}\n\n\treturn context as T;\n};\n\n/**\n * Creates a Strivacity SDK plugin for Vue.\n *\n * @param {SDKOptions} options - The options used to configure the SDK.\n *\n * @returns {Plugin} A Vue plugin that can be installed in the application.\n */\nexport const createStrivacitySDK = (options: SDKOptions) => {\n\tconst sdk = initFlow(options);\n\n\tconst plugin = {\n\t\tinstall: (app: App) => {\n\t\t\tconst loadingRef = ref<boolean>(true);\n\t\t\tconst isAuthenticatedRef = ref<boolean>(false);\n\t\t\tconst idTokenClaimsRef = ref<IdTokenClaims | null>(null);\n\t\t\tconst accessTokenRef = ref<string | null>(null);\n\t\t\tconst refreshTokenRef = ref<string | null>(null);\n\t\t\tconst accessTokenExpiredRef = ref<boolean>(true);\n\t\t\tconst accessTokenExpirationDateRef = ref<number | null>(null);\n\n\t\t\tconst updateSession = async () => {\n\t\t\t\tisAuthenticatedRef.value = await sdk.isAuthenticated;\n\t\t\t\tidTokenClaimsRef.value = sdk.idTokenClaims || null;\n\t\t\t\taccessTokenRef.value = sdk.accessToken || null;\n\t\t\t\trefreshTokenRef.value = sdk.refreshToken || null;\n\t\t\t\taccessTokenExpiredRef.value = sdk.accessTokenExpired;\n\t\t\t\taccessTokenExpirationDateRef.value = sdk.accessTokenExpirationDate || null;\n\n\t\t\t\tif (loadingRef.value) {\n\t\t\t\t\tloadingRef.value = false;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tisAuthenticated = () => sdk.isAuthenticated;\n\n\t\t\tsdk.subscribeToEvent('init', updateSession);\n\t\t\tsdk.subscribeToEvent('loggedIn', updateSession);\n\t\t\tsdk.subscribeToEvent('sessionLoaded', updateSession);\n\t\t\tsdk.subscribeToEvent('tokenRefreshed', updateSession);\n\t\t\tsdk.subscribeToEvent('tokenRefreshFailed', updateSession);\n\t\t\tsdk.subscribeToEvent('logoutInitiated', updateSession);\n\t\t\tsdk.subscribeToEvent('tokenRevoked', updateSession);\n\t\t\tsdk.subscribeToEvent('tokenRevokeFailed', updateSession);\n\n\t\t\tapp.provide(STRIVACITY_SDK, {\n\t\t\t\tloading: loadingRef,\n\t\t\t\tisAuthenticated: isAuthenticatedRef,\n\t\t\t\tidTokenClaims: idTokenClaimsRef,\n\t\t\t\taccessToken: accessTokenRef,\n\t\t\t\trefreshToken: refreshTokenRef,\n\t\t\t\taccessTokenExpired: accessTokenExpiredRef,\n\t\t\t\taccessTokenExpirationDate: accessTokenExpirationDateRef,\n\n\t\t\t\tlogin: async (options?: Parameters<PopupFlow['login'] | RedirectFlow['login']>[0]) => {\n\t\t\t\t\tawait sdk.login(options);\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\tregister: async (options?: Parameters<PopupFlow['register'] | RedirectFlow['register']>[0]) => {\n\t\t\t\t\tawait sdk.register(options);\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\trefresh: async () => {\n\t\t\t\t\tawait sdk.refresh();\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\trevoke: async () => {\n\t\t\t\t\tawait sdk.revoke();\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\tlogout: async (options?: Parameters<PopupFlow['logout'] | RedirectFlow['logout']>[0]) => {\n\t\t\t\t\tawait sdk.logout(options);\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\thandleCallback: async (url?: Parameters<PopupFlow['handleCallback'] | RedirectFlow['handleCallback']>[0]) => {\n\t\t\t\t\tawait sdk.handleCallback(url);\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n\n\treturn plugin;\n};\n"],"names":["STRIVACITY_SDK","isAuthenticated","useStrivacity","context","inject","createStrivacitySDK","options","sdk","initFlow","app","loadingRef","ref","isAuthenticatedRef","idTokenClaimsRef","accessTokenRef","refreshTokenRef","accessTokenExpiredRef","accessTokenExpirationDateRef","updateSession","url"],"mappings":"2PAWMA,EAAiB,OAAO,KAAK,EAOxBC,QAAAA,gBAA0C,IAAM,QAAQ,QAAQ,EAAK,EAWzE,MAAMC,EAAgB,IAAgD,CACtE,MAAAC,EAAUC,SAAOJ,CAAc,EAErC,GAAI,CAACG,EACJ,MAAM,MAAM,gCAAgC,EAGtC,OAAAA,CACR,EASaE,EAAuBC,GAAwB,CACrD,MAAAC,EAAMC,WAASF,CAAO,EAyErB,MAvEQ,CACd,QAAUG,GAAa,CAChB,MAAAC,EAAaC,MAAa,EAAI,EAC9BC,EAAqBD,MAAa,EAAK,EACvCE,EAAmBF,MAA0B,IAAI,EACjDG,EAAiBH,MAAmB,IAAI,EACxCI,EAAkBJ,MAAmB,IAAI,EACzCK,EAAwBL,MAAa,EAAI,EACzCM,EAA+BN,MAAmB,IAAI,EAEtDO,EAAgB,SAAY,CACdN,EAAA,MAAQ,MAAML,EAAI,gBACpBM,EAAA,MAAQN,EAAI,eAAiB,KAC/BO,EAAA,MAAQP,EAAI,aAAe,KAC1BQ,EAAA,MAAQR,EAAI,cAAgB,KAC5CS,EAAsB,MAAQT,EAAI,mBACLU,EAAA,MAAQV,EAAI,2BAA6B,KAElEG,EAAW,QACdA,EAAW,MAAQ,GACpB,EAGDT,wBAAkB,IAAMM,EAAI,gBAExBA,EAAA,iBAAiB,OAAQW,CAAa,EACtCX,EAAA,iBAAiB,WAAYW,CAAa,EAC1CX,EAAA,iBAAiB,gBAAiBW,CAAa,EAC/CX,EAAA,iBAAiB,iBAAkBW,CAAa,EAChDX,EAAA,iBAAiB,qBAAsBW,CAAa,EACpDX,EAAA,iBAAiB,kBAAmBW,CAAa,EACjDX,EAAA,iBAAiB,eAAgBW,CAAa,EAC9CX,EAAA,iBAAiB,oBAAqBW,CAAa,EAEvDT,EAAI,QAAQT,EAAgB,CAC3B,QAASU,EACT,gBAAiBE,EACjB,cAAeC,EACf,YAAaC,EACb,aAAcC,EACd,mBAAoBC,EACpB,0BAA2BC,EAE3B,MAAO,MAAOX,GAAwE,CAC/E,MAAAC,EAAI,MAAMD,CAAO,EACvB,MAAMY,EAAc,CACrB,EACA,SAAU,MAAOZ,GAA8E,CACxF,MAAAC,EAAI,SAASD,CAAO,EAC1B,MAAMY,EAAc,CACrB,EACA,QAAS,SAAY,CACpB,MAAMX,EAAI,UACV,MAAMW,EAAc,CACrB,EACA,OAAQ,SAAY,CACnB,MAAMX,EAAI,SACV,MAAMW,EAAc,CACrB,EACA,OAAQ,MAAOZ,GAA0E,CAClF,MAAAC,EAAI,OAAOD,CAAO,EACxB,MAAMY,EAAc,CACrB,EACA,eAAgB,MAAOC,GAAsF,CACtG,MAAAZ,EAAI,eAAeY,CAAG,EAC5B,MAAMD,EAAc,CACrB,CAAA,CACA,CACF,CAAA,CAIF"}
@@ -0,0 +1,35 @@
1
+ import { App } from 'vue';
2
+ import { SDKOptions, SDKStorage, IdTokenClaims } from '@strivacity/sdk-core';
3
+ import { PopupFlow } from '@strivacity/sdk-core/flows/PopupFlow';
4
+ import { RedirectFlow } from '@strivacity/sdk-core/flows/RedirectFlow';
5
+ import { LocalStorage } from '@strivacity/sdk-core/storages/LocalStorage';
6
+ import { SessionStorage } from '@strivacity/sdk-core/storages/SessionStorage';
7
+ import { Session, PopupContext, PopupSDK, RedirectContext, RedirectSDK } from './types';
8
+ export type { SDKOptions, SDKStorage, Session, IdTokenClaims, PopupFlow, RedirectFlow, PopupContext, RedirectContext, PopupSDK, RedirectSDK };
9
+ export { LocalStorage, SessionStorage };
10
+ /**
11
+ * Checks if the user is authenticated.
12
+ *
13
+ * @returns {Promise<boolean>} A promise that resolves to `true` if the user is authenticated, otherwise `false`.
14
+ */
15
+ export declare let isAuthenticated: () => Promise<boolean>;
16
+ /**
17
+ * Retrieves the Strivacity SDK context for Popup or Redirect flows.
18
+ *
19
+ * @template T The type of context, either PopupContext or RedirectContext.
20
+ *
21
+ * @throws {Error} If the Strivacity SDK context is not found.
22
+ *
23
+ * @returns {T} The Strivacity SDK context, typed as either PopupContext or RedirectContext.
24
+ */
25
+ export declare const useStrivacity: <T extends PopupContext | RedirectContext>() => T;
26
+ /**
27
+ * Creates a Strivacity SDK plugin for Vue.
28
+ *
29
+ * @param {SDKOptions} options - The options used to configure the SDK.
30
+ *
31
+ * @returns {Plugin} A Vue plugin that can be installed in the application.
32
+ */
33
+ export declare const createStrivacitySDK: (options: SDKOptions) => {
34
+ install: (app: App) => void;
35
+ };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import{inject as T,ref as a}from"vue";import{initFlow as f}from"@strivacity/sdk-core";import{LocalStorage as S}from"@strivacity/sdk-core/storages/LocalStorage";import{SessionStorage as x}from"@strivacity/sdk-core/storages/SessionStorage";const k=Symbol("sty");let b=()=>Promise.resolve(!1);const w=()=>{const n=T(k);if(!n)throw Error("Missing Strivacity SDK context");return n},E=n=>{const e=f(n);return{install:v=>{const o=a(!0),i=a(!1),c=a(null),r=a(null),l=a(null),u=a(!0),d=a(null),t=async()=>{i.value=await e.isAuthenticated,c.value=e.idTokenClaims||null,r.value=e.accessToken||null,l.value=e.refreshToken||null,u.value=e.accessTokenExpired,d.value=e.accessTokenExpirationDate||null,o.value&&(o.value=!1)};b=()=>e.isAuthenticated,e.subscribeToEvent("init",t),e.subscribeToEvent("loggedIn",t),e.subscribeToEvent("sessionLoaded",t),e.subscribeToEvent("tokenRefreshed",t),e.subscribeToEvent("tokenRefreshFailed",t),e.subscribeToEvent("logoutInitiated",t),e.subscribeToEvent("tokenRevoked",t),e.subscribeToEvent("tokenRevokeFailed",t),v.provide(k,{loading:o,isAuthenticated:i,idTokenClaims:c,accessToken:r,refreshToken:l,accessTokenExpired:u,accessTokenExpirationDate:d,login:async s=>{await e.login(s),await t()},register:async s=>{await e.register(s),await t()},refresh:async()=>{await e.refresh(),await t()},revoke:async()=>{await e.revoke(),await t()},logout:async s=>{await e.logout(s),await t()},handleCallback:async s=>{await e.handleCallback(s),await t()}})}}};export{S as LocalStorage,x as SessionStorage,E as createStrivacitySDK,b as isAuthenticated,w as useStrivacity};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { type App, inject, ref } from 'vue';\nimport { initFlow, type SDKOptions, type SDKStorage, type IdTokenClaims } from '@strivacity/sdk-core';\nimport type { PopupFlow } from '@strivacity/sdk-core/flows/PopupFlow';\nimport type { RedirectFlow } from '@strivacity/sdk-core/flows/RedirectFlow';\nimport { LocalStorage } from '@strivacity/sdk-core/storages/LocalStorage';\nimport { SessionStorage } from '@strivacity/sdk-core/storages/SessionStorage';\nimport type { Session, PopupContext, PopupSDK, RedirectContext, RedirectSDK } from './types';\n\nexport type { SDKOptions, SDKStorage, Session, IdTokenClaims, PopupFlow, RedirectFlow, PopupContext, RedirectContext, PopupSDK, RedirectSDK };\nexport { LocalStorage, SessionStorage };\n\nconst STRIVACITY_SDK = Symbol('sty');\n\n/**\n * Checks if the user is authenticated.\n *\n * @returns {Promise<boolean>} A promise that resolves to `true` if the user is authenticated, otherwise `false`.\n */\nexport let isAuthenticated: () => Promise<boolean> = () => Promise.resolve(false);\n\n/**\n * Retrieves the Strivacity SDK context for Popup or Redirect flows.\n *\n * @template T The type of context, either PopupContext or RedirectContext.\n *\n * @throws {Error} If the Strivacity SDK context is not found.\n *\n * @returns {T} The Strivacity SDK context, typed as either PopupContext or RedirectContext.\n */\nexport const useStrivacity = <T extends PopupContext | RedirectContext>() => {\n\tconst context = inject(STRIVACITY_SDK);\n\n\tif (!context) {\n\t\tthrow Error('Missing Strivacity SDK context');\n\t}\n\n\treturn context as T;\n};\n\n/**\n * Creates a Strivacity SDK plugin for Vue.\n *\n * @param {SDKOptions} options - The options used to configure the SDK.\n *\n * @returns {Plugin} A Vue plugin that can be installed in the application.\n */\nexport const createStrivacitySDK = (options: SDKOptions) => {\n\tconst sdk = initFlow(options);\n\n\tconst plugin = {\n\t\tinstall: (app: App) => {\n\t\t\tconst loadingRef = ref<boolean>(true);\n\t\t\tconst isAuthenticatedRef = ref<boolean>(false);\n\t\t\tconst idTokenClaimsRef = ref<IdTokenClaims | null>(null);\n\t\t\tconst accessTokenRef = ref<string | null>(null);\n\t\t\tconst refreshTokenRef = ref<string | null>(null);\n\t\t\tconst accessTokenExpiredRef = ref<boolean>(true);\n\t\t\tconst accessTokenExpirationDateRef = ref<number | null>(null);\n\n\t\t\tconst updateSession = async () => {\n\t\t\t\tisAuthenticatedRef.value = await sdk.isAuthenticated;\n\t\t\t\tidTokenClaimsRef.value = sdk.idTokenClaims || null;\n\t\t\t\taccessTokenRef.value = sdk.accessToken || null;\n\t\t\t\trefreshTokenRef.value = sdk.refreshToken || null;\n\t\t\t\taccessTokenExpiredRef.value = sdk.accessTokenExpired;\n\t\t\t\taccessTokenExpirationDateRef.value = sdk.accessTokenExpirationDate || null;\n\n\t\t\t\tif (loadingRef.value) {\n\t\t\t\t\tloadingRef.value = false;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tisAuthenticated = () => sdk.isAuthenticated;\n\n\t\t\tsdk.subscribeToEvent('init', updateSession);\n\t\t\tsdk.subscribeToEvent('loggedIn', updateSession);\n\t\t\tsdk.subscribeToEvent('sessionLoaded', updateSession);\n\t\t\tsdk.subscribeToEvent('tokenRefreshed', updateSession);\n\t\t\tsdk.subscribeToEvent('tokenRefreshFailed', updateSession);\n\t\t\tsdk.subscribeToEvent('logoutInitiated', updateSession);\n\t\t\tsdk.subscribeToEvent('tokenRevoked', updateSession);\n\t\t\tsdk.subscribeToEvent('tokenRevokeFailed', updateSession);\n\n\t\t\tapp.provide(STRIVACITY_SDK, {\n\t\t\t\tloading: loadingRef,\n\t\t\t\tisAuthenticated: isAuthenticatedRef,\n\t\t\t\tidTokenClaims: idTokenClaimsRef,\n\t\t\t\taccessToken: accessTokenRef,\n\t\t\t\trefreshToken: refreshTokenRef,\n\t\t\t\taccessTokenExpired: accessTokenExpiredRef,\n\t\t\t\taccessTokenExpirationDate: accessTokenExpirationDateRef,\n\n\t\t\t\tlogin: async (options?: Parameters<PopupFlow['login'] | RedirectFlow['login']>[0]) => {\n\t\t\t\t\tawait sdk.login(options);\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\tregister: async (options?: Parameters<PopupFlow['register'] | RedirectFlow['register']>[0]) => {\n\t\t\t\t\tawait sdk.register(options);\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\trefresh: async () => {\n\t\t\t\t\tawait sdk.refresh();\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\trevoke: async () => {\n\t\t\t\t\tawait sdk.revoke();\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\tlogout: async (options?: Parameters<PopupFlow['logout'] | RedirectFlow['logout']>[0]) => {\n\t\t\t\t\tawait sdk.logout(options);\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t\thandleCallback: async (url?: Parameters<PopupFlow['handleCallback'] | RedirectFlow['handleCallback']>[0]) => {\n\t\t\t\t\tawait sdk.handleCallback(url);\n\t\t\t\t\tawait updateSession();\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n\n\treturn plugin;\n};\n"],"names":["STRIVACITY_SDK","isAuthenticated","useStrivacity","context","inject","createStrivacitySDK","options","sdk","initFlow","app","loadingRef","ref","isAuthenticatedRef","idTokenClaimsRef","accessTokenRef","refreshTokenRef","accessTokenExpiredRef","accessTokenExpirationDateRef","updateSession","url"],"mappings":"8OAWA,MAAMA,EAAiB,OAAO,KAAK,EAO5B,IAAIC,EAA0C,IAAM,QAAQ,QAAQ,EAAK,EAWzE,MAAMC,EAAgB,IAAgD,CACtE,MAAAC,EAAUC,EAAOJ,CAAc,EAErC,GAAI,CAACG,EACJ,MAAM,MAAM,gCAAgC,EAGtC,OAAAA,CACR,EASaE,EAAuBC,GAAwB,CACrD,MAAAC,EAAMC,EAASF,CAAO,EAyErB,MAvEQ,CACd,QAAUG,GAAa,CAChB,MAAAC,EAAaC,EAAa,EAAI,EAC9BC,EAAqBD,EAAa,EAAK,EACvCE,EAAmBF,EAA0B,IAAI,EACjDG,EAAiBH,EAAmB,IAAI,EACxCI,EAAkBJ,EAAmB,IAAI,EACzCK,EAAwBL,EAAa,EAAI,EACzCM,EAA+BN,EAAmB,IAAI,EAEtDO,EAAgB,SAAY,CACdN,EAAA,MAAQ,MAAML,EAAI,gBACpBM,EAAA,MAAQN,EAAI,eAAiB,KAC/BO,EAAA,MAAQP,EAAI,aAAe,KAC1BQ,EAAA,MAAQR,EAAI,cAAgB,KAC5CS,EAAsB,MAAQT,EAAI,mBACLU,EAAA,MAAQV,EAAI,2BAA6B,KAElEG,EAAW,QACdA,EAAW,MAAQ,GACpB,EAGDT,EAAkB,IAAMM,EAAI,gBAExBA,EAAA,iBAAiB,OAAQW,CAAa,EACtCX,EAAA,iBAAiB,WAAYW,CAAa,EAC1CX,EAAA,iBAAiB,gBAAiBW,CAAa,EAC/CX,EAAA,iBAAiB,iBAAkBW,CAAa,EAChDX,EAAA,iBAAiB,qBAAsBW,CAAa,EACpDX,EAAA,iBAAiB,kBAAmBW,CAAa,EACjDX,EAAA,iBAAiB,eAAgBW,CAAa,EAC9CX,EAAA,iBAAiB,oBAAqBW,CAAa,EAEvDT,EAAI,QAAQT,EAAgB,CAC3B,QAASU,EACT,gBAAiBE,EACjB,cAAeC,EACf,YAAaC,EACb,aAAcC,EACd,mBAAoBC,EACpB,0BAA2BC,EAE3B,MAAO,MAAOX,GAAwE,CAC/E,MAAAC,EAAI,MAAMD,CAAO,EACvB,MAAMY,EAAc,CACrB,EACA,SAAU,MAAOZ,GAA8E,CACxF,MAAAC,EAAI,SAASD,CAAO,EAC1B,MAAMY,EAAc,CACrB,EACA,QAAS,SAAY,CACpB,MAAMX,EAAI,UACV,MAAMW,EAAc,CACrB,EACA,OAAQ,SAAY,CACnB,MAAMX,EAAI,SACV,MAAMW,EAAc,CACrB,EACA,OAAQ,MAAOZ,GAA0E,CAClF,MAAAC,EAAI,OAAOD,CAAO,EACxB,MAAMY,EAAc,CACrB,EACA,eAAgB,MAAOC,GAAsF,CACtG,MAAAZ,EAAI,eAAeY,CAAG,EAC5B,MAAMD,EAAc,CACrB,CAAA,CACA,CACF,CAAA,CAIF"}
package/dist/types.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,110 @@
1
+ import { Ref } from 'vue';
2
+ import { IdTokenClaims } from '@strivacity/sdk-core';
3
+ import { PopupFlow } from '@strivacity/sdk-core/flows/PopupFlow';
4
+ import { RedirectFlow } from '@strivacity/sdk-core/flows/RedirectFlow';
5
+ /**
6
+ * Represents the session state, including authentication details and token information.
7
+ */
8
+ export type Session = {
9
+ /**
10
+ * Reactive reference to the loading state of the session.
11
+ * `true` when the session is initializing, otherwise `false`.
12
+ */
13
+ loading: Ref<boolean>;
14
+ /**
15
+ * Reactive reference to the user's authentication status.
16
+ * `true` if the user is authenticated, otherwise `false`.
17
+ */
18
+ isAuthenticated: Ref<boolean>;
19
+ /**
20
+ * Reactive reference to the claims contained in the ID token.
21
+ * Contains user identity and other information, or `null` if not authenticated.
22
+ */
23
+ idTokenClaims: Ref<IdTokenClaims | null>;
24
+ /**
25
+ * Reactive reference to the current access token for API authorization.
26
+ * `null` if the user is not authenticated or the token is unavailable.
27
+ */
28
+ accessToken: Ref<string | null>;
29
+ /**
30
+ * Reactive reference to the refresh token, used to refresh the access token.
31
+ * `null` if the user is not authenticated or the refresh token is unavailable.
32
+ */
33
+ refreshToken: Ref<string | null>;
34
+ /**
35
+ * Reactive reference indicating if the access token has expired.
36
+ * `true` if expired, otherwise `false`.
37
+ */
38
+ accessTokenExpired: Ref<boolean>;
39
+ /**
40
+ * Reactive reference to the expiration date of the access token in Unix time (milliseconds).
41
+ * `null` if no token is available or the session is not authenticated.
42
+ */
43
+ accessTokenExpirationDate: Ref<number | null>;
44
+ };
45
+ /**
46
+ * Represents the available authentication flows and operations for Popup-based interactions.
47
+ */
48
+ export type PopupSDK = {
49
+ /**
50
+ * Initiates the login process using a popup window.
51
+ */
52
+ login: InstanceType<typeof PopupFlow>['login'];
53
+ /**
54
+ * Registers a new user using a popup flow.
55
+ */
56
+ register: InstanceType<typeof PopupFlow>['register'];
57
+ /**
58
+ * Refreshes the user's session using a popup.
59
+ */
60
+ refresh: InstanceType<typeof PopupFlow>['refresh'];
61
+ /**
62
+ * Revokes the current session tokens using a popup flow.
63
+ */
64
+ revoke: InstanceType<typeof PopupFlow>['revoke'];
65
+ /**
66
+ * Logs out the user using a popup window.
67
+ */
68
+ logout: InstanceType<typeof PopupFlow>['logout'];
69
+ /**
70
+ * Handles the callback after a popup-based authentication or token exchange.
71
+ */
72
+ handleCallback: InstanceType<typeof PopupFlow>['handleCallback'];
73
+ };
74
+ /**
75
+ * Represents the available authentication flows and operations for Redirect-based interactions.
76
+ */
77
+ export type RedirectSDK = {
78
+ /**
79
+ * Initiates the login process by redirecting the user to the identity provider.
80
+ */
81
+ login: InstanceType<typeof RedirectFlow>['login'];
82
+ /**
83
+ * Registers a new user using a redirect flow.
84
+ */
85
+ register: InstanceType<typeof RedirectFlow>['register'];
86
+ /**
87
+ * Refreshes the user's session using a redirect flow.
88
+ */
89
+ refresh: InstanceType<typeof RedirectFlow>['refresh'];
90
+ /**
91
+ * Revokes the current session tokens using a redirect flow.
92
+ */
93
+ revoke: InstanceType<typeof RedirectFlow>['revoke'];
94
+ /**
95
+ * Logs out the user by redirecting to the logout page.
96
+ */
97
+ logout: InstanceType<typeof RedirectFlow>['logout'];
98
+ /**
99
+ * Handles the callback after a redirect-based authentication or token exchange.
100
+ */
101
+ handleCallback: InstanceType<typeof RedirectFlow>['handleCallback'];
102
+ };
103
+ /**
104
+ * Represents a combined context for Popup-based flows, containing both the Popup SDK and the session state.
105
+ */
106
+ export type PopupContext = PopupSDK & Session;
107
+ /**
108
+ * Represents a combined context for Redirect-based flows, containing both the Redirect SDK and the session state.
109
+ */
110
+ export type RedirectContext = RedirectSDK & Session;
package/dist/types.mjs ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@strivacity/sdk-vue",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "description": "Strivacity Vue.js SDK client",
7
+ "author": "strivacity <info@strivacity.com>",
8
+ "dependencies": {
9
+ "@strivacity/sdk-core": "1.0.0"
10
+ },
11
+ "peerDependencies": {
12
+ "vue": ">=3"
13
+ },
14
+ "main": "./dist/index.cjs",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs",
21
+ "default": "./dist/index.mjs"
22
+ }
23
+ }
24
+ }