@merkaly/nuxt 0.11.4 → 0.12.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/README.md +1 -1
- package/dist/module.json +1 -1
- package/dist/runtime/components/input/InputSearch.d.vue.ts +2 -2
- package/dist/runtime/components/input/InputSearch.vue.d.ts +2 -2
- package/dist/runtime/plugins/auth0.client.d.ts +3 -2
- package/dist/runtime/plugins/auth0.client.js +18 -15
- package/package.json +1 -2
- package/dist/runtime/adapters/delete.auth.session.d.ts +0 -1
- package/dist/runtime/adapters/delete.auth.session.js +0 -6
- package/dist/runtime/adapters/read.auth.session.d.ts +0 -9
- package/dist/runtime/adapters/read.auth.session.js +0 -8
- package/dist/runtime/components/format/FormatAddress.d.vue.ts +0 -69
- package/dist/runtime/components/format/FormatAddress.vue +0 -37
- package/dist/runtime/components/format/FormatAddress.vue.d.ts +0 -69
- package/dist/runtime/components/input/InputAddress.d.vue.ts +0 -88
- package/dist/runtime/components/input/InputAddress.vue +0 -115
- package/dist/runtime/components/input/InputAddress.vue.d.ts +0 -88
- package/dist/runtime/components/input/InputPassword.d.vue.ts +0 -3
- package/dist/runtime/components/input/InputPassword.vue +0 -7
- package/dist/runtime/components/input/InputPassword.vue.d.ts +0 -3
- package/dist/runtime/components/modal/ModalAddress.d.vue.ts +0 -11
- package/dist/runtime/components/modal/ModalAddress.vue +0 -56
- package/dist/runtime/components/modal/ModalAddress.vue.d.ts +0 -11
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ On boot the module restores an existing session (user and token) and then runs t
|
|
|
37
37
|
|
|
38
38
|
### Session lifetime
|
|
39
39
|
|
|
40
|
-
The SPA keeps the session with **refresh tokens**: the client uses `useRefreshTokens` with `localStorage` cache and logs in with `audience` and `scope: openid profile email offline_access`. Before each API call the module asks Auth0 for the current access token, which is cached and renewed with the refresh token once it expires (2 hours for `https://api.merkaly.io`). When the refresh token is gone or expired, protected surfaces (`requiresAuth: true`) go back to login instead of calling the API without a token. Account linking (`linkWithConnection`) uses a separate client (account.merkaly.io) with an in-memory cache.
|
|
40
|
+
The SPA keeps the session with **refresh tokens**: the client uses `useRefreshTokens` with `localStorage` cache and logs in with `audience` and `scope: openid profile email offline_access`. Before each API call the module asks Auth0 for the current access token, which is cached and renewed with the refresh token once it expires (2 hours for `https://api.merkaly.io`). When the refresh token is gone or expired, protected surfaces (`requiresAuth: true`) go back to login instead of calling the API without a token. Account linking (`linkWithConnection(connection)`) uses a separate Auth0 client, the account linking client (named `account.merkaly.io` in Auth0, no app behind it), with an in-memory cache, created only on the first call (no extra `checkSession` on page load). It opens a login popup for that connection and sends the popup's raw ID token to `POST /identities` as `{ idToken }`; the api verifies the token (signature, issuer, audience = the account linking client, expiry) and links the identity from its `sub` into the logged-in user. Requires an api with that contract (older clients that sent `{ provider, userId }` get `400`).
|
|
41
41
|
|
|
42
42
|
The Auth0 side (tenant, API, app settings, refresh token rotation and lifetimes, organizations, and the checklist for a new app) is documented in the auth.merkaly.io repo: [`docs/tenant-setup.md`](https://github.com/merkaly-io/auth.merkaly.io/blob/master/docs/tenant-setup.md).
|
|
43
43
|
|
package/dist/module.json
CHANGED
|
@@ -7,8 +7,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
7
7
|
type: import("vue").PropType<string>;
|
|
8
8
|
};
|
|
9
9
|
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
10
|
-
change: () => any;
|
|
11
10
|
"update:modelValue": (value: string) => any;
|
|
11
|
+
change: () => any;
|
|
12
12
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
13
13
|
debounce: {
|
|
14
14
|
type: NumberConstructor;
|
|
@@ -18,8 +18,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
18
18
|
type: import("vue").PropType<string>;
|
|
19
19
|
};
|
|
20
20
|
}>> & Readonly<{
|
|
21
|
-
onChange?: (() => any) | undefined;
|
|
22
21
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
22
|
+
onChange?: (() => any) | undefined;
|
|
23
23
|
}>, {
|
|
24
24
|
debounce: number;
|
|
25
25
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -7,8 +7,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
7
7
|
type: import("vue").PropType<string>;
|
|
8
8
|
};
|
|
9
9
|
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
10
|
-
change: () => any;
|
|
11
10
|
"update:modelValue": (value: string) => any;
|
|
11
|
+
change: () => any;
|
|
12
12
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
13
13
|
debounce: {
|
|
14
14
|
type: NumberConstructor;
|
|
@@ -18,8 +18,8 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
18
18
|
type: import("vue").PropType<string>;
|
|
19
19
|
};
|
|
20
20
|
}>> & Readonly<{
|
|
21
|
-
onChange?: (() => any) | undefined;
|
|
22
21
|
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
22
|
+
onChange?: (() => any) | undefined;
|
|
23
23
|
}>, {
|
|
24
24
|
debounce: number;
|
|
25
25
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Auth0Client } from '@auth0/auth0-spa-js';
|
|
1
2
|
declare const _default: import("#app").Plugin<{
|
|
2
|
-
auth0:
|
|
3
|
+
auth0: Auth0Client;
|
|
3
4
|
}> & import("#app").ObjectPlugin<{
|
|
4
|
-
auth0:
|
|
5
|
+
auth0: Auth0Client;
|
|
5
6
|
}>;
|
|
6
7
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createAuth0Client } from "@auth0/auth0-spa-js";
|
|
1
|
+
import { Auth0Client, createAuth0Client } from "@auth0/auth0-spa-js";
|
|
2
2
|
import { defineNuxtPlugin, useRuntimeConfig, useNuxtApp, useState } from "#imports";
|
|
3
3
|
import { navigateTo } from "#app";
|
|
4
4
|
import { defu } from "defu";
|
|
@@ -71,27 +71,30 @@ export default defineNuxtPlugin(async ({ callHook, hook }) => {
|
|
|
71
71
|
returnTo: URL.canParse($config.merkaly.auth0.logoutUrl) ? $config.merkaly.auth0.logoutUrl : location.origin.concat($config.merkaly.auth0.logoutUrl)
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
74
|
+
let linkingClient;
|
|
75
|
+
const getLinkingClient = () => linkingClient ??= new Auth0Client({
|
|
76
|
+
authorizationParams: {
|
|
77
|
+
redirect_uri: URL.canParse($config.merkaly.auth0.callbackUrl) ? $config.merkaly.auth0.callbackUrl : location.origin.concat($config.merkaly.auth0.callbackUrl)
|
|
78
|
+
},
|
|
77
79
|
cacheLocation: "memory",
|
|
78
80
|
clientId: "AwD3uBHhLhFBbJhwSWXYFh9cZYidNc6L",
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
redirect_uri: redirectUri
|
|
82
|
-
}
|
|
81
|
+
// account.merkaly.io, the api checks this audience
|
|
82
|
+
domain: $config.merkaly.auth0.domain
|
|
83
83
|
});
|
|
84
84
|
auth0.linkWithConnection = async (connection) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
const client = getLinkingClient();
|
|
86
|
+
await client.loginWithPopup({ authorizationParams: { connection } });
|
|
87
|
+
const claims = await client.getIdTokenClaims();
|
|
88
|
+
if (!claims?.__raw) {
|
|
88
89
|
throw new Error("Failed to get ID token for linking");
|
|
89
90
|
}
|
|
90
|
-
const [provider, ...userIdParts] = claims.sub.split("|");
|
|
91
|
-
const userId = userIdParts.join("|");
|
|
92
|
-
const body = { provider, userId };
|
|
93
91
|
const { $api } = useNuxtApp();
|
|
94
|
-
return await $api("/identities", {
|
|
92
|
+
return await $api("/identities", {
|
|
93
|
+
// the api verifies it and derives the identity
|
|
94
|
+
body: { idToken: claims.__raw },
|
|
95
|
+
global: true,
|
|
96
|
+
method: "POST"
|
|
97
|
+
});
|
|
95
98
|
};
|
|
96
99
|
const isAuthCallback = window.location.pathname === callbackPath;
|
|
97
100
|
if (isAuthCallback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkaly/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/merkaly-io/nuxt.git"
|
|
@@ -71,7 +71,6 @@
|
|
|
71
71
|
"@nuxt/module-builder": "^1.0.2",
|
|
72
72
|
"@nuxt/schema": "^4.6.0",
|
|
73
73
|
"changelogen": "^0.6.2",
|
|
74
|
-
"eslint-plugin-storybook": "^10.6.0",
|
|
75
74
|
"vue-tsc": "^3.3.4"
|
|
76
75
|
},
|
|
77
76
|
"optionalDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const deleteAuthSession: (args?: ((args: object) => import("../utils/withAdapter.js").AdapterArgs<undefined, Record<string, unknown>, object>) | undefined) => import("../composables/useApi.js").UseApiReturn<undefined, Record<string, unknown>, object>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
interface AuthSessionData {
|
|
2
|
-
expiresAt: string | Date;
|
|
3
|
-
issuedAt: string | Date;
|
|
4
|
-
orgId?: string;
|
|
5
|
-
role: string;
|
|
6
|
-
userId: string;
|
|
7
|
-
}
|
|
8
|
-
export declare const readAuthSession: (args?: ((args: object) => import("../utils/withAdapter.js").AdapterArgs<AuthSessionData, Record<string, unknown>, object>) | undefined) => import("../composables/useApi.js").UseApiReturn<AuthSessionData, Record<string, unknown>, object>;
|
|
9
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
|
-
city: {
|
|
3
|
-
type: StringConstructor;
|
|
4
|
-
default: string;
|
|
5
|
-
};
|
|
6
|
-
code: {
|
|
7
|
-
type: StringConstructor;
|
|
8
|
-
default: string;
|
|
9
|
-
};
|
|
10
|
-
country: {
|
|
11
|
-
type: StringConstructor;
|
|
12
|
-
default: string;
|
|
13
|
-
};
|
|
14
|
-
line1: {
|
|
15
|
-
type: StringConstructor;
|
|
16
|
-
default: string;
|
|
17
|
-
};
|
|
18
|
-
line2: {
|
|
19
|
-
type: StringConstructor;
|
|
20
|
-
default: string;
|
|
21
|
-
};
|
|
22
|
-
locality: {
|
|
23
|
-
type: StringConstructor;
|
|
24
|
-
default: string;
|
|
25
|
-
};
|
|
26
|
-
state: {
|
|
27
|
-
type: StringConstructor;
|
|
28
|
-
default: string;
|
|
29
|
-
};
|
|
30
|
-
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
31
|
-
city: {
|
|
32
|
-
type: StringConstructor;
|
|
33
|
-
default: string;
|
|
34
|
-
};
|
|
35
|
-
code: {
|
|
36
|
-
type: StringConstructor;
|
|
37
|
-
default: string;
|
|
38
|
-
};
|
|
39
|
-
country: {
|
|
40
|
-
type: StringConstructor;
|
|
41
|
-
default: string;
|
|
42
|
-
};
|
|
43
|
-
line1: {
|
|
44
|
-
type: StringConstructor;
|
|
45
|
-
default: string;
|
|
46
|
-
};
|
|
47
|
-
line2: {
|
|
48
|
-
type: StringConstructor;
|
|
49
|
-
default: string;
|
|
50
|
-
};
|
|
51
|
-
locality: {
|
|
52
|
-
type: StringConstructor;
|
|
53
|
-
default: string;
|
|
54
|
-
};
|
|
55
|
-
state: {
|
|
56
|
-
type: StringConstructor;
|
|
57
|
-
default: string;
|
|
58
|
-
};
|
|
59
|
-
}>> & Readonly<{}>, {
|
|
60
|
-
code: string;
|
|
61
|
-
city: string;
|
|
62
|
-
country: string;
|
|
63
|
-
line1: string;
|
|
64
|
-
line2: string;
|
|
65
|
-
locality: string;
|
|
66
|
-
state: string;
|
|
67
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
68
|
-
declare const _default: typeof __VLS_export;
|
|
69
|
-
export default _default;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { computed } from "vue";
|
|
3
|
-
const props = defineProps({
|
|
4
|
-
city: { type: String, default: "" },
|
|
5
|
-
code: { type: String, default: "" },
|
|
6
|
-
country: { type: String, default: "" },
|
|
7
|
-
line1: { type: String, default: "" },
|
|
8
|
-
line2: { type: String, default: "" },
|
|
9
|
-
locality: { type: String, default: "" },
|
|
10
|
-
state: { type: String, default: "" }
|
|
11
|
-
});
|
|
12
|
-
const lines = computed(() => {
|
|
13
|
-
const parts = [];
|
|
14
|
-
if (props.line1) parts.push(props.line1);
|
|
15
|
-
if (props.line2) parts.push(props.line2);
|
|
16
|
-
const cityLine = [props.city, props.state].filter(Boolean).join(", ");
|
|
17
|
-
const cityWithCode = [cityLine, props.code].filter(Boolean).join(" ");
|
|
18
|
-
if (cityWithCode) parts.push(cityWithCode);
|
|
19
|
-
if (props.locality) parts.push(props.locality);
|
|
20
|
-
if (props.country) parts.push(props.country);
|
|
21
|
-
return parts;
|
|
22
|
-
});
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<template>
|
|
26
|
-
<address>
|
|
27
|
-
<template v-for="(line, i) in lines" :key="i">
|
|
28
|
-
{{ line }}<br v-if="i < lines.length - 1">
|
|
29
|
-
</template>
|
|
30
|
-
</address>
|
|
31
|
-
</template>
|
|
32
|
-
|
|
33
|
-
<style scoped>
|
|
34
|
-
address {
|
|
35
|
-
margin: 0;
|
|
36
|
-
}
|
|
37
|
-
</style>
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
|
-
city: {
|
|
3
|
-
type: StringConstructor;
|
|
4
|
-
default: string;
|
|
5
|
-
};
|
|
6
|
-
code: {
|
|
7
|
-
type: StringConstructor;
|
|
8
|
-
default: string;
|
|
9
|
-
};
|
|
10
|
-
country: {
|
|
11
|
-
type: StringConstructor;
|
|
12
|
-
default: string;
|
|
13
|
-
};
|
|
14
|
-
line1: {
|
|
15
|
-
type: StringConstructor;
|
|
16
|
-
default: string;
|
|
17
|
-
};
|
|
18
|
-
line2: {
|
|
19
|
-
type: StringConstructor;
|
|
20
|
-
default: string;
|
|
21
|
-
};
|
|
22
|
-
locality: {
|
|
23
|
-
type: StringConstructor;
|
|
24
|
-
default: string;
|
|
25
|
-
};
|
|
26
|
-
state: {
|
|
27
|
-
type: StringConstructor;
|
|
28
|
-
default: string;
|
|
29
|
-
};
|
|
30
|
-
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
31
|
-
city: {
|
|
32
|
-
type: StringConstructor;
|
|
33
|
-
default: string;
|
|
34
|
-
};
|
|
35
|
-
code: {
|
|
36
|
-
type: StringConstructor;
|
|
37
|
-
default: string;
|
|
38
|
-
};
|
|
39
|
-
country: {
|
|
40
|
-
type: StringConstructor;
|
|
41
|
-
default: string;
|
|
42
|
-
};
|
|
43
|
-
line1: {
|
|
44
|
-
type: StringConstructor;
|
|
45
|
-
default: string;
|
|
46
|
-
};
|
|
47
|
-
line2: {
|
|
48
|
-
type: StringConstructor;
|
|
49
|
-
default: string;
|
|
50
|
-
};
|
|
51
|
-
locality: {
|
|
52
|
-
type: StringConstructor;
|
|
53
|
-
default: string;
|
|
54
|
-
};
|
|
55
|
-
state: {
|
|
56
|
-
type: StringConstructor;
|
|
57
|
-
default: string;
|
|
58
|
-
};
|
|
59
|
-
}>> & Readonly<{}>, {
|
|
60
|
-
code: string;
|
|
61
|
-
city: string;
|
|
62
|
-
country: string;
|
|
63
|
-
line1: string;
|
|
64
|
-
line2: string;
|
|
65
|
-
locality: string;
|
|
66
|
-
state: string;
|
|
67
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
68
|
-
declare const _default: typeof __VLS_export;
|
|
69
|
-
export default _default;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { PropType } from 'vue';
|
|
2
|
-
export type PlaceTypes = 'address' | 'geocode' | 'establishment' | '(regions)' | '(cities)';
|
|
3
|
-
export interface Address {
|
|
4
|
-
city: string;
|
|
5
|
-
code: string;
|
|
6
|
-
country: string;
|
|
7
|
-
latitude: number;
|
|
8
|
-
line1: string;
|
|
9
|
-
line2: string;
|
|
10
|
-
locality: string;
|
|
11
|
-
longitude: number;
|
|
12
|
-
name: string;
|
|
13
|
-
number: string;
|
|
14
|
-
state: string;
|
|
15
|
-
street: string;
|
|
16
|
-
}
|
|
17
|
-
interface PlaceResult {
|
|
18
|
-
formatted_address?: string;
|
|
19
|
-
name?: string;
|
|
20
|
-
geometry?: {
|
|
21
|
-
location: {
|
|
22
|
-
lat: () => number;
|
|
23
|
-
lng: () => number;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
address_components?: AddressComponent[];
|
|
27
|
-
}
|
|
28
|
-
interface AddressComponent {
|
|
29
|
-
short_name: string;
|
|
30
|
-
types: string[];
|
|
31
|
-
}
|
|
32
|
-
declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
33
|
-
mode: {
|
|
34
|
-
type: PropType<PlaceTypes>;
|
|
35
|
-
default: string;
|
|
36
|
-
};
|
|
37
|
-
countries: {
|
|
38
|
-
type: PropType<string[]>;
|
|
39
|
-
default: () => never[];
|
|
40
|
-
};
|
|
41
|
-
placeholder: {
|
|
42
|
-
type: StringConstructor;
|
|
43
|
-
default: string;
|
|
44
|
-
};
|
|
45
|
-
disabled: {
|
|
46
|
-
type: BooleanConstructor;
|
|
47
|
-
default: boolean;
|
|
48
|
-
};
|
|
49
|
-
modelValue: {
|
|
50
|
-
type: PropType<string>;
|
|
51
|
-
};
|
|
52
|
-
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
53
|
-
"update:modelValue": (value: string) => any;
|
|
54
|
-
} & {
|
|
55
|
-
error: (place: PlaceResult) => any;
|
|
56
|
-
search: (args: Address) => any;
|
|
57
|
-
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
58
|
-
mode: {
|
|
59
|
-
type: PropType<PlaceTypes>;
|
|
60
|
-
default: string;
|
|
61
|
-
};
|
|
62
|
-
countries: {
|
|
63
|
-
type: PropType<string[]>;
|
|
64
|
-
default: () => never[];
|
|
65
|
-
};
|
|
66
|
-
placeholder: {
|
|
67
|
-
type: StringConstructor;
|
|
68
|
-
default: string;
|
|
69
|
-
};
|
|
70
|
-
disabled: {
|
|
71
|
-
type: BooleanConstructor;
|
|
72
|
-
default: boolean;
|
|
73
|
-
};
|
|
74
|
-
modelValue: {
|
|
75
|
-
type: PropType<string>;
|
|
76
|
-
};
|
|
77
|
-
}>> & Readonly<{
|
|
78
|
-
onError?: ((place: PlaceResult) => any) | undefined;
|
|
79
|
-
onSearch?: ((args: Address) => any) | undefined;
|
|
80
|
-
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
81
|
-
}>, {
|
|
82
|
-
mode: PlaceTypes;
|
|
83
|
-
disabled: boolean;
|
|
84
|
-
placeholder: string;
|
|
85
|
-
countries: string[];
|
|
86
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
87
|
-
declare const _default: typeof __VLS_export;
|
|
88
|
-
export default _default;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { h, onBeforeUnmount, onMounted, reactive, ref } from "vue";
|
|
3
|
-
import { BFormInput, BInputGroup, BButton, useModal } from "bootstrap-vue-next";
|
|
4
|
-
import { useNuxtApp } from "#imports";
|
|
5
|
-
import FormatIcon from "../format/FormatIcon.vue";
|
|
6
|
-
import ModalAddress from "../modal/ModalAddress.vue";
|
|
7
|
-
const ADDRESS_FORMAT = {
|
|
8
|
-
city: ["locality", "administrative_area_level_2"],
|
|
9
|
-
code: ["postal_code"],
|
|
10
|
-
country: ["country"],
|
|
11
|
-
locality: ["sublocality", "sublocality_level_1", "political"],
|
|
12
|
-
number: ["street_number"],
|
|
13
|
-
state: ["administrative_area_level_1"],
|
|
14
|
-
street: ["route"]
|
|
15
|
-
};
|
|
16
|
-
const emit = defineEmits(["search", "error"]);
|
|
17
|
-
const props = defineProps({
|
|
18
|
-
mode: { type: String, default: "geocode" },
|
|
19
|
-
countries: { type: Array, default: () => [] },
|
|
20
|
-
placeholder: { type: String, default: "Search address" },
|
|
21
|
-
disabled: { type: Boolean, default: false }
|
|
22
|
-
});
|
|
23
|
-
const model = defineModel({ type: String, default: () => "" });
|
|
24
|
-
const address = reactive({
|
|
25
|
-
city: "",
|
|
26
|
-
code: "",
|
|
27
|
-
country: "",
|
|
28
|
-
latitude: 0,
|
|
29
|
-
line1: "",
|
|
30
|
-
line2: "",
|
|
31
|
-
locality: "",
|
|
32
|
-
longitude: 0,
|
|
33
|
-
name: "",
|
|
34
|
-
number: "",
|
|
35
|
-
state: "",
|
|
36
|
-
street: ""
|
|
37
|
-
});
|
|
38
|
-
const input = ref();
|
|
39
|
-
let placeChangedListener = null;
|
|
40
|
-
function setAddress(items) {
|
|
41
|
-
for (const item of items) {
|
|
42
|
-
const type = item.types[0];
|
|
43
|
-
if (!type) continue;
|
|
44
|
-
for (const key of Object.keys(ADDRESS_FORMAT)) {
|
|
45
|
-
if (ADDRESS_FORMAT[key].includes(type)) {
|
|
46
|
-
address[key] = item.short_name;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
emit("search", { ...address });
|
|
52
|
-
}
|
|
53
|
-
function getInputElement() {
|
|
54
|
-
return input.value?.$el ?? null;
|
|
55
|
-
}
|
|
56
|
-
onMounted(() => {
|
|
57
|
-
const { $gmap } = useNuxtApp();
|
|
58
|
-
const inputElement = getInputElement();
|
|
59
|
-
if (!inputElement) return;
|
|
60
|
-
inputElement.value = model.value;
|
|
61
|
-
const ac = new $gmap.places.Autocomplete(inputElement, {
|
|
62
|
-
componentRestrictions: props.countries.length ? { country: props.countries } : void 0,
|
|
63
|
-
types: [props.mode]
|
|
64
|
-
});
|
|
65
|
-
placeChangedListener = ac.addListener("place_changed", () => {
|
|
66
|
-
const place = ac.getPlace();
|
|
67
|
-
if (!place.geometry) {
|
|
68
|
-
return emit("error", place);
|
|
69
|
-
}
|
|
70
|
-
const { lat, lng } = place.geometry.location;
|
|
71
|
-
address.line1 = place.name ?? "";
|
|
72
|
-
address.latitude = lat();
|
|
73
|
-
address.longitude = lng();
|
|
74
|
-
setAddress(place.address_components ?? []);
|
|
75
|
-
model.value = place.formatted_address;
|
|
76
|
-
address.name = model.value;
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
onBeforeUnmount(() => {
|
|
80
|
-
placeChangedListener?.remove();
|
|
81
|
-
placeChangedListener = null;
|
|
82
|
-
});
|
|
83
|
-
const { create: createModal } = useModal();
|
|
84
|
-
async function openAddressModal() {
|
|
85
|
-
const editedAddress = reactive({ ...address });
|
|
86
|
-
const result = await createModal({
|
|
87
|
-
cancelTitle: "Cancelar",
|
|
88
|
-
okTitle: "Guardar",
|
|
89
|
-
size: "lg",
|
|
90
|
-
slots: {
|
|
91
|
-
default: () => h(ModalAddress, {
|
|
92
|
-
address: editedAddress,
|
|
93
|
-
"onUpdate:address": (value) => Object.assign(editedAddress, value)
|
|
94
|
-
})
|
|
95
|
-
},
|
|
96
|
-
title: "Editar direcci\xF3n"
|
|
97
|
-
}).show();
|
|
98
|
-
if (result.ok) {
|
|
99
|
-
Object.assign(address, editedAddress);
|
|
100
|
-
emit("search", { ...address });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
</script>
|
|
104
|
-
|
|
105
|
-
<template>
|
|
106
|
-
<BInputGroup>
|
|
107
|
-
<template #append>
|
|
108
|
-
<BButton variant="light" class="border px-3" @click="openAddressModal()">
|
|
109
|
-
<FormatIcon name="map-marker-alt" />
|
|
110
|
-
</BButton>
|
|
111
|
-
</template>
|
|
112
|
-
|
|
113
|
-
<BFormInput ref="input" :model-value="model" v-bind="{ ...props, $attrs }" autocomplete="one-time-code" />
|
|
114
|
-
</BInputGroup>
|
|
115
|
-
</template>
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { PropType } from 'vue';
|
|
2
|
-
export type PlaceTypes = 'address' | 'geocode' | 'establishment' | '(regions)' | '(cities)';
|
|
3
|
-
export interface Address {
|
|
4
|
-
city: string;
|
|
5
|
-
code: string;
|
|
6
|
-
country: string;
|
|
7
|
-
latitude: number;
|
|
8
|
-
line1: string;
|
|
9
|
-
line2: string;
|
|
10
|
-
locality: string;
|
|
11
|
-
longitude: number;
|
|
12
|
-
name: string;
|
|
13
|
-
number: string;
|
|
14
|
-
state: string;
|
|
15
|
-
street: string;
|
|
16
|
-
}
|
|
17
|
-
interface PlaceResult {
|
|
18
|
-
formatted_address?: string;
|
|
19
|
-
name?: string;
|
|
20
|
-
geometry?: {
|
|
21
|
-
location: {
|
|
22
|
-
lat: () => number;
|
|
23
|
-
lng: () => number;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
address_components?: AddressComponent[];
|
|
27
|
-
}
|
|
28
|
-
interface AddressComponent {
|
|
29
|
-
short_name: string;
|
|
30
|
-
types: string[];
|
|
31
|
-
}
|
|
32
|
-
declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
33
|
-
mode: {
|
|
34
|
-
type: PropType<PlaceTypes>;
|
|
35
|
-
default: string;
|
|
36
|
-
};
|
|
37
|
-
countries: {
|
|
38
|
-
type: PropType<string[]>;
|
|
39
|
-
default: () => never[];
|
|
40
|
-
};
|
|
41
|
-
placeholder: {
|
|
42
|
-
type: StringConstructor;
|
|
43
|
-
default: string;
|
|
44
|
-
};
|
|
45
|
-
disabled: {
|
|
46
|
-
type: BooleanConstructor;
|
|
47
|
-
default: boolean;
|
|
48
|
-
};
|
|
49
|
-
modelValue: {
|
|
50
|
-
type: PropType<string>;
|
|
51
|
-
};
|
|
52
|
-
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
53
|
-
"update:modelValue": (value: string) => any;
|
|
54
|
-
} & {
|
|
55
|
-
error: (place: PlaceResult) => any;
|
|
56
|
-
search: (args: Address) => any;
|
|
57
|
-
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
58
|
-
mode: {
|
|
59
|
-
type: PropType<PlaceTypes>;
|
|
60
|
-
default: string;
|
|
61
|
-
};
|
|
62
|
-
countries: {
|
|
63
|
-
type: PropType<string[]>;
|
|
64
|
-
default: () => never[];
|
|
65
|
-
};
|
|
66
|
-
placeholder: {
|
|
67
|
-
type: StringConstructor;
|
|
68
|
-
default: string;
|
|
69
|
-
};
|
|
70
|
-
disabled: {
|
|
71
|
-
type: BooleanConstructor;
|
|
72
|
-
default: boolean;
|
|
73
|
-
};
|
|
74
|
-
modelValue: {
|
|
75
|
-
type: PropType<string>;
|
|
76
|
-
};
|
|
77
|
-
}>> & Readonly<{
|
|
78
|
-
onError?: ((place: PlaceResult) => any) | undefined;
|
|
79
|
-
onSearch?: ((args: Address) => any) | undefined;
|
|
80
|
-
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
81
|
-
}>, {
|
|
82
|
-
mode: PlaceTypes;
|
|
83
|
-
disabled: boolean;
|
|
84
|
-
placeholder: string;
|
|
85
|
-
countries: string[];
|
|
86
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
87
|
-
declare const _default: typeof __VLS_export;
|
|
88
|
-
export default _default;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
-
declare const _default: typeof __VLS_export;
|
|
3
|
-
export default _default;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
-
declare const _default: typeof __VLS_export;
|
|
3
|
-
export default _default;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Address } from '../input/InputAddress.vue.js';
|
|
2
|
-
type __VLS_Props = {
|
|
3
|
-
address: Address;
|
|
4
|
-
};
|
|
5
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
6
|
-
"update:address": (value: Address) => any;
|
|
7
|
-
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
8
|
-
"onUpdate:address"?: ((value: Address) => any) | undefined;
|
|
9
|
-
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
-
declare const _default: typeof __VLS_export;
|
|
11
|
-
export default _default;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { reactive, watch } from "vue";
|
|
3
|
-
import { BFormGroup, BFormInput, BRow, BCol } from "bootstrap-vue-next";
|
|
4
|
-
const props = defineProps({
|
|
5
|
-
address: { type: Object, required: true }
|
|
6
|
-
});
|
|
7
|
-
const emit = defineEmits(["update:address"]);
|
|
8
|
-
const form = reactive({ ...props.address });
|
|
9
|
-
watch(form, (value) => emit("update:address", { ...value }), { deep: true });
|
|
10
|
-
</script>
|
|
11
|
-
|
|
12
|
-
<template>
|
|
13
|
-
<BRow class="g-3">
|
|
14
|
-
<BCol cols="12">
|
|
15
|
-
<BFormGroup label="Address line 1" label-for="line1">
|
|
16
|
-
<BFormInput id="line1" v-model="form.line1" />
|
|
17
|
-
</BFormGroup>
|
|
18
|
-
</BCol>
|
|
19
|
-
|
|
20
|
-
<BCol cols="12">
|
|
21
|
-
<BFormGroup label="Address line 2 (Apt, Suite, etc.)" label-for="line2">
|
|
22
|
-
<BFormInput id="line2" v-model="form.line2" />
|
|
23
|
-
</BFormGroup>
|
|
24
|
-
</BCol>
|
|
25
|
-
|
|
26
|
-
<BCol cols="6">
|
|
27
|
-
<BFormGroup label="City" label-for="city">
|
|
28
|
-
<BFormInput id="city" v-model="form.city" />
|
|
29
|
-
</BFormGroup>
|
|
30
|
-
</BCol>
|
|
31
|
-
|
|
32
|
-
<BCol cols="6">
|
|
33
|
-
<BFormGroup label="Locality" label-for="locality">
|
|
34
|
-
<BFormInput id="locality" v-model="form.locality" />
|
|
35
|
-
</BFormGroup>
|
|
36
|
-
</BCol>
|
|
37
|
-
|
|
38
|
-
<BCol cols="6">
|
|
39
|
-
<BFormGroup label="State/Province" label-for="state">
|
|
40
|
-
<BFormInput id="state" v-model="form.state" />
|
|
41
|
-
</BFormGroup>
|
|
42
|
-
</BCol>
|
|
43
|
-
|
|
44
|
-
<BCol cols="6">
|
|
45
|
-
<BFormGroup label="Postal code" label-for="code">
|
|
46
|
-
<BFormInput id="code" v-model="form.code" />
|
|
47
|
-
</BFormGroup>
|
|
48
|
-
</BCol>
|
|
49
|
-
|
|
50
|
-
<BCol cols="12">
|
|
51
|
-
<BFormGroup label="Country" label-for="country">
|
|
52
|
-
<BFormInput id="country" v-model="form.country" />
|
|
53
|
-
</BFormGroup>
|
|
54
|
-
</BCol>
|
|
55
|
-
</BRow>
|
|
56
|
-
</template>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Address } from '../input/InputAddress.vue.js';
|
|
2
|
-
type __VLS_Props = {
|
|
3
|
-
address: Address;
|
|
4
|
-
};
|
|
5
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
6
|
-
"update:address": (value: Address) => any;
|
|
7
|
-
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
8
|
-
"onUpdate:address"?: ((value: Address) => any) | undefined;
|
|
9
|
-
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
-
declare const _default: typeof __VLS_export;
|
|
11
|
-
export default _default;
|