@purespectrum1/purescore-client 0.7.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.
Files changed (136) hide show
  1. package/README.md +55 -0
  2. package/lib/application/auto-init.d.ts +44 -0
  3. package/lib/application/auto-init.js +245 -0
  4. package/lib/application/device-identifier.d.ts +116 -0
  5. package/lib/application/device-identifier.js +169 -0
  6. package/lib/domain/models/crosscutting/device-intelligence.d.ts +11 -0
  7. package/lib/domain/models/crosscutting/device-intelligence.js +18 -0
  8. package/lib/domain/models/crosscutting/index.d.ts +1 -0
  9. package/lib/domain/models/crosscutting/index.js +17 -0
  10. package/lib/domain/protocols/cache/get-storage.d.ts +8 -0
  11. package/lib/domain/protocols/cache/get-storage.js +2 -0
  12. package/lib/domain/protocols/cache/index.d.ts +3 -0
  13. package/lib/domain/protocols/cache/index.js +19 -0
  14. package/lib/domain/protocols/cache/remove-storage.d.ts +6 -0
  15. package/lib/domain/protocols/cache/remove-storage.js +2 -0
  16. package/lib/domain/protocols/cache/set-storage.d.ts +7 -0
  17. package/lib/domain/protocols/cache/set-storage.js +2 -0
  18. package/lib/domain/protocols/http/http-client.d.ts +23 -0
  19. package/lib/domain/protocols/http/http-client.js +13 -0
  20. package/lib/domain/protocols/services/behavioural-biometrics/cursor-behavior.d.ts +63 -0
  21. package/lib/domain/protocols/services/behavioural-biometrics/cursor-behavior.js +2 -0
  22. package/lib/domain/protocols/services/behavioural-biometrics/index.d.ts +3 -0
  23. package/lib/domain/protocols/services/behavioural-biometrics/index.js +19 -0
  24. package/lib/domain/protocols/services/behavioural-biometrics/keystorke-metrics.d.ts +35 -0
  25. package/lib/domain/protocols/services/behavioural-biometrics/keystorke-metrics.js +2 -0
  26. package/lib/domain/protocols/services/behavioural-biometrics/touch-behavior.d.ts +88 -0
  27. package/lib/domain/protocols/services/behavioural-biometrics/touch-behavior.js +2 -0
  28. package/lib/domain/protocols/services/device-fingerprint/display.d.ts +22 -0
  29. package/lib/domain/protocols/services/device-fingerprint/display.js +2 -0
  30. package/lib/domain/protocols/services/device-fingerprint/index.d.ts +3 -0
  31. package/lib/domain/protocols/services/device-fingerprint/index.js +19 -0
  32. package/lib/domain/protocols/services/device-fingerprint/navigator.d.ts +63 -0
  33. package/lib/domain/protocols/services/device-fingerprint/navigator.js +2 -0
  34. package/lib/domain/protocols/services/device-fingerprint/utils.d.ts +40 -0
  35. package/lib/domain/protocols/services/device-fingerprint/utils.js +2 -0
  36. package/lib/domain/protocols/services/device-identifier.d.ts +96 -0
  37. package/lib/domain/protocols/services/device-identifier.js +2 -0
  38. package/lib/domain/protocols/services/device-intelligence.d.ts +5 -0
  39. package/lib/domain/protocols/services/device-intelligence.js +2 -0
  40. package/lib/domain/protocols/services/listeners.d.ts +9 -0
  41. package/lib/domain/protocols/services/listeners.js +2 -0
  42. package/lib/domain/protocols/services/single-script-injection/auto-init.d.ts +120 -0
  43. package/lib/domain/protocols/services/single-script-injection/auto-init.js +2 -0
  44. package/lib/domain/protocols/services/single-script-injection/index.d.ts +1 -0
  45. package/lib/domain/protocols/services/single-script-injection/index.js +17 -0
  46. package/lib/domain/services/behavioural-biometrics/collector.d.ts +94 -0
  47. package/lib/domain/services/behavioural-biometrics/collector.js +229 -0
  48. package/lib/domain/services/behavioural-biometrics/cursor-behavior.d.ts +87 -0
  49. package/lib/domain/services/behavioural-biometrics/cursor-behavior.js +369 -0
  50. package/lib/domain/services/behavioural-biometrics/index.d.ts +4 -0
  51. package/lib/domain/services/behavioural-biometrics/index.js +20 -0
  52. package/lib/domain/services/behavioural-biometrics/keystroke-metrics.d.ts +60 -0
  53. package/lib/domain/services/behavioural-biometrics/keystroke-metrics.js +213 -0
  54. package/lib/domain/services/behavioural-biometrics/touch-behavior.d.ts +125 -0
  55. package/lib/domain/services/behavioural-biometrics/touch-behavior.js +413 -0
  56. package/lib/domain/services/device-fingerprint/audio.d.ts +14 -0
  57. package/lib/domain/services/device-fingerprint/audio.js +109 -0
  58. package/lib/domain/services/device-fingerprint/canvas.d.ts +10 -0
  59. package/lib/domain/services/device-fingerprint/canvas.js +33 -0
  60. package/lib/domain/services/device-fingerprint/display.d.ts +49 -0
  61. package/lib/domain/services/device-fingerprint/display.js +88 -0
  62. package/lib/domain/services/device-fingerprint/hash.d.ts +14 -0
  63. package/lib/domain/services/device-fingerprint/hash.js +60 -0
  64. package/lib/domain/services/device-fingerprint/index.d.ts +8 -0
  65. package/lib/domain/services/device-fingerprint/index.js +24 -0
  66. package/lib/domain/services/device-fingerprint/navigator.d.ts +110 -0
  67. package/lib/domain/services/device-fingerprint/navigator.js +213 -0
  68. package/lib/domain/services/device-fingerprint/pointer-capability.d.ts +14 -0
  69. package/lib/domain/services/device-fingerprint/pointer-capability.js +42 -0
  70. package/lib/domain/services/device-fingerprint/storage.d.ts +44 -0
  71. package/lib/domain/services/device-fingerprint/storage.js +64 -0
  72. package/lib/domain/services/device-fingerprint/utils.d.ts +42 -0
  73. package/lib/domain/services/device-fingerprint/utils.js +95 -0
  74. package/lib/domain/services/device-intelligence.d.ts +10 -0
  75. package/lib/domain/services/device-intelligence.js +59 -0
  76. package/lib/domain/services/single-script-injection/checkpoint-scheduler.d.ts +37 -0
  77. package/lib/domain/services/single-script-injection/checkpoint-scheduler.js +94 -0
  78. package/lib/domain/services/single-script-injection/index.d.ts +3 -0
  79. package/lib/domain/services/single-script-injection/index.js +19 -0
  80. package/lib/domain/services/single-script-injection/response-delivery.d.ts +47 -0
  81. package/lib/domain/services/single-script-injection/response-delivery.js +115 -0
  82. package/lib/domain/services/single-script-injection/schedule-store.d.ts +69 -0
  83. package/lib/domain/services/single-script-injection/schedule-store.js +146 -0
  84. package/lib/domain/services/snapshot-store.d.ts +19 -0
  85. package/lib/domain/services/snapshot-store.js +36 -0
  86. package/lib/domain/services/spa-navigation.d.ts +15 -0
  87. package/lib/domain/services/spa-navigation.js +40 -0
  88. package/lib/index.d.ts +19 -0
  89. package/lib/index.js +27 -0
  90. package/lib/infra/cache/index.d.ts +3 -0
  91. package/lib/infra/cache/index.js +19 -0
  92. package/lib/infra/cache/local-storage-adapter.d.ts +8 -0
  93. package/lib/infra/cache/local-storage-adapter.js +14 -0
  94. package/lib/infra/cache/session-storage-adapter.d.ts +8 -0
  95. package/lib/infra/cache/session-storage-adapter.js +14 -0
  96. package/lib/infra/cache/web-storage-adapter.d.ts +13 -0
  97. package/lib/infra/cache/web-storage-adapter.js +33 -0
  98. package/lib/infra/http/axios-http-client.d.ts +4 -0
  99. package/lib/infra/http/axios-http-client.js +39 -0
  100. package/lib/validation/builder.d.ts +43 -0
  101. package/lib/validation/builder.js +85 -0
  102. package/lib/validation/composite.d.ts +13 -0
  103. package/lib/validation/composite.js +23 -0
  104. package/lib/validation/errors/index.d.ts +2 -0
  105. package/lib/validation/errors/index.js +18 -0
  106. package/lib/validation/errors/invalid-field-error.d.ts +7 -0
  107. package/lib/validation/errors/invalid-field-error.js +14 -0
  108. package/lib/validation/errors/required-field-error.d.ts +3 -0
  109. package/lib/validation/errors/required-field-error.js +10 -0
  110. package/lib/validation/index.d.ts +5 -0
  111. package/lib/validation/index.js +21 -0
  112. package/lib/validation/protocols/index.d.ts +1 -0
  113. package/lib/validation/protocols/index.js +17 -0
  114. package/lib/validation/protocols/validator.d.ts +11 -0
  115. package/lib/validation/protocols/validator.js +2 -0
  116. package/lib/validation/validators/behavioural-signal.d.ts +27 -0
  117. package/lib/validation/validators/behavioural-signal.js +56 -0
  118. package/lib/validation/validators/country-code.d.ts +14 -0
  119. package/lib/validation/validators/country-code.js +24 -0
  120. package/lib/validation/validators/global-function.d.ts +14 -0
  121. package/lib/validation/validators/global-function.js +29 -0
  122. package/lib/validation/validators/index.d.ts +9 -0
  123. package/lib/validation/validators/index.js +25 -0
  124. package/lib/validation/validators/interpolated-template.d.ts +14 -0
  125. package/lib/validation/validators/interpolated-template.js +28 -0
  126. package/lib/validation/validators/json-object.d.ts +14 -0
  127. package/lib/validation/validators/json-object.js +33 -0
  128. package/lib/validation/validators/language-code.d.ts +13 -0
  129. package/lib/validation/validators/language-code.js +23 -0
  130. package/lib/validation/validators/positive-number.d.ts +13 -0
  131. package/lib/validation/validators/positive-number.js +24 -0
  132. package/lib/validation/validators/required-string.d.ts +10 -0
  133. package/lib/validation/validators/required-string.js +19 -0
  134. package/lib/validation/validators/schedule-record.d.ts +26 -0
  135. package/lib/validation/validators/schedule-record.js +33 -0
  136. package/package.json +51 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequiredString = void 0;
