@patientprism/snippet-sdk 1.0.0 → 1.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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Patient Prism SDK
1
+ # Patient Prism Snippet SDK
2
2
  This package includes the Patient Prism Snippet SDK typings, used to assist you with integrating the Patient Prism Snippet into your custom application flow.
3
3
 
4
4
  # How to use
@@ -16,3 +16,34 @@ const data: Submission = {
16
16
 
17
17
  (window.$prism as PrismSDK).submission.send(data, 'elementId');
18
18
  ```
19
+
20
+ # Form Tracking Control
21
+ You can control which forms and fields are tracked by the snippet using data attributes:
22
+
23
+ - `data-prism-exclude-form`: Add this attribute to any form element to exclude the entire form from tracking
24
+ - `data-prism-exclude-input`: Add this attribute to any input element to exclude just that specific field from tracking
25
+ - `data-prism-field-label`: Add this attribute to any input element to override the label used for tracking
26
+
27
+ Example:
28
+ ```html
29
+ <!-- This form will be tracked, but the password field will be excluded -->
30
+ <form id="signup-form">
31
+ <input type="text" name="email" placeholder="Email">
32
+ <input type="password" name="password" data-prism-exclude-input placeholder="Password">
33
+ <button type="submit">Sign Up</button>
34
+ </form>
35
+
36
+ <!-- This entire form will be excluded from tracking -->
37
+ <form id="login-form" data-prism-exclude-form>
38
+ <input type="text" name="username" placeholder="Username">
39
+ <input type="password" name="password" placeholder="Password">
40
+ <button type="submit">Login</button>
41
+ </form>
42
+
43
+ <!-- Override field labels for tracking -->
44
+ <form id="contact-form">
45
+ <input type="text" name="name" data-prism-field-label="Patient Name" placeholder="Your Name">
46
+ <input type="email" name="email" data-prism-field-label="Patient Email" placeholder="Your Email">
47
+ <button type="submit">Submit</button>
48
+ </form>
49
+ ```
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@patientprism/snippet-sdk",
3
3
  "type": "module",
4
4
  "types": "types/index.d.ts",
5
- "version": "1.0.0",
5
+ "version": "1.1.0",
6
6
  "scripts": {
7
7
  "test": "vitest run",
8
8
  "test:watch": "vitest watch",
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@patientprism/snippet-sdk",
3
+ "type": "module",
4
+ "types": "types/index.d.ts",
5
+ "version": "1.1.0",
6
+ "scripts": {
7
+ "test": "vitest run",
8
+ "test:watch": "vitest watch",
9
+ "dev": "vite dev",
10
+ "build": "vite build",
11
+ "build:types": "sh ./build-type-declarations.sh"
12
+ },
13
+ "dependencies": {
14
+ "collect.js": "^4.36.1",
15
+ "js-cookie": "^3.0.5",
16
+ "jsdom": "^23.0.1",
17
+ "libphonenumber-js": "^1.10.51",
18
+ "vite": "^7.1.5",
19
+ "vitest": "^3.2.4",
20
+ "ziggy-js": "^2.5.0"
21
+ },
22
+ "devDependencies": {
23
+ "json": "^11.0.0",
24
+ "typescript": "^5.5.4"
25
+ }
26
+ }
package/types/index.d.ts CHANGED
@@ -1,3 +1,59 @@
1
+ /**
2
+ * @typedef {Object} SubmissionField
3
+ *
4
+ * @property {string} type
5
+ * @property {string|number} value
6
+ * @property {string} label
7
+ */
8
+ /**
9
+ * @typedef {Record<string, string|number|null>} SubmissionOptions
10
+ */
11
+ /**
12
+ * @typedef {Record<string, SubmissionField>} Submission
13
+ */
14
+ /**
15
+ * @typedef {Object} SwapSDK
16
+ *
17
+ * Object containing methods related to Swap functionality.
18
+ *
19
+ * @property {() => Promise<void>} init Initializes the Swap functionality.
20
+ */
21
+ /**
22
+ * @typedef {Object} SubmissionSDK
23
+ *
24
+ * Object containing methods related to Submission functionality.
25
+ *
26
+ * @property {boolean} captureHiddenFields Indicates whether hidden fields should be captured in submissions.
27
+ * @property {() => Promise<void>} init Initialize the Submission functionality.
28
+ * @property {(data: Submission, elementID: string|HTMLElement, options?: SubmissionOptions) => Promise<void>} send Send the form submission.
29
+ */
30
+ /**
31
+ * @typedef {Object} CustomFieldSDK
32
+ *
33
+ * Object containing methods related to the Custom Field functionality.
34
+ *
35
+ * @property {(keys?: string|string[]|Set<string>) => Promise<void>} recapture Recapture some or all of the custom fields.
36
+ */
37
+ /**
38
+ * @typedef {Object} CustomFieldSDK
39
+ *
40
+ * Object containing methods related to the Custom Field functionality.
41
+ *
42
+ * @property {(keys?: string|string[]|Set<string>) => Promise<void>} recapture Recapture some or all of the custom fields.
43
+ */
44
+ /**
45
+ * @typedef {Object} PrismSDK
46
+ *
47
+ * The global `$prism` object for managing Prism-related functionality.
48
+ *
49
+ * @property {boolean} loaded Indicates whether Prism has been loaded or not.
50
+ * @property {boolean} debug Indicates whether Prism is in debug mode or not.
51
+ * @property {(message: string) => void} log Logs a message to the console if debug mode is enabled.
52
+ * @property {SwapSDK} swap Object containing methods related to Swap functionality.
53
+ * @property {SubmissionSDK} submission Object containing methods related to Submission functionality.
54
+ * @property {CustomFieldSDK} custom_fields Object containing methods related to the Custom Field functionality.
55
+ */
56
+ export default function handle(): void;
1
57
  export type SubmissionField = {
2
58
  type: string;
3
59
  value: string | number;
@@ -12,20 +68,33 @@ export type SwapSDK = {
12
68
  /**
13
69
  * Initializes the Swap functionality.
14
70
  */
15
- init: () => void;
71
+ init: () => Promise<void>;
16
72
  };
17
73
  /**
18
74
  * Object containing methods related to Submission functionality.
19
75
  */
20
76
  export type SubmissionSDK = {
77
+ /**
78
+ * Indicates whether hidden fields should be captured in submissions.
79
+ */
80
+ captureHiddenFields: boolean;
21
81
  /**
22
82
  * Initialize the Submission functionality.
23
83
  */
24
- init: () => void;
84
+ init: () => Promise<void>;
25
85
  /**
26
86
  * Send the form submission.
27
87
  */
28
- send: (data: Submission, elementID: string | HTMLElement, options?: SubmissionOptions) => void;
88
+ send: (data: Submission, elementID: string | HTMLElement, options?: SubmissionOptions) => Promise<void>;
89
+ };
90
+ /**
91
+ * Object containing methods related to the Custom Field functionality.
92
+ */
93
+ export type CustomFieldSDK = {
94
+ /**
95
+ * Recapture some or all of the custom fields.
96
+ */
97
+ recapture: (keys?: string | string[] | Set<string>) => Promise<void>;
29
98
  };
30
99
  /**
31
100
  * The global `$prism` object for managing Prism-related functionality.
@@ -51,6 +120,10 @@ export type PrismSDK = {
51
120
  * Object containing methods related to Submission functionality.
52
121
  */
53
122
  submission: SubmissionSDK;
123
+ /**
124
+ * Object containing methods related to the Custom Field functionality.
125
+ */
126
+ custom_fields: CustomFieldSDK;
54
127
  };
55
128
 
56
129
  declare global {