@capgo/capacitor-persistent-uuid 8.1.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.
@@ -0,0 +1,113 @@
1
+ package app.capgo.persistent_uuid;
2
+
3
+ import android.accounts.Account;
4
+ import android.accounts.AccountManager;
5
+ import android.content.Context;
6
+ import java.util.UUID;
7
+
8
+ public class PersistentUuid {
9
+
10
+ static final String ACCOUNT_TYPE = "app.capgo.persistent_uuid";
11
+ private static final String ACCOUNT_PREFIX = "PersistentUuid:";
12
+ private static final String USERDATA_UUID = "uuid";
13
+ private static final String FALLBACK_SCOPE = "default";
14
+ private final Context context;
15
+
16
+ public PersistentUuid(Context context) {
17
+ this.context = context.getApplicationContext();
18
+ }
19
+
20
+ public Result getId(String scope) {
21
+ String normalizedScope = normalizeScope(scope);
22
+ Account account = getOrCreateAccount(normalizedScope);
23
+ AccountManager accountManager = AccountManager.get(context);
24
+ String existing = accountManager.getUserData(account, USERDATA_UUID);
25
+
26
+ if (existing != null && !existing.isEmpty()) {
27
+ return new Result(existing, normalizedScope, false);
28
+ }
29
+
30
+ String id = createUuid();
31
+ accountManager.setUserData(account, USERDATA_UUID, id);
32
+ return new Result(id, normalizedScope, true);
33
+ }
34
+
35
+ public Result resetId(String scope) {
36
+ String normalizedScope = normalizeScope(scope);
37
+ Account account = getOrCreateAccount(normalizedScope);
38
+ String id = createUuid();
39
+ AccountManager.get(context).setUserData(account, USERDATA_UUID, id);
40
+ return new Result(id, normalizedScope, true);
41
+ }
42
+
43
+ public String getPluginVersion() {
44
+ return "8.0.0";
45
+ }
46
+
47
+ private Account getOrCreateAccount(String scope) {
48
+ AccountManager accountManager = AccountManager.get(context);
49
+ Account existing = findAccount(accountManager, scope);
50
+ if (existing != null) {
51
+ return existing;
52
+ }
53
+
54
+ Account account = new Account(accountName(scope), ACCOUNT_TYPE);
55
+ if (accountManager.addAccountExplicitly(account, null, null)) {
56
+ return account;
57
+ }
58
+
59
+ existing = findAccount(accountManager, scope);
60
+ if (existing != null) {
61
+ return existing;
62
+ }
63
+
64
+ throw new IllegalStateException("Unable to create persistent UUID account");
65
+ }
66
+
67
+ private Account findAccount(AccountManager accountManager, String scope) {
68
+ String accountName = accountName(scope);
69
+ for (Account account : accountManager.getAccountsByType(ACCOUNT_TYPE)) {
70
+ if (accountName.equals(account.name)) {
71
+ return account;
72
+ }
73
+ }
74
+ return null;
75
+ }
76
+
77
+ private String accountName(String scope) {
78
+ return ACCOUNT_PREFIX + scope;
79
+ }
80
+
81
+ private String normalizeScope(String scope) {
82
+ if (scope != null) {
83
+ String trimmed = scope.trim();
84
+ if (!trimmed.isEmpty()) {
85
+ return trimmed;
86
+ }
87
+ }
88
+
89
+ String packageName = context.getPackageName();
90
+ if (packageName != null && !packageName.isEmpty()) {
91
+ return packageName;
92
+ }
93
+
94
+ return FALLBACK_SCOPE;
95
+ }
96
+
97
+ private String createUuid() {
98
+ return UUID.randomUUID().toString();
99
+ }
100
+
101
+ public static class Result {
102
+
103
+ public final String id;
104
+ public final String scope;
105
+ public final boolean created;
106
+
107
+ Result(String id, String scope, boolean created) {
108
+ this.id = id;
109
+ this.scope = scope;
110
+ this.created = created;
111
+ }
112
+ }
113
+ }
@@ -0,0 +1,54 @@
1
+ package app.capgo.persistent_uuid;
2
+
3
+ import com.getcapacitor.JSObject;
4
+ import com.getcapacitor.Plugin;
5
+ import com.getcapacitor.PluginCall;
6
+ import com.getcapacitor.PluginMethod;
7
+ import com.getcapacitor.annotation.CapacitorPlugin;
8
+
9
+ @CapacitorPlugin(name = "PersistentUuid")
10
+ public class PersistentUuidPlugin extends Plugin {
11
+
12
+ private PersistentUuid implementation;
13
+
14
+ @Override
15
+ public void load() {
16
+ super.load();
17
+ implementation = new PersistentUuid(getContext());
18
+ }
19
+
20
+ @PluginMethod
21
+ public void getId(PluginCall call) {
22
+ try {
23
+ PersistentUuid.Result result = implementation.getId(call.getString("scope"));
24
+ call.resolve(toJsObject(result));
25
+ } catch (Exception exception) {
26
+ call.reject("Failed to get persistent UUID", exception);
27
+ }
28
+ }
29
+
30
+ @PluginMethod
31
+ public void resetId(PluginCall call) {
32
+ try {
33
+ PersistentUuid.Result result = implementation.resetId(call.getString("scope"));
34
+ call.resolve(toJsObject(result));
35
+ } catch (Exception exception) {
36
+ call.reject("Failed to reset persistent UUID", exception);
37
+ }
38
+ }
39
+
40
+ @PluginMethod
41
+ public void getPluginVersion(PluginCall call) {
42
+ JSObject ret = new JSObject();
43
+ ret.put("version", implementation.getPluginVersion());
44
+ call.resolve(ret);
45
+ }
46
+
47
+ private JSObject toJsObject(PersistentUuid.Result result) {
48
+ JSObject ret = new JSObject();
49
+ ret.put("id", result.id);
50
+ ret.put("scope", result.scope);
51
+ ret.put("created", result.created);
52
+ return ret;
53
+ }
54
+ }
@@ -0,0 +1,60 @@
1
+ package app.capgo.persistent_uuid.auth;
2
+
3
+ import android.accounts.AbstractAccountAuthenticator;
4
+ import android.accounts.Account;
5
+ import android.accounts.AccountAuthenticatorResponse;
6
+ import android.accounts.NetworkErrorException;
7
+ import android.content.Context;
8
+ import android.os.Bundle;
9
+
10
+ public class Authenticator extends AbstractAccountAuthenticator {
11
+
12
+ public Authenticator(Context context) {
13
+ super(context);
14
+ }
15
+
16
+ @Override
17
+ public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
18
+ throw new UnsupportedOperationException();
19
+ }
20
+
21
+ @Override
22
+ public Bundle addAccount(
23
+ AccountAuthenticatorResponse response,
24
+ String accountType,
25
+ String authTokenType,
26
+ String[] requiredFeatures,
27
+ Bundle options
28
+ ) throws NetworkErrorException {
29
+ return null;
30
+ }
31
+
32
+ @Override
33
+ public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException {
34
+ return null;
35
+ }
36
+
37
+ @Override
38
+ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)
39
+ throws NetworkErrorException {
40
+ throw new UnsupportedOperationException();
41
+ }
42
+
43
+ @Override
44
+ public String getAuthTokenLabel(String authTokenType) {
45
+ return null;
46
+ }
47
+
48
+ @Override
49
+ public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)
50
+ throws NetworkErrorException {
51
+ return null;
52
+ }
53
+
54
+ @Override
55
+ public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException {
56
+ Bundle result = new Bundle();
57
+ result.putBoolean("booleanResult", false);
58
+ return result;
59
+ }
60
+ }
@@ -0,0 +1,21 @@
1
+ package app.capgo.persistent_uuid.auth;
2
+
3
+ import android.app.Service;
4
+ import android.content.Intent;
5
+ import android.os.IBinder;
6
+
7
+ public class AuthenticatorService extends Service {
8
+
9
+ private Authenticator authenticator;
10
+
11
+ @Override
12
+ public void onCreate() {
13
+ super.onCreate();
14
+ authenticator = new Authenticator(this);
15
+ }
16
+
17
+ @Override
18
+ public IBinder onBind(Intent intent) {
19
+ return authenticator.getIBinder();
20
+ }
21
+ }
File without changes
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="persistent_uuid_label">Persistent UUID</string>
4
+ </resources>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:accountType="app.capgo.persistent_uuid"
4
+ android:label="@string/persistent_uuid_label" />
package/dist/docs.json ADDED
@@ -0,0 +1,128 @@
1
+ {
2
+ "api": {
3
+ "name": "PersistentUuidPlugin",
4
+ "slug": "persistentuuidplugin",
5
+ "docs": "Persistent UUID API.",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "getId",
10
+ "signature": "(options?: PersistentUuidOptions | undefined) => Promise<PersistentUuidResult>",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "",
15
+ "type": "PersistentUuidOptions | undefined"
16
+ }
17
+ ],
18
+ "returns": "Promise<PersistentUuidResult>",
19
+ "tags": [],
20
+ "docs": "Read the persistent UUID, creating one when none exists for the selected scope.",
21
+ "complexTypes": [
22
+ "PersistentUuidResult",
23
+ "PersistentUuidOptions"
24
+ ],
25
+ "slug": "getid"
26
+ },
27
+ {
28
+ "name": "resetId",
29
+ "signature": "(options?: PersistentUuidOptions | undefined) => Promise<PersistentUuidResult>",
30
+ "parameters": [
31
+ {
32
+ "name": "options",
33
+ "docs": "",
34
+ "type": "PersistentUuidOptions | undefined"
35
+ }
36
+ ],
37
+ "returns": "Promise<PersistentUuidResult>",
38
+ "tags": [],
39
+ "docs": "Replace the stored UUID for the selected scope and return the new value.",
40
+ "complexTypes": [
41
+ "PersistentUuidResult",
42
+ "PersistentUuidOptions"
43
+ ],
44
+ "slug": "resetid"
45
+ },
46
+ {
47
+ "name": "getPluginVersion",
48
+ "signature": "() => Promise<PluginVersionResult>",
49
+ "parameters": [],
50
+ "returns": "Promise<PluginVersionResult>",
51
+ "tags": [],
52
+ "docs": "Returns the platform implementation version marker.",
53
+ "complexTypes": [
54
+ "PluginVersionResult"
55
+ ],
56
+ "slug": "getpluginversion"
57
+ }
58
+ ],
59
+ "properties": []
60
+ },
61
+ "interfaces": [
62
+ {
63
+ "name": "PersistentUuidResult",
64
+ "slug": "persistentuuidresult",
65
+ "docs": "Persistent UUID payload.",
66
+ "tags": [],
67
+ "methods": [],
68
+ "properties": [
69
+ {
70
+ "name": "id",
71
+ "tags": [],
72
+ "docs": "RFC 4122 UUID generated once for the selected scope.",
73
+ "complexTypes": [],
74
+ "type": "string"
75
+ },
76
+ {
77
+ "name": "scope",
78
+ "tags": [],
79
+ "docs": "The scope used to read or create the UUID.",
80
+ "complexTypes": [],
81
+ "type": "string"
82
+ },
83
+ {
84
+ "name": "created",
85
+ "tags": [],
86
+ "docs": "True when this call generated and stored a new UUID.",
87
+ "complexTypes": [],
88
+ "type": "boolean"
89
+ }
90
+ ]
91
+ },
92
+ {
93
+ "name": "PersistentUuidOptions",
94
+ "slug": "persistentuuidoptions",
95
+ "docs": "Options used when reading or resetting the persistent UUID.",
96
+ "tags": [],
97
+ "methods": [],
98
+ "properties": [
99
+ {
100
+ "name": "scope",
101
+ "tags": [],
102
+ "docs": "Optional namespace for the UUID.\n\nBy default, native platforms use the app package/bundle identifier. Pass a\nstable custom scope when debug and production builds use different package\nidentifiers but should share the same persistent UUID.",
103
+ "complexTypes": [],
104
+ "type": "string | undefined"
105
+ }
106
+ ]
107
+ },
108
+ {
109
+ "name": "PluginVersionResult",
110
+ "slug": "pluginversionresult",
111
+ "docs": "Plugin version payload.",
112
+ "tags": [],
113
+ "methods": [],
114
+ "properties": [
115
+ {
116
+ "name": "version",
117
+ "tags": [],
118
+ "docs": "Version identifier returned by the platform implementation.",
119
+ "complexTypes": [],
120
+ "type": "string"
121
+ }
122
+ ]
123
+ }
124
+ ],
125
+ "enums": [],
126
+ "typeAliases": [],
127
+ "pluginConfigs": []
128
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Options used when reading or resetting the persistent UUID.
3
+ */
4
+ export interface PersistentUuidOptions {
5
+ /**
6
+ * Optional namespace for the UUID.
7
+ *
8
+ * By default, native platforms use the app package/bundle identifier. Pass a
9
+ * stable custom scope when debug and production builds use different package
10
+ * identifiers but should share the same persistent UUID.
11
+ */
12
+ scope?: string;
13
+ }
14
+ /**
15
+ * Persistent UUID payload.
16
+ */
17
+ export interface PersistentUuidResult {
18
+ /**
19
+ * RFC 4122 UUID generated once for the selected scope.
20
+ */
21
+ id: string;
22
+ /**
23
+ * The scope used to read or create the UUID.
24
+ */
25
+ scope: string;
26
+ /**
27
+ * True when this call generated and stored a new UUID.
28
+ */
29
+ created: boolean;
30
+ }
31
+ /**
32
+ * Plugin version payload.
33
+ */
34
+ export interface PluginVersionResult {
35
+ /**
36
+ * Version identifier returned by the platform implementation.
37
+ */
38
+ version: string;
39
+ }
40
+ /**
41
+ * Persistent UUID API.
42
+ */
43
+ export interface PersistentUuidPlugin {
44
+ /**
45
+ * Read the persistent UUID, creating one when none exists for the selected scope.
46
+ */
47
+ getId(options?: PersistentUuidOptions): Promise<PersistentUuidResult>;
48
+ /**
49
+ * Replace the stored UUID for the selected scope and return the new value.
50
+ */
51
+ resetId(options?: PersistentUuidOptions): Promise<PersistentUuidResult>;
52
+ /**
53
+ * Returns the platform implementation version marker.
54
+ */
55
+ getPluginVersion(): Promise<PluginVersionResult>;
56
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Options used when reading or resetting the persistent UUID.\n */\nexport interface PersistentUuidOptions {\n /**\n * Optional namespace for the UUID.\n *\n * By default, native platforms use the app package/bundle identifier. Pass a\n * stable custom scope when debug and production builds use different package\n * identifiers but should share the same persistent UUID.\n */\n scope?: string;\n}\n\n/**\n * Persistent UUID payload.\n */\nexport interface PersistentUuidResult {\n /**\n * RFC 4122 UUID generated once for the selected scope.\n */\n id: string;\n\n /**\n * The scope used to read or create the UUID.\n */\n scope: string;\n\n /**\n * True when this call generated and stored a new UUID.\n */\n created: boolean;\n}\n\n/**\n * Plugin version payload.\n */\nexport interface PluginVersionResult {\n /**\n * Version identifier returned by the platform implementation.\n */\n version: string;\n}\n\n/**\n * Persistent UUID API.\n */\nexport interface PersistentUuidPlugin {\n /**\n * Read the persistent UUID, creating one when none exists for the selected scope.\n */\n getId(options?: PersistentUuidOptions): Promise<PersistentUuidResult>;\n\n /**\n * Replace the stored UUID for the selected scope and return the new value.\n */\n resetId(options?: PersistentUuidOptions): Promise<PersistentUuidResult>;\n\n /**\n * Returns the platform implementation version marker.\n */\n getPluginVersion(): Promise<PluginVersionResult>;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { PersistentUuidPlugin } from './definitions';
2
+ declare const PersistentUuid: PersistentUuidPlugin;
3
+ export * from './definitions';
4
+ export { PersistentUuid };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const PersistentUuid = registerPlugin('PersistentUuid', {
3
+ web: () => import('./web').then((m) => new m.PersistentUuidWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { PersistentUuid };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,cAAc,GAAG,cAAc,CAAuB,gBAAgB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;CAClE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { PersistentUuidPlugin } from './definitions';\n\nconst PersistentUuid = registerPlugin<PersistentUuidPlugin>('PersistentUuid', {\n web: () => import('./web').then((m) => new m.PersistentUuidWeb()),\n});\n\nexport * from './definitions';\nexport { PersistentUuid };\n"]}
@@ -0,0 +1,7 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { PersistentUuidOptions, PersistentUuidPlugin, PersistentUuidResult, PluginVersionResult } from './definitions';
3
+ export declare class PersistentUuidWeb extends WebPlugin implements PersistentUuidPlugin {
4
+ getId(options?: PersistentUuidOptions): Promise<PersistentUuidResult>;
5
+ resetId(options?: PersistentUuidOptions): Promise<PersistentUuidResult>;
6
+ getPluginVersion(): Promise<PluginVersionResult>;
7
+ }
@@ -0,0 +1,75 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ const STORAGE_PREFIX = 'capgo:persistent-uuid:';
3
+ const DEFAULT_SCOPE = 'web';
4
+ const memoryStore = new Map();
5
+ const normalizeScope = (options) => {
6
+ var _a;
7
+ const scope = (_a = options === null || options === void 0 ? void 0 : options.scope) === null || _a === void 0 ? void 0 : _a.trim();
8
+ return scope && scope.length > 0 ? scope : DEFAULT_SCOPE;
9
+ };
10
+ const createUuid = () => {
11
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
12
+ return crypto.randomUUID();
13
+ }
14
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {
15
+ const random = Math.floor(Math.random() * 16);
16
+ const value = char === 'x' ? random : (random & 0x3) | 0x8;
17
+ return value.toString(16);
18
+ });
19
+ };
20
+ const readValue = (key) => {
21
+ var _a, _b, _c, _d;
22
+ try {
23
+ return (_c = (_b = (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(key)) !== null && _b !== void 0 ? _b : memoryStore.get(key)) !== null && _c !== void 0 ? _c : null;
24
+ }
25
+ catch (_e) {
26
+ return (_d = memoryStore.get(key)) !== null && _d !== void 0 ? _d : null;
27
+ }
28
+ };
29
+ const writeValue = (key, value) => {
30
+ var _a;
31
+ memoryStore.set(key, value);
32
+ try {
33
+ (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(key, value);
34
+ }
35
+ catch (_b) {
36
+ // In-memory fallback already updated.
37
+ }
38
+ };
39
+ export class PersistentUuidWeb extends WebPlugin {
40
+ async getId(options) {
41
+ const scope = normalizeScope(options);
42
+ const key = STORAGE_PREFIX + scope;
43
+ const existing = readValue(key);
44
+ if (existing) {
45
+ return {
46
+ id: existing,
47
+ scope,
48
+ created: false,
49
+ };
50
+ }
51
+ const id = createUuid();
52
+ writeValue(key, id);
53
+ return {
54
+ id,
55
+ scope,
56
+ created: true,
57
+ };
58
+ }
59
+ async resetId(options) {
60
+ const scope = normalizeScope(options);
61
+ const id = createUuid();
62
+ writeValue(STORAGE_PREFIX + scope, id);
63
+ return {
64
+ id,
65
+ scope,
66
+ created: true,
67
+ };
68
+ }
69
+ async getPluginVersion() {
70
+ return {
71
+ version: 'web',
72
+ };
73
+ }
74
+ }
75
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"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","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n PersistentUuidOptions,\n PersistentUuidPlugin,\n PersistentUuidResult,\n PluginVersionResult,\n} from './definitions';\n\nconst STORAGE_PREFIX = 'capgo:persistent-uuid:';\nconst DEFAULT_SCOPE = 'web';\n\nconst memoryStore = new Map<string, string>();\n\nconst normalizeScope = (options?: PersistentUuidOptions): string => {\n const scope = options?.scope?.trim();\n return scope && scope.length > 0 ? scope : DEFAULT_SCOPE;\n};\n\nconst createUuid = (): string => {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {\n const random = Math.floor(Math.random() * 16);\n const value = char === 'x' ? random : (random & 0x3) | 0x8;\n return value.toString(16);\n });\n};\n\nconst readValue = (key: string): string | null => {\n try {\n return globalThis.localStorage?.getItem(key) ?? memoryStore.get(key) ?? null;\n } catch {\n return memoryStore.get(key) ?? null;\n }\n};\n\nconst writeValue = (key: string, value: string): void => {\n memoryStore.set(key, value);\n try {\n globalThis.localStorage?.setItem(key, value);\n } catch {\n // In-memory fallback already updated.\n }\n};\n\nexport class PersistentUuidWeb extends WebPlugin implements PersistentUuidPlugin {\n async getId(options?: PersistentUuidOptions): Promise<PersistentUuidResult> {\n const scope = normalizeScope(options);\n const key = STORAGE_PREFIX + scope;\n const existing = readValue(key);\n\n if (existing) {\n return {\n id: existing,\n scope,\n created: false,\n };\n }\n\n const id = createUuid();\n writeValue(key, id);\n\n return {\n id,\n scope,\n created: true,\n };\n }\n\n async resetId(options?: PersistentUuidOptions): Promise<PersistentUuidResult> {\n const scope = normalizeScope(options);\n const id = createUuid();\n writeValue(STORAGE_PREFIX + scope, id);\n\n return {\n id,\n scope,\n created: true,\n };\n }\n\n async getPluginVersion(): Promise<PluginVersionResult> {\n return {\n version: 'web',\n };\n }\n}\n"]}
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const PersistentUuid = core.registerPlugin('PersistentUuid', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.PersistentUuidWeb()),
7
+ });
8
+
9
+ const STORAGE_PREFIX = 'capgo:persistent-uuid:';
10
+ const DEFAULT_SCOPE = 'web';
11
+ const memoryStore = new Map();
12
+ const normalizeScope = (options) => {
13
+ var _a;
14
+ const scope = (_a = options === null || options === void 0 ? void 0 : options.scope) === null || _a === void 0 ? void 0 : _a.trim();
15
+ return scope && scope.length > 0 ? scope : DEFAULT_SCOPE;
16
+ };
17
+ const createUuid = () => {
18
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
19
+ return crypto.randomUUID();
20
+ }
21
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {
22
+ const random = Math.floor(Math.random() * 16);
23
+ const value = char === 'x' ? random : (random & 0x3) | 0x8;
24
+ return value.toString(16);
25
+ });
26
+ };
27
+ const readValue = (key) => {
28
+ var _a, _b, _c, _d;
29
+ try {
30
+ return (_c = (_b = (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(key)) !== null && _b !== void 0 ? _b : memoryStore.get(key)) !== null && _c !== void 0 ? _c : null;
31
+ }
32
+ catch (_e) {
33
+ return (_d = memoryStore.get(key)) !== null && _d !== void 0 ? _d : null;
34
+ }
35
+ };
36
+ const writeValue = (key, value) => {
37
+ var _a;
38
+ memoryStore.set(key, value);
39
+ try {
40
+ (_a = globalThis.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(key, value);
41
+ }
42
+ catch (_b) {
43
+ // In-memory fallback already updated.
44
+ }
45
+ };
46
+ class PersistentUuidWeb extends core.WebPlugin {
47
+ async getId(options) {
48
+ const scope = normalizeScope(options);
49
+ const key = STORAGE_PREFIX + scope;
50
+ const existing = readValue(key);
51
+ if (existing) {
52
+ return {
53
+ id: existing,
54
+ scope,
55
+ created: false,
56
+ };
57
+ }
58
+ const id = createUuid();
59
+ writeValue(key, id);
60
+ return {
61
+ id,
62
+ scope,
63
+ created: true,
64
+ };
65
+ }
66
+ async resetId(options) {
67
+ const scope = normalizeScope(options);
68
+ const id = createUuid();
69
+ writeValue(STORAGE_PREFIX + scope, id);
70
+ return {
71
+ id,
72
+ scope,
73
+ created: true,
74
+ };
75
+ }
76
+ async getPluginVersion() {
77
+ return {
78
+ version: 'web',
79
+ };
80
+ }
81
+ }
82
+
83
+ var web = /*#__PURE__*/Object.freeze({
84
+ __proto__: null,
85
+ PersistentUuidWeb: PersistentUuidWeb
86
+ });
87
+
88
+ exports.PersistentUuid = PersistentUuid;
89
+ //# sourceMappingURL=plugin.cjs.js.map