4
+ const errors_1 = require("../errors");
5
+ /**
6
+ * Rejects a missing, empty or whitespace-only string.
7
+ */
8
+ class RequiredString {
9
+ constructor(value, fieldName) {
10
+ this.value = value;
11
+ this.fieldName = fieldName;
12
+ }
13
+ validate() {
14
+ var _a;
15
+ if (!((_a = this.value) === null || _a === void 0 ? void 0 : _a.trim()))
16
+ return new errors_1.RequiredFieldError(this.fieldName);
17
+ }
18
+ }
19
+ exports.RequiredString = RequiredString;
@@ -0,0 +1,26 @@
1
+ import { Validator } from '../protocols';
2
+ /**
3
+ * The fields this rule insists on. Deliberately structural rather than an import
4
+ * of `ScheduleRecord`: the subject is untrusted JSON that has not earned that
5
+ * type yet, and claiming it before checking would defeat the check.
6
+ */
7
+ type MaybeScheduleRecord = {
8
+ startedAt?: unknown;
9
+ sent?: unknown;
10
+ expiry?: unknown;
11
+ checkpoints?: unknown;
12
+ };
13
+ /**
14
+ * Rejects a schedule record that is not usable.
15
+ *
16
+ * The record is read back from localStorage, which the respondent can edit, so
17
+ * nothing about its shape can be assumed: a record missing its timestamps or its
18
+ * checkpoints has to be discarded rather than driven off.
19
+ */
20
+ export declare class ScheduleRecordShape implements Validator {
21
+ private readonly record;
22
+ private readonly fieldName;
23
+ constructor(record: MaybeScheduleRecord | null | undefined, fieldName: string);
24
+ validate(): Error | undefined;
25
+ }
26
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScheduleRecordShape = void 0;
4
+ const errors_1 = require("../errors");
5
+ /**
6
+ * Rejects a schedule record that is not usable.
7
+ *
8
+ * The record is read back from localStorage, which the respondent can edit, so
9
+ * nothing about its shape can be assumed: a record missing its timestamps or its
10
+ * checkpoints has to be discarded rather than driven off.
11
+ */
12
+ class ScheduleRecordShape {
13
+ constructor(record, fieldName) {
14
+ this.record = record;
15
+ this.fieldName = fieldName;
16
+ }
17
+ validate() {
18
+ if (!this.record)
19
+ return new errors_1.InvalidFieldError(this.fieldName, 'is missing');
20
+ const { startedAt, sent, expiry, checkpoints } = this.record;
21
+ if (typeof startedAt !== 'number' || typeof sent !== 'number' || typeof expiry !== 'number') {
22
+ return new errors_1.InvalidFieldError(this.fieldName, 'is missing its timestamps');
23
+ }
24
+ if (!Array.isArray(checkpoints) || checkpoints.length === 0) {
25
+ return new errors_1.InvalidFieldError(this.fieldName, 'has no checkpoints');
26
+ }
27
+ const allCheckpointsUsable = checkpoints.every(c => typeof (c === null || c === void 0 ? void 0 : c.n) === 'number' && typeof (c === null || c === void 0 ? void 0 : c.dueAt) === 'number');
28
+ if (!allCheckpointsUsable) {
29
+ return new errors_1.InvalidFieldError(this.fieldName, 'has a malformed checkpoint');
30
+ }
31
+ }
32
+ }
33
+ exports.ScheduleRecordShape = ScheduleRecordShape;
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@purespectrum1/purescore-client",
3
+ "description": "A library to identify purescore devices",
4
+ "version": "0.7.0",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "clean": "rm -rf lib && rm -rf dist",
8
+ "build": "tsc && webpack --config webpack.config.js",
9
+ "build:node": "tsc",
10
+ "build:browser": "webpack --config webpack.config.js && OUTPUT_NAME=bundle.js webpack --config webpack.config.js",
11
+ "prepare": "npm run build",
12
+ "test": "jest",
13
+ "lint": "npx eslint"
14
+ },
15
+ "files": [
16
+ "lib/**/*"
17
+ ],
18
+ "keywords": [
19
+ "device identifier",
20
+ "device fingerprints"
21
+ ],
22
+ "author": "datastars",
23
+ "license": "ISC",
24
+ "dependencies": {
25
+ "axios": "^1.20.0",
26
+ "ua-parser-js": "^2.0.10"
27
+ },
28
+ "devDependencies": {
29
+ "@babel/core": "^7.29.7",
30
+ "@babel/preset-env": "^7.29.7",
31
+ "@babel/preset-typescript": "^7.29.7",
32
+ "@eslint/js": "^9.39.5",
33
+ "@jest/globals": "^29.7.0",
34
+ "@testing-library/dom": "^10.4.1",
35
+ "@testing-library/jest-dom": "^6.9.1",
36
+ "@types/eslint__js": "^8.42.3",
37
+ "@types/jest": "^29.5.14",
38
+ "@types/ua-parser-js": "^0.7.39",
39
+ "babel-loader": "^10.1.1",
40
+ "canvas": "^2.11.2",
41
+ "core-js": "^3.50.0",
42
+ "eslint": "^9.39.5",
43
+ "globals": "^15.15.0",
44
+ "jest": "^29.7.0",
45
+ "jest-environment-jsdom": "^29.7.0",
46
+ "ts-jest": "^29.4.12",
47
+ "typescript": "^5.9.3",
48
+ "webpack": "^5.110.3",
49
+ "webpack-cli": "^6.0.1"
50
+ }
51
+ }