@metamask-previews/geolocation-controller 0.1.0-preview-0aca970c8
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 +14 -0
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/GeolocationController-method-action-types.cjs +7 -0
- package/dist/GeolocationController-method-action-types.cjs.map +1 -0
- package/dist/GeolocationController-method-action-types.d.cts +30 -0
- package/dist/GeolocationController-method-action-types.d.cts.map +1 -0
- package/dist/GeolocationController-method-action-types.d.mts +30 -0
- package/dist/GeolocationController-method-action-types.d.mts.map +1 -0
- package/dist/GeolocationController-method-action-types.mjs +6 -0
- package/dist/GeolocationController-method-action-types.mjs.map +1 -0
- package/dist/GeolocationController.cjs +154 -0
- package/dist/GeolocationController.cjs.map +1 -0
- package/dist/GeolocationController.d.cts +112 -0
- package/dist/GeolocationController.d.cts.map +1 -0
- package/dist/GeolocationController.d.mts +112 -0
- package/dist/GeolocationController.d.mts.map +1 -0
- package/dist/GeolocationController.mjs +149 -0
- package/dist/GeolocationController.mjs.map +1 -0
- package/dist/geolocation-api-service/geolocation-api-service-method-action-types.cjs +7 -0
- package/dist/geolocation-api-service/geolocation-api-service-method-action-types.cjs.map +1 -0
- package/dist/geolocation-api-service/geolocation-api-service-method-action-types.d.cts +25 -0
- package/dist/geolocation-api-service/geolocation-api-service-method-action-types.d.cts.map +1 -0
- package/dist/geolocation-api-service/geolocation-api-service-method-action-types.d.mts +25 -0
- package/dist/geolocation-api-service/geolocation-api-service-method-action-types.d.mts.map +1 -0
- package/dist/geolocation-api-service/geolocation-api-service-method-action-types.mjs +6 -0
- package/dist/geolocation-api-service/geolocation-api-service-method-action-types.mjs.map +1 -0
- package/dist/geolocation-api-service/geolocation-api-service.cjs +186 -0
- package/dist/geolocation-api-service/geolocation-api-service.cjs.map +1 -0
- package/dist/geolocation-api-service/geolocation-api-service.d.cts +127 -0
- package/dist/geolocation-api-service/geolocation-api-service.d.cts.map +1 -0
- package/dist/geolocation-api-service/geolocation-api-service.d.mts +127 -0
- package/dist/geolocation-api-service/geolocation-api-service.d.mts.map +1 -0
- package/dist/geolocation-api-service/geolocation-api-service.mjs +182 -0
- package/dist/geolocation-api-service/geolocation-api-service.mjs.map +1 -0
- package/dist/index.cjs +12 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +13 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +13 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +13 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +10 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _GeolocationController_instances, _GeolocationController_fetchAndUpdate;
|
|
7
|
+
import { BaseController } from "@metamask/base-controller";
|
|
8
|
+
import { UNKNOWN_LOCATION } from "./geolocation-api-service/geolocation-api-service.mjs";
|
|
9
|
+
/**
|
|
10
|
+
* The name of the {@link GeolocationController}, used to namespace the
|
|
11
|
+
* controller's actions and events and to namespace the controller's state data
|
|
12
|
+
* when composed with other controllers.
|
|
13
|
+
*/
|
|
14
|
+
export const controllerName = 'GeolocationController';
|
|
15
|
+
/**
|
|
16
|
+
* The metadata for each property in {@link GeolocationControllerState}.
|
|
17
|
+
*/
|
|
18
|
+
const geolocationControllerMetadata = {
|
|
19
|
+
location: {
|
|
20
|
+
persist: false,
|
|
21
|
+
includeInDebugSnapshot: true,
|
|
22
|
+
includeInStateLogs: true,
|
|
23
|
+
usedInUi: true,
|
|
24
|
+
},
|
|
25
|
+
status: {
|
|
26
|
+
persist: false,
|
|
27
|
+
includeInDebugSnapshot: true,
|
|
28
|
+
includeInStateLogs: true,
|
|
29
|
+
usedInUi: true,
|
|
30
|
+
},
|
|
31
|
+
lastFetchedAt: {
|
|
32
|
+
persist: false,
|
|
33
|
+
includeInDebugSnapshot: true,
|
|
34
|
+
includeInStateLogs: true,
|
|
35
|
+
usedInUi: false,
|
|
36
|
+
},
|
|
37
|
+
error: {
|
|
38
|
+
persist: false,
|
|
39
|
+
includeInDebugSnapshot: true,
|
|
40
|
+
includeInStateLogs: true,
|
|
41
|
+
usedInUi: false,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Constructs the default {@link GeolocationController} state. This allows
|
|
46
|
+
* consumers to provide a partial state object when initializing the controller
|
|
47
|
+
* and also helps in constructing complete state objects for this controller in
|
|
48
|
+
* tests.
|
|
49
|
+
*
|
|
50
|
+
* @returns The default {@link GeolocationController} state.
|
|
51
|
+
*/
|
|
52
|
+
export function getDefaultGeolocationControllerState() {
|
|
53
|
+
return {
|
|
54
|
+
location: UNKNOWN_LOCATION,
|
|
55
|
+
status: 'idle',
|
|
56
|
+
lastFetchedAt: null,
|
|
57
|
+
error: null,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
61
|
+
'getGeolocation',
|
|
62
|
+
'refreshGeolocation',
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* GeolocationController manages UI-facing geolocation state by delegating
|
|
66
|
+
* the actual API interaction to {@link GeolocationApiService} via the
|
|
67
|
+
* messenger.
|
|
68
|
+
*
|
|
69
|
+
* The service (registered externally as
|
|
70
|
+
* `GeolocationApiService:fetchGeolocation`) handles HTTP requests, response
|
|
71
|
+
* validation, TTL caching, and promise deduplication. This controller focuses
|
|
72
|
+
* on state lifecycle (`idle` -> `loading` -> `complete` | `error`) and
|
|
73
|
+
* exposes `getGeolocation` / `refreshGeolocation` as messenger actions.
|
|
74
|
+
*/
|
|
75
|
+
export class GeolocationController extends BaseController {
|
|
76
|
+
/**
|
|
77
|
+
* Constructs a new {@link GeolocationController}.
|
|
78
|
+
*
|
|
79
|
+
* @param args - The arguments to this controller.
|
|
80
|
+
* @param args.messenger - The messenger suited for this controller. Must
|
|
81
|
+
* have a `GeolocationApiService:fetchGeolocation` action handler registered.
|
|
82
|
+
* @param args.state - Optional partial initial state.
|
|
83
|
+
*/
|
|
84
|
+
constructor({ messenger, state }) {
|
|
85
|
+
super({
|
|
86
|
+
messenger,
|
|
87
|
+
metadata: geolocationControllerMetadata,
|
|
88
|
+
name: controllerName,
|
|
89
|
+
state: { ...getDefaultGeolocationControllerState(), ...state },
|
|
90
|
+
});
|
|
91
|
+
_GeolocationController_instances.add(this);
|
|
92
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns the geolocation country code. Delegates to the
|
|
96
|
+
* {@link GeolocationApiService} for network fetching and caching, then
|
|
97
|
+
* updates controller state with the result.
|
|
98
|
+
*
|
|
99
|
+
* @returns The ISO country code string.
|
|
100
|
+
*/
|
|
101
|
+
async getGeolocation() {
|
|
102
|
+
return __classPrivateFieldGet(this, _GeolocationController_instances, "m", _GeolocationController_fetchAndUpdate).call(this);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Forces a fresh geolocation fetch, bypassing the service's cache.
|
|
106
|
+
*
|
|
107
|
+
* @returns The ISO country code string.
|
|
108
|
+
*/
|
|
109
|
+
async refreshGeolocation() {
|
|
110
|
+
this.update((draft) => {
|
|
111
|
+
draft.lastFetchedAt = null;
|
|
112
|
+
});
|
|
113
|
+
return __classPrivateFieldGet(this, _GeolocationController_instances, "m", _GeolocationController_fetchAndUpdate).call(this, { bypassCache: true });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
_GeolocationController_instances = new WeakSet(), _GeolocationController_fetchAndUpdate =
|
|
117
|
+
/**
|
|
118
|
+
* Calls the geolocation service and updates controller state with the
|
|
119
|
+
* result.
|
|
120
|
+
*
|
|
121
|
+
* @param options - Options forwarded to the service.
|
|
122
|
+
* @param options.bypassCache - When true, the service skips its TTL cache.
|
|
123
|
+
* @returns The ISO country code string.
|
|
124
|
+
*/
|
|
125
|
+
async function _GeolocationController_fetchAndUpdate(options) {
|
|
126
|
+
this.update((draft) => {
|
|
127
|
+
draft.status = 'loading';
|
|
128
|
+
draft.error = null;
|
|
129
|
+
});
|
|
130
|
+
try {
|
|
131
|
+
const location = await this.messenger.call('GeolocationApiService:fetchGeolocation', options);
|
|
132
|
+
this.update((draft) => {
|
|
133
|
+
draft.location = location;
|
|
134
|
+
draft.status = 'complete';
|
|
135
|
+
draft.lastFetchedAt = Date.now();
|
|
136
|
+
draft.error = null;
|
|
137
|
+
});
|
|
138
|
+
return location;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
142
|
+
this.update((draft) => {
|
|
143
|
+
draft.status = 'error';
|
|
144
|
+
draft.error = message;
|
|
145
|
+
});
|
|
146
|
+
return this.state.location;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=GeolocationController.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeolocationController.mjs","sourceRoot":"","sources":["../src/GeolocationController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,8DAA0D;AAKrF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAu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,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC;QACxB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { UNKNOWN_LOCATION } from './geolocation-api-service/geolocation-api-service';\nimport type { GeolocationApiServiceFetchGeolocationAction } from './geolocation-api-service/geolocation-api-service-method-action-types';\nimport type { GeolocationControllerMethodActions } from './GeolocationController-method-action-types';\nimport type { GeolocationRequestStatus } from './types';\n\n/**\n * The name of the {@link GeolocationController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'GeolocationController';\n\n/**\n * State for the {@link GeolocationController}.\n */\nexport type GeolocationControllerState = {\n /** ISO 3166-1 alpha-2 country code, or \"UNKNOWN\" if not yet determined. */\n location: string;\n /** Current status of the geolocation fetch lifecycle. */\n status: GeolocationRequestStatus;\n /** Epoch milliseconds of the last successful fetch, or null if never fetched. */\n lastFetchedAt: number | null;\n /** Last error message, or null if no error has occurred. */\n error: string | null;\n};\n\n/**\n * The metadata for each property in {@link GeolocationControllerState}.\n */\nconst geolocationControllerMetadata = {\n location: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n status: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n lastFetchedAt: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: false,\n },\n error: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<GeolocationControllerState>;\n\n/**\n * Constructs the default {@link GeolocationController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link GeolocationController} state.\n */\nexport function getDefaultGeolocationControllerState(): GeolocationControllerState {\n return {\n location: UNKNOWN_LOCATION,\n status: 'idle',\n lastFetchedAt: null,\n error: null,\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getGeolocation',\n 'refreshGeolocation',\n] as const;\n\n/**\n * Retrieves the state of the {@link GeolocationController}.\n */\nexport type GeolocationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GeolocationControllerState\n>;\n\n/**\n * Actions that {@link GeolocationControllerMessenger} exposes to other consumers.\n */\nexport type GeolocationControllerActions =\n | GeolocationControllerGetStateAction\n | GeolocationControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link GeolocationControllerMessenger} calls.\n */\ntype AllowedActions = GeolocationApiServiceFetchGeolocationAction;\n\n/**\n * Published when the state of {@link GeolocationController} changes.\n */\nexport type GeolocationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n GeolocationControllerState\n>;\n\n/**\n * Events that {@link GeolocationControllerMessenger} exposes to other consumers.\n */\nexport type GeolocationControllerEvents = GeolocationControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link GeolocationControllerMessenger}\n * subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link GeolocationController}.\n */\nexport type GeolocationControllerMessenger = Messenger<\n typeof controllerName,\n GeolocationControllerActions | AllowedActions,\n GeolocationControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing the {@link GeolocationController}.\n */\nexport type GeolocationControllerOptions = {\n /** The messenger for inter-controller communication. */\n messenger: GeolocationControllerMessenger;\n /** Optional partial initial state. */\n state?: Partial<GeolocationControllerState>;\n};\n\n/**\n * GeolocationController manages UI-facing geolocation state by delegating\n * the actual API interaction to {@link GeolocationApiService} via the\n * messenger.\n *\n * The service (registered externally as\n * `GeolocationApiService:fetchGeolocation`) handles HTTP requests, response\n * validation, TTL caching, and promise deduplication. This controller focuses\n * on state lifecycle (`idle` -> `loading` -> `complete` | `error`) and\n * exposes `getGeolocation` / `refreshGeolocation` as messenger actions.\n */\nexport class GeolocationController extends BaseController<\n typeof controllerName,\n GeolocationControllerState,\n GeolocationControllerMessenger\n> {\n /**\n * Constructs a new {@link GeolocationController}.\n *\n * @param args - The arguments to this controller.\n * @param args.messenger - The messenger suited for this controller. Must\n * have a `GeolocationApiService:fetchGeolocation` action handler registered.\n * @param args.state - Optional partial initial state.\n */\n constructor({ messenger, state }: GeolocationControllerOptions) {\n super({\n messenger,\n metadata: geolocationControllerMetadata,\n name: controllerName,\n state: { ...getDefaultGeolocationControllerState(), ...state },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Returns the geolocation country code. Delegates to the\n * {@link GeolocationApiService} for network fetching and caching, then\n * updates controller state with the result.\n *\n * @returns The ISO country code string.\n */\n async getGeolocation(): Promise<string> {\n return this.#fetchAndUpdate();\n }\n\n /**\n * Forces a fresh geolocation fetch, bypassing the service's cache.\n *\n * @returns The ISO country code string.\n */\n async refreshGeolocation(): Promise<string> {\n this.update((draft) => {\n draft.lastFetchedAt = null;\n });\n return this.#fetchAndUpdate({ bypassCache: true });\n }\n\n /**\n * Calls the geolocation service and updates controller state with the\n * result.\n *\n * @param options - Options forwarded to the service.\n * @param options.bypassCache - When true, the service skips its TTL cache.\n * @returns The ISO country code string.\n */\n async #fetchAndUpdate(options?: { bypassCache?: boolean }): Promise<string> {\n this.update((draft) => {\n draft.status = 'loading';\n draft.error = null;\n });\n\n try {\n const location = await this.messenger.call(\n 'GeolocationApiService:fetchGeolocation',\n options,\n );\n\n this.update((draft) => {\n draft.location = location;\n draft.status = 'complete';\n draft.lastFetchedAt = Date.now();\n draft.error = null;\n });\n\n return location;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n\n this.update((draft) => {\n draft.status = 'error';\n draft.error = message;\n });\n\n return this.state.location;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
4
|
+
* Do not edit manually.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=geolocation-api-service-method-action-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation-api-service-method-action-types.cjs","sourceRoot":"","sources":["../../src/geolocation-api-service/geolocation-api-service-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { GeolocationApiService } from './geolocation-api-service';\n\n/**\n * Returns the geolocation country code. Serves from cache when the TTL has\n * not expired, otherwise performs a network fetch. Concurrent callers are\n * deduplicated to a single in-flight request.\n *\n * @param options - Optional fetch options.\n * @param options.bypassCache - When true, invalidates the cache and forces a\n * fresh network request.\n * @returns The ISO 3166-1 alpha-2 country code, or `UNKNOWN_LOCATION`\n * when the API returns an empty or invalid body.\n */\nexport type GeolocationApiServiceFetchGeolocationAction = {\n type: `GeolocationApiService:fetchGeolocation`;\n handler: GeolocationApiService['fetchGeolocation'];\n};\n\n/**\n * Union of all GeolocationApiService action types.\n */\nexport type GeolocationApiServiceMethodActions =\n GeolocationApiServiceFetchGeolocationAction;\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { GeolocationApiService } from "./geolocation-api-service.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Returns the geolocation country code. Serves from cache when the TTL has
|
|
8
|
+
* not expired, otherwise performs a network fetch. Concurrent callers are
|
|
9
|
+
* deduplicated to a single in-flight request.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Optional fetch options.
|
|
12
|
+
* @param options.bypassCache - When true, invalidates the cache and forces a
|
|
13
|
+
* fresh network request.
|
|
14
|
+
* @returns The ISO 3166-1 alpha-2 country code, or `UNKNOWN_LOCATION`
|
|
15
|
+
* when the API returns an empty or invalid body.
|
|
16
|
+
*/
|
|
17
|
+
export type GeolocationApiServiceFetchGeolocationAction = {
|
|
18
|
+
type: `GeolocationApiService:fetchGeolocation`;
|
|
19
|
+
handler: GeolocationApiService['fetchGeolocation'];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Union of all GeolocationApiService action types.
|
|
23
|
+
*/
|
|
24
|
+
export type GeolocationApiServiceMethodActions = GeolocationApiServiceFetchGeolocationAction;
|
|
25
|
+
//# sourceMappingURL=geolocation-api-service-method-action-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation-api-service-method-action-types.d.cts","sourceRoot":"","sources":["../../src/geolocation-api-service/geolocation-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAkC;AAEvE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CACpD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAC5C,2CAA2C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { GeolocationApiService } from "./geolocation-api-service.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Returns the geolocation country code. Serves from cache when the TTL has
|
|
8
|
+
* not expired, otherwise performs a network fetch. Concurrent callers are
|
|
9
|
+
* deduplicated to a single in-flight request.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Optional fetch options.
|
|
12
|
+
* @param options.bypassCache - When true, invalidates the cache and forces a
|
|
13
|
+
* fresh network request.
|
|
14
|
+
* @returns The ISO 3166-1 alpha-2 country code, or `UNKNOWN_LOCATION`
|
|
15
|
+
* when the API returns an empty or invalid body.
|
|
16
|
+
*/
|
|
17
|
+
export type GeolocationApiServiceFetchGeolocationAction = {
|
|
18
|
+
type: `GeolocationApiService:fetchGeolocation`;
|
|
19
|
+
handler: GeolocationApiService['fetchGeolocation'];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Union of all GeolocationApiService action types.
|
|
23
|
+
*/
|
|
24
|
+
export type GeolocationApiServiceMethodActions = GeolocationApiServiceFetchGeolocationAction;
|
|
25
|
+
//# sourceMappingURL=geolocation-api-service-method-action-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation-api-service-method-action-types.d.mts","sourceRoot":"","sources":["../../src/geolocation-api-service/geolocation-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAkC;AAEvE;;;;;;;;;;GAUG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;CACpD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAC5C,2CAA2C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation-api-service-method-action-types.mjs","sourceRoot":"","sources":["../../src/geolocation-api-service/geolocation-api-service-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { GeolocationApiService } from './geolocation-api-service';\n\n/**\n * Returns the geolocation country code. Serves from cache when the TTL has\n * not expired, otherwise performs a network fetch. Concurrent callers are\n * deduplicated to a single in-flight request.\n *\n * @param options - Optional fetch options.\n * @param options.bypassCache - When true, invalidates the cache and forces a\n * fresh network request.\n * @returns The ISO 3166-1 alpha-2 country code, or `UNKNOWN_LOCATION`\n * when the API returns an empty or invalid body.\n */\nexport type GeolocationApiServiceFetchGeolocationAction = {\n type: `GeolocationApiService:fetchGeolocation`;\n handler: GeolocationApiService['fetchGeolocation'];\n};\n\n/**\n * Union of all GeolocationApiService action types.\n */\nexport type GeolocationApiServiceMethodActions =\n GeolocationApiServiceFetchGeolocationAction;\n"]}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _GeolocationApiService_instances, _GeolocationApiService_messenger, _GeolocationApiService_fetch, _GeolocationApiService_url, _GeolocationApiService_ttlMs, _GeolocationApiService_policy, _GeolocationApiService_cachedLocation, _GeolocationApiService_lastFetchedAt, _GeolocationApiService_fetchPromise, _GeolocationApiService_isCacheValid, _GeolocationApiService_performFetch;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GeolocationApiService = exports.UNKNOWN_LOCATION = exports.serviceName = void 0;
|
|
16
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
17
|
+
const types_1 = require("../types.cjs");
|
|
18
|
+
const DEFAULT_TTL_MS = 5 * 60 * 1000;
|
|
19
|
+
const ENDPOINT_PATH = '/geolocation';
|
|
20
|
+
// === GENERAL ===
|
|
21
|
+
/**
|
|
22
|
+
* The name of the {@link GeolocationApiService}, used to namespace the
|
|
23
|
+
* service's actions and events.
|
|
24
|
+
*/
|
|
25
|
+
exports.serviceName = 'GeolocationApiService';
|
|
26
|
+
/**
|
|
27
|
+
* Sentinel value used when the geolocation has not been determined yet or when
|
|
28
|
+
* the API returns an empty / invalid response.
|
|
29
|
+
*/
|
|
30
|
+
exports.UNKNOWN_LOCATION = 'UNKNOWN';
|
|
31
|
+
// === MESSENGER ===
|
|
32
|
+
const MESSENGER_EXPOSED_METHODS = ['fetchGeolocation'];
|
|
33
|
+
// === SERVICE DEFINITION ===
|
|
34
|
+
/**
|
|
35
|
+
* Returns the base URL for the geolocation API for the given environment.
|
|
36
|
+
*
|
|
37
|
+
* @param env - The environment to get the URL for.
|
|
38
|
+
* @returns The full URL for the geolocation endpoint.
|
|
39
|
+
*/
|
|
40
|
+
function getGeolocationUrl(env) {
|
|
41
|
+
const envPrefix = env === types_1.Env.PRD ? '' : `${env}-`;
|
|
42
|
+
return `https://on-ramp.${envPrefix}api.cx.metamask.io${ENDPOINT_PATH}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Low-level data service that fetches a country code from the geolocation API.
|
|
46
|
+
*
|
|
47
|
+
* Responsibilities:
|
|
48
|
+
* - HTTP request to the geolocation endpoint (wrapped in a service policy)
|
|
49
|
+
* - ISO 3166-1 alpha-2 response validation
|
|
50
|
+
* - TTL-based in-memory cache
|
|
51
|
+
* - Promise deduplication (concurrent callers share a single in-flight request)
|
|
52
|
+
*
|
|
53
|
+
* This class is intentionally not a controller: it does not manage UI state.
|
|
54
|
+
* Its {@link fetchGeolocation} method is automatically registered on the
|
|
55
|
+
* messenger so that controllers and other packages can call it directly.
|
|
56
|
+
*/
|
|
57
|
+
class GeolocationApiService {
|
|
58
|
+
/**
|
|
59
|
+
* Constructs a new {@link GeolocationApiService}.
|
|
60
|
+
*
|
|
61
|
+
* @param args - The constructor arguments.
|
|
62
|
+
* @param args.messenger - The messenger suited for this service.
|
|
63
|
+
* @param args.env - The environment to determine the correct API endpoint.
|
|
64
|
+
* Defaults to PRD.
|
|
65
|
+
* @param args.fetch - A function that can be used to make an HTTP request.
|
|
66
|
+
* Defaults to the global fetch.
|
|
67
|
+
* @param args.ttlMs - Cache TTL in milliseconds. Defaults to 5 minutes.
|
|
68
|
+
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
69
|
+
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
70
|
+
*/
|
|
71
|
+
constructor({ messenger, env = types_1.Env.PRD, fetch: fetchFunction = globalThis.fetch, ttlMs, policyOptions = {}, }) {
|
|
72
|
+
_GeolocationApiService_instances.add(this);
|
|
73
|
+
_GeolocationApiService_messenger.set(this, void 0);
|
|
74
|
+
_GeolocationApiService_fetch.set(this, void 0);
|
|
75
|
+
_GeolocationApiService_url.set(this, void 0);
|
|
76
|
+
_GeolocationApiService_ttlMs.set(this, void 0);
|
|
77
|
+
/**
|
|
78
|
+
* The policy that wraps each HTTP request.
|
|
79
|
+
*
|
|
80
|
+
* @see {@link createServicePolicy}
|
|
81
|
+
*/
|
|
82
|
+
_GeolocationApiService_policy.set(this, void 0);
|
|
83
|
+
_GeolocationApiService_cachedLocation.set(this, exports.UNKNOWN_LOCATION);
|
|
84
|
+
_GeolocationApiService_lastFetchedAt.set(this, null);
|
|
85
|
+
_GeolocationApiService_fetchPromise.set(this, null);
|
|
86
|
+
this.name = exports.serviceName;
|
|
87
|
+
__classPrivateFieldSet(this, _GeolocationApiService_messenger, messenger, "f");
|
|
88
|
+
__classPrivateFieldSet(this, _GeolocationApiService_url, getGeolocationUrl(env), "f");
|
|
89
|
+
__classPrivateFieldSet(this, _GeolocationApiService_fetch, fetchFunction, "f");
|
|
90
|
+
__classPrivateFieldSet(this, _GeolocationApiService_ttlMs, ttlMs ?? DEFAULT_TTL_MS, "f");
|
|
91
|
+
__classPrivateFieldSet(this, _GeolocationApiService_policy, (0, controller_utils_1.createServicePolicy)(policyOptions), "f");
|
|
92
|
+
__classPrivateFieldGet(this, _GeolocationApiService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Registers a handler that will be called after a request returns a 5xx
|
|
96
|
+
* response, causing a retry.
|
|
97
|
+
*
|
|
98
|
+
* @param listener - The handler to be called.
|
|
99
|
+
* @returns An object that can be used to unregister the handler.
|
|
100
|
+
* @see {@link createServicePolicy}
|
|
101
|
+
*/
|
|
102
|
+
onRetry(listener) {
|
|
103
|
+
return __classPrivateFieldGet(this, _GeolocationApiService_policy, "f").onRetry(listener);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Registers a handler that will be called after a set number of retry rounds
|
|
107
|
+
* prove that requests to the API endpoint consistently return a 5xx response.
|
|
108
|
+
*
|
|
109
|
+
* @param listener - The handler to be called.
|
|
110
|
+
* @returns An object that can be used to unregister the handler.
|
|
111
|
+
* @see {@link createServicePolicy}
|
|
112
|
+
*/
|
|
113
|
+
onBreak(listener) {
|
|
114
|
+
return __classPrivateFieldGet(this, _GeolocationApiService_policy, "f").onBreak(listener);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Registers a handler that will be called when requests are consistently
|
|
118
|
+
* failing or when a successful request takes longer than the degraded
|
|
119
|
+
* threshold.
|
|
120
|
+
*
|
|
121
|
+
* @param listener - The handler to be called.
|
|
122
|
+
* @returns An object that can be used to unregister the handler.
|
|
123
|
+
*/
|
|
124
|
+
onDegraded(listener) {
|
|
125
|
+
return __classPrivateFieldGet(this, _GeolocationApiService_policy, "f").onDegraded(listener);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns the geolocation country code. Serves from cache when the TTL has
|
|
129
|
+
* not expired, otherwise performs a network fetch. Concurrent callers are
|
|
130
|
+
* deduplicated to a single in-flight request.
|
|
131
|
+
*
|
|
132
|
+
* @param options - Optional fetch options.
|
|
133
|
+
* @param options.bypassCache - When true, invalidates the TTL cache. If a
|
|
134
|
+
* request is already in-flight it will be reused (deduplication always
|
|
135
|
+
* applies).
|
|
136
|
+
* @returns The ISO 3166-1 alpha-2 country code, or {@link UNKNOWN_LOCATION}
|
|
137
|
+
* when the API returns an empty or invalid body.
|
|
138
|
+
*/
|
|
139
|
+
async fetchGeolocation(options) {
|
|
140
|
+
if (options?.bypassCache) {
|
|
141
|
+
__classPrivateFieldSet(this, _GeolocationApiService_lastFetchedAt, null, "f");
|
|
142
|
+
}
|
|
143
|
+
if (__classPrivateFieldGet(this, _GeolocationApiService_instances, "m", _GeolocationApiService_isCacheValid).call(this)) {
|
|
144
|
+
return __classPrivateFieldGet(this, _GeolocationApiService_cachedLocation, "f");
|
|
145
|
+
}
|
|
146
|
+
if (__classPrivateFieldGet(this, _GeolocationApiService_fetchPromise, "f")) {
|
|
147
|
+
return __classPrivateFieldGet(this, _GeolocationApiService_fetchPromise, "f");
|
|
148
|
+
}
|
|
149
|
+
const promise = __classPrivateFieldGet(this, _GeolocationApiService_instances, "m", _GeolocationApiService_performFetch).call(this);
|
|
150
|
+
__classPrivateFieldSet(this, _GeolocationApiService_fetchPromise, promise, "f");
|
|
151
|
+
try {
|
|
152
|
+
return await promise;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
__classPrivateFieldSet(this, _GeolocationApiService_fetchPromise, null, "f");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.GeolocationApiService = GeolocationApiService;
|
|
160
|
+
_GeolocationApiService_messenger = new WeakMap(), _GeolocationApiService_fetch = new WeakMap(), _GeolocationApiService_url = new WeakMap(), _GeolocationApiService_ttlMs = new WeakMap(), _GeolocationApiService_policy = new WeakMap(), _GeolocationApiService_cachedLocation = new WeakMap(), _GeolocationApiService_lastFetchedAt = new WeakMap(), _GeolocationApiService_fetchPromise = new WeakMap(), _GeolocationApiService_instances = new WeakSet(), _GeolocationApiService_isCacheValid = function _GeolocationApiService_isCacheValid() {
|
|
161
|
+
return (__classPrivateFieldGet(this, _GeolocationApiService_lastFetchedAt, "f") !== null &&
|
|
162
|
+
Date.now() - __classPrivateFieldGet(this, _GeolocationApiService_lastFetchedAt, "f") < __classPrivateFieldGet(this, _GeolocationApiService_ttlMs, "f"));
|
|
163
|
+
}, _GeolocationApiService_performFetch =
|
|
164
|
+
/**
|
|
165
|
+
* Performs the actual HTTP fetch, wrapped in the service policy for automatic
|
|
166
|
+
* retry and circuit-breaking, and validates the response.
|
|
167
|
+
*
|
|
168
|
+
* @returns The ISO country code string.
|
|
169
|
+
*/
|
|
170
|
+
async function _GeolocationApiService_performFetch() {
|
|
171
|
+
const response = await __classPrivateFieldGet(this, _GeolocationApiService_policy, "f").execute(async () => {
|
|
172
|
+
const localResponse = await __classPrivateFieldGet(this, _GeolocationApiService_fetch, "f").call(this, __classPrivateFieldGet(this, _GeolocationApiService_url, "f"));
|
|
173
|
+
if (!localResponse.ok) {
|
|
174
|
+
throw new controller_utils_1.HttpError(localResponse.status, `Geolocation fetch failed: ${localResponse.status}`);
|
|
175
|
+
}
|
|
176
|
+
return localResponse;
|
|
177
|
+
});
|
|
178
|
+
const raw = (await response.text()).trim();
|
|
179
|
+
const location = /^[A-Z]{2}$/u.test(raw) ? raw : exports.UNKNOWN_LOCATION;
|
|
180
|
+
if (location !== exports.UNKNOWN_LOCATION) {
|
|
181
|
+
__classPrivateFieldSet(this, _GeolocationApiService_cachedLocation, location, "f");
|
|
182
|
+
__classPrivateFieldSet(this, _GeolocationApiService_lastFetchedAt, Date.now(), "f");
|
|
183
|
+
}
|
|
184
|
+
return location;
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=geolocation-api-service.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation-api-service.cjs","sourceRoot":"","sources":["../../src/geolocation-api-service/geolocation-api-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,iEAA4E;AAK5E,wCAA+B;AAE/B,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAErC,MAAM,aAAa,GAAG,cAAc,CAAC;AAErC,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,uBAAuB,CAAC;AAEnD;;;GAGG;AACU,QAAA,gBAAgB,GAAG,SAAS,CAAC;AAE1C,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,kBAAkB,CAAU,CAAC;AAkChE,6BAA6B;AAE7B;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,GAAQ;IACjC,MAAM,SAAS,GAAG,GAAG,KAAK,WAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;IACnD,OAAO,mBAAmB,SAAS,qBAAqB,aAAa,EAAE,CAAC;AAC1E,CAAC;AAUD;;;;;;;;;;;;GAYG;AACH,MAAa,qBAAqB;IA2BhC;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,SAAS,EACT,GAAG,GAAG,WAAG,CAAC,GAAG,EACb,KAAK,EAAE,aAAa,GAAG,UAAU,CAAC,KAAK,EACvC,KAAK,EACL,aAAa,GAAG,EAAE,GAOnB;;QA9CQ,mDAA2C;QAE3C,+CAAgC;QAEhC,6CAAa;QAEb,+CAAe;QAExB;;;;WAIG;QACM,gDAAuB;QAEhC,gDAA0B,wBAAgB,EAAC;QAE3C,+CAAgC,IAAI,EAAC;QA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AC;AAClB,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { GeolocationApiServiceMethodActions } from './geolocation-api-service-method-action-types';\nimport { Env } from '../types';\n\nconst DEFAULT_TTL_MS = 5 * 60 * 1000;\n\nconst ENDPOINT_PATH = '/geolocation';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link GeolocationApiService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'GeolocationApiService';\n\n/**\n * Sentinel value used when the geolocation has not been determined yet or when\n * the API returns an empty / invalid response.\n */\nexport const UNKNOWN_LOCATION = 'UNKNOWN';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['fetchGeolocation'] as const;\n\n/**\n * Actions that {@link GeolocationApiService} exposes to other consumers.\n */\nexport type GeolocationApiServiceActions = GeolocationApiServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link GeolocationApiServiceMessenger}\n * calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link GeolocationApiService} exposes to other consumers.\n */\nexport type GeolocationApiServiceEvents = never;\n\n/**\n * Events from other messengers that {@link GeolocationApiService} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link GeolocationApiService}.\n */\nexport type GeolocationApiServiceMessenger = Messenger<\n typeof serviceName,\n GeolocationApiServiceActions | AllowedActions,\n GeolocationApiServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Returns the base URL for the geolocation API for the given environment.\n *\n * @param env - The environment to get the URL for.\n * @returns The full URL for the geolocation endpoint.\n */\nfunction getGeolocationUrl(env: Env): string {\n const envPrefix = env === Env.PRD ? '' : `${env}-`;\n return `https://on-ramp.${envPrefix}api.cx.metamask.io${ENDPOINT_PATH}`;\n}\n\n/**\n * Options accepted by {@link GeolocationApiService.fetchGeolocation}.\n */\nexport type FetchGeolocationOptions = {\n /** When true, the TTL cache is invalidated so the next request fetches fresh data. */\n bypassCache?: boolean;\n};\n\n/**\n * Low-level data service that fetches a country code from the geolocation API.\n *\n * Responsibilities:\n * - HTTP request to the geolocation endpoint (wrapped in a service policy)\n * - ISO 3166-1 alpha-2 response validation\n * - TTL-based in-memory cache\n * - Promise deduplication (concurrent callers share a single in-flight request)\n *\n * This class is intentionally not a controller: it does not manage UI state.\n * Its {@link fetchGeolocation} method is automatically registered on the\n * messenger so that controllers and other packages can call it directly.\n */\nexport class GeolocationApiService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n readonly #messenger: GeolocationApiServiceMessenger;\n\n readonly #fetch: typeof globalThis.fetch;\n\n readonly #url: string;\n\n readonly #ttlMs: number;\n\n /**\n * The policy that wraps each HTTP request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n #cachedLocation: string = UNKNOWN_LOCATION;\n\n #lastFetchedAt: number | null = null;\n\n #fetchPromise: Promise<string> | null = null;\n\n /**\n * Constructs a new {@link GeolocationApiService}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.env - The environment to determine the correct API endpoint.\n * Defaults to PRD.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * Defaults to the global fetch.\n * @param args.ttlMs - Cache TTL in milliseconds. Defaults to 5 minutes.\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n env = Env.PRD,\n fetch: fetchFunction = globalThis.fetch,\n ttlMs,\n policyOptions = {},\n }: {\n messenger: GeolocationApiServiceMessenger;\n env?: Env;\n fetch?: typeof fetch;\n ttlMs?: number;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#url = getGeolocationUrl(env);\n this.#fetch = fetchFunction;\n this.#ttlMs = ttlMs ?? DEFAULT_TTL_MS;\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a 5xx\n * response, causing a retry.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable {\n return this.#policy.onBreak(listener);\n }\n\n /**\n * Registers a handler that will be called when requests are consistently\n * failing or when a successful request takes longer than the degraded\n * threshold.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n */\n onDegraded(\n listener: Parameters<ServicePolicy['onDegraded']>[0],\n ): IDisposable {\n return this.#policy.onDegraded(listener);\n }\n\n /**\n * Returns the geolocation country code. Serves from cache when the TTL has\n * not expired, otherwise performs a network fetch. Concurrent callers are\n * deduplicated to a single in-flight request.\n *\n * @param options - Optional fetch options.\n * @param options.bypassCache - When true, invalidates the TTL cache. If a\n * request is already in-flight it will be reused (deduplication always\n * applies).\n * @returns The ISO 3166-1 alpha-2 country code, or {@link UNKNOWN_LOCATION}\n * when the API returns an empty or invalid body.\n */\n async fetchGeolocation(options?: FetchGeolocationOptions): Promise<string> {\n if (options?.bypassCache) {\n this.#lastFetchedAt = null;\n }\n\n if (this.#isCacheValid()) {\n return this.#cachedLocation;\n }\n\n if (this.#fetchPromise) {\n return this.#fetchPromise;\n }\n\n const promise = this.#performFetch();\n this.#fetchPromise = promise;\n\n try {\n return await promise;\n } finally {\n this.#fetchPromise = null;\n }\n }\n\n /**\n * Checks whether the cached geolocation is still within the TTL window.\n *\n * @returns True if the cache is valid.\n */\n #isCacheValid(): boolean {\n return (\n this.#lastFetchedAt !== null &&\n Date.now() - this.#lastFetchedAt < this.#ttlMs\n );\n }\n\n /**\n * Performs the actual HTTP fetch, wrapped in the service policy for automatic\n * retry and circuit-breaking, and validates the response.\n *\n * @returns The ISO country code string.\n */\n async #performFetch(): Promise<string> {\n const response = await this.#policy.execute(async () => {\n const localResponse = await this.#fetch(this.#url);\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Geolocation fetch failed: ${localResponse.status}`,\n );\n }\n return localResponse;\n });\n\n const raw = (await response.text()).trim();\n const location = /^[A-Z]{2}$/u.test(raw) ? raw : UNKNOWN_LOCATION;\n\n if (location !== UNKNOWN_LOCATION) {\n this.#cachedLocation = location;\n this.#lastFetchedAt = Date.now();\n }\n\n return location;\n }\n}\n"]}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { IDisposable } from "cockatiel";
|
|
4
|
+
import type { GeolocationApiServiceMethodActions } from "./geolocation-api-service-method-action-types.cjs";
|
|
5
|
+
import { Env } from "../types.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* The name of the {@link GeolocationApiService}, used to namespace the
|
|
8
|
+
* service's actions and events.
|
|
9
|
+
*/
|
|
10
|
+
export declare const serviceName = "GeolocationApiService";
|
|
11
|
+
/**
|
|
12
|
+
* Sentinel value used when the geolocation has not been determined yet or when
|
|
13
|
+
* the API returns an empty / invalid response.
|
|
14
|
+
*/
|
|
15
|
+
export declare const UNKNOWN_LOCATION = "UNKNOWN";
|
|
16
|
+
/**
|
|
17
|
+
* Actions that {@link GeolocationApiService} exposes to other consumers.
|
|
18
|
+
*/
|
|
19
|
+
export type GeolocationApiServiceActions = GeolocationApiServiceMethodActions;
|
|
20
|
+
/**
|
|
21
|
+
* Actions from other messengers that {@link GeolocationApiServiceMessenger}
|
|
22
|
+
* calls.
|
|
23
|
+
*/
|
|
24
|
+
type AllowedActions = never;
|
|
25
|
+
/**
|
|
26
|
+
* Events that {@link GeolocationApiService} exposes to other consumers.
|
|
27
|
+
*/
|
|
28
|
+
export type GeolocationApiServiceEvents = never;
|
|
29
|
+
/**
|
|
30
|
+
* Events from other messengers that {@link GeolocationApiService} subscribes
|
|
31
|
+
* to.
|
|
32
|
+
*/
|
|
33
|
+
type AllowedEvents = never;
|
|
34
|
+
/**
|
|
35
|
+
* The messenger restricted to actions and events accessed by
|
|
36
|
+
* {@link GeolocationApiService}.
|
|
37
|
+
*/
|
|
38
|
+
export type GeolocationApiServiceMessenger = Messenger<typeof serviceName, GeolocationApiServiceActions | AllowedActions, GeolocationApiServiceEvents | AllowedEvents>;
|
|
39
|
+
/**
|
|
40
|
+
* Options accepted by {@link GeolocationApiService.fetchGeolocation}.
|
|
41
|
+
*/
|
|
42
|
+
export type FetchGeolocationOptions = {
|
|
43
|
+
/** When true, the TTL cache is invalidated so the next request fetches fresh data. */
|
|
44
|
+
bypassCache?: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Low-level data service that fetches a country code from the geolocation API.
|
|
48
|
+
*
|
|
49
|
+
* Responsibilities:
|
|
50
|
+
* - HTTP request to the geolocation endpoint (wrapped in a service policy)
|
|
51
|
+
* - ISO 3166-1 alpha-2 response validation
|
|
52
|
+
* - TTL-based in-memory cache
|
|
53
|
+
* - Promise deduplication (concurrent callers share a single in-flight request)
|
|
54
|
+
*
|
|
55
|
+
* This class is intentionally not a controller: it does not manage UI state.
|
|
56
|
+
* Its {@link fetchGeolocation} method is automatically registered on the
|
|
57
|
+
* messenger so that controllers and other packages can call it directly.
|
|
58
|
+
*/
|
|
59
|
+
export declare class GeolocationApiService {
|
|
60
|
+
#private;
|
|
61
|
+
/**
|
|
62
|
+
* The name of the service.
|
|
63
|
+
*/
|
|
64
|
+
readonly name: typeof serviceName;
|
|
65
|
+
/**
|
|
66
|
+
* Constructs a new {@link GeolocationApiService}.
|
|
67
|
+
*
|
|
68
|
+
* @param args - The constructor arguments.
|
|
69
|
+
* @param args.messenger - The messenger suited for this service.
|
|
70
|
+
* @param args.env - The environment to determine the correct API endpoint.
|
|
71
|
+
* Defaults to PRD.
|
|
72
|
+
* @param args.fetch - A function that can be used to make an HTTP request.
|
|
73
|
+
* Defaults to the global fetch.
|
|
74
|
+
* @param args.ttlMs - Cache TTL in milliseconds. Defaults to 5 minutes.
|
|
75
|
+
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
76
|
+
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
77
|
+
*/
|
|
78
|
+
constructor({ messenger, env, fetch: fetchFunction, ttlMs, policyOptions, }: {
|
|
79
|
+
messenger: GeolocationApiServiceMessenger;
|
|
80
|
+
env?: Env;
|
|
81
|
+
fetch?: typeof fetch;
|
|
82
|
+
ttlMs?: number;
|
|
83
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Registers a handler that will be called after a request returns a 5xx
|
|
87
|
+
* response, causing a retry.
|
|
88
|
+
*
|
|
89
|
+
* @param listener - The handler to be called.
|
|
90
|
+
* @returns An object that can be used to unregister the handler.
|
|
91
|
+
* @see {@link createServicePolicy}
|
|
92
|
+
*/
|
|
93
|
+
onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable;
|
|
94
|
+
/**
|
|
95
|
+
* Registers a handler that will be called after a set number of retry rounds
|
|
96
|
+
* prove that requests to the API endpoint consistently return a 5xx response.
|
|
97
|
+
*
|
|
98
|
+
* @param listener - The handler to be called.
|
|
99
|
+
* @returns An object that can be used to unregister the handler.
|
|
100
|
+
* @see {@link createServicePolicy}
|
|
101
|
+
*/
|
|
102
|
+
onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable;
|
|
103
|
+
/**
|
|
104
|
+
* Registers a handler that will be called when requests are consistently
|
|
105
|
+
* failing or when a successful request takes longer than the degraded
|
|
106
|
+
* threshold.
|
|
107
|
+
*
|
|
108
|
+
* @param listener - The handler to be called.
|
|
109
|
+
* @returns An object that can be used to unregister the handler.
|
|
110
|
+
*/
|
|
111
|
+
onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]): IDisposable;
|
|
112
|
+
/**
|
|
113
|
+
* Returns the geolocation country code. Serves from cache when the TTL has
|
|
114
|
+
* not expired, otherwise performs a network fetch. Concurrent callers are
|
|
115
|
+
* deduplicated to a single in-flight request.
|
|
116
|
+
*
|
|
117
|
+
* @param options - Optional fetch options.
|
|
118
|
+
* @param options.bypassCache - When true, invalidates the TTL cache. If a
|
|
119
|
+
* request is already in-flight it will be reused (deduplication always
|
|
120
|
+
* applies).
|
|
121
|
+
* @returns The ISO 3166-1 alpha-2 country code, or {@link UNKNOWN_LOCATION}
|
|
122
|
+
* when the API returns an empty or invalid body.
|
|
123
|
+
*/
|
|
124
|
+
fetchGeolocation(options?: FetchGeolocationOptions): Promise<string>;
|
|
125
|
+
}
|
|
126
|
+
export {};
|
|
127
|
+
//# sourceMappingURL=geolocation-api-service.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation-api-service.d.cts","sourceRoot":"","sources":["../../src/geolocation-api-service/geolocation-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAE7C,OAAO,KAAK,EAAE,kCAAkC,EAAE,0DAAsD;AACxG,OAAO,EAAE,GAAG,EAAE,qBAAiB;AAQ/B;;;GAGG;AACH,eAAO,MAAM,WAAW,0BAA0B,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAM1C;;GAEG;AACH,MAAM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