@planningcenter/chat-react-native 3.20.1-rc.1 → 3.20.1-rc.3

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 (80) hide show
  1. package/build/contexts/chat_context.d.ts +2 -0
  2. package/build/contexts/chat_context.d.ts.map +1 -1
  3. package/build/contexts/chat_context.js +40 -1
  4. package/build/contexts/chat_context.js.map +1 -1
  5. package/build/hooks/index.d.ts +1 -0
  6. package/build/hooks/index.d.ts.map +1 -1
  7. package/build/hooks/index.js +1 -0
  8. package/build/hooks/index.js.map +1 -1
  9. package/build/hooks/use_conversation.d.ts +1 -0
  10. package/build/hooks/use_conversation.d.ts.map +1 -1
  11. package/build/hooks/use_conversation.js +11 -2
  12. package/build/hooks/use_conversation.js.map +1 -1
  13. package/build/hooks/use_message_create_or_update.d.ts.map +1 -1
  14. package/build/hooks/use_message_create_or_update.js +2 -1
  15. package/build/hooks/use_message_create_or_update.js.map +1 -1
  16. package/build/hooks/use_product_analytics.d.ts +9 -0
  17. package/build/hooks/use_product_analytics.d.ts.map +1 -0
  18. package/build/hooks/use_product_analytics.js +68 -0
  19. package/build/hooks/use_product_analytics.js.map +1 -0
  20. package/build/hooks/use_suspense_api.d.ts +1 -1
  21. package/build/hooks/use_suspense_api.d.ts.map +1 -1
  22. package/build/hooks/use_suspense_api.js.map +1 -1
  23. package/build/screens/conversation_screen.d.ts.map +1 -1
  24. package/build/screens/conversation_screen.js +6 -0
  25. package/build/screens/conversation_screen.js.map +1 -1
  26. package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
  27. package/build/screens/conversations/conversations_screen.js +2 -1
  28. package/build/screens/conversations/conversations_screen.js.map +1 -1
  29. package/build/screens/message_actions_screen.js +4 -3
  30. package/build/screens/message_actions_screen.js.map +1 -1
  31. package/build/types/product_analytics.d.ts +6 -0
  32. package/build/types/product_analytics.d.ts.map +1 -0
  33. package/build/types/product_analytics.js +2 -0
  34. package/build/types/product_analytics.js.map +1 -0
  35. package/build/types/resources/analytics_metadata.d.ts +5 -0
  36. package/build/types/resources/analytics_metadata.d.ts.map +1 -0
  37. package/build/types/resources/analytics_metadata.js +2 -0
  38. package/build/types/resources/analytics_metadata.js.map +1 -0
  39. package/build/types/resources/conversation.d.ts +2 -0
  40. package/build/types/resources/conversation.d.ts.map +1 -1
  41. package/build/types/resources/conversation.js.map +1 -1
  42. package/build/types/resources/index.d.ts +1 -0
  43. package/build/types/resources/index.d.ts.map +1 -1
  44. package/build/types/resources/index.js +1 -0
  45. package/build/types/resources/index.js.map +1 -1
  46. package/build/utils/cache/optimistically_update_message.d.ts +2 -1
  47. package/build/utils/cache/optimistically_update_message.d.ts.map +1 -1
  48. package/build/utils/cache/optimistically_update_message.js +5 -2
  49. package/build/utils/cache/optimistically_update_message.js.map +1 -1
  50. package/build/utils/request/conversation.d.ts.map +1 -1
  51. package/build/utils/request/conversation.js +2 -1
  52. package/build/utils/request/conversation.js.map +1 -1
  53. package/build/utils/request/get_messages.d.ts +1 -0
  54. package/build/utils/request/get_messages.d.ts.map +1 -1
  55. package/build/utils/request/get_messages.js +4 -2
  56. package/build/utils/request/get_messages.js.map +1 -1
  57. package/build/utils/sha_256.d.ts +31 -0
  58. package/build/utils/sha_256.d.ts.map +1 -0
  59. package/build/utils/sha_256.js +195 -0
  60. package/build/utils/sha_256.js.map +1 -0
  61. package/package.json +2 -2
  62. package/src/__tests__/hooks/useTheme.tsx +40 -16
  63. package/src/contexts/chat_context.tsx +59 -2
  64. package/src/hooks/index.ts +1 -0
  65. package/src/hooks/use_conversation.ts +12 -2
  66. package/src/hooks/use_message_create_or_update.ts +2 -1
  67. package/src/hooks/use_product_analytics.ts +107 -0
  68. package/src/hooks/use_suspense_api.ts +1 -1
  69. package/src/screens/conversation_screen.tsx +11 -0
  70. package/src/screens/conversations/conversations_screen.tsx +3 -1
  71. package/src/screens/message_actions_screen.tsx +4 -3
  72. package/src/types/product_analytics.ts +5 -0
  73. package/src/types/resources/analytics_metadata.ts +4 -0
  74. package/src/types/resources/conversation.ts +2 -0
  75. package/src/types/resources/index.ts +1 -0
  76. package/src/utils/__tests__/sha_256.test.ts +70 -0
  77. package/src/utils/cache/optimistically_update_message.ts +7 -1
  78. package/src/utils/request/conversation.ts +2 -1
  79. package/src/utils/request/get_messages.ts +4 -2
  80. package/src/utils/sha_256.ts +229 -0
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Pure JavaScript SHA-256 implementation
3
+ * Conforms to the crypto-js API for drop-in replacement
4
+ */
5
+ /** Hash result object with toString methods */
6
+ declare class HashResult {
7
+ private bytes;
8
+ constructor(bytes: number[]);
9
+ /** Convert hash to hexadecimal string */
10
+ toString(encoding?: {
11
+ stringify: (bytes: number[]) => string;
12
+ }): string;
13
+ }
14
+ /** Hex encoding object (mimics crypto-js enc.Hex) */
15
+ export declare const Hex: {
16
+ stringify: (bytes: number[]) => string;
17
+ };
18
+ /**
19
+ * Compute SHA-256 hash of a string
20
+ * @param message - The message to hash
21
+ * @returns HashResult object with toString method
22
+ */
23
+ export declare function SHA256(message: string): HashResult;
24
+ /** Encoding utilities (mimics crypto-js enc) */
25
+ export declare const enc: {
26
+ Hex: {
27
+ stringify: (bytes: number[]) => string;
28
+ };
29
+ };
30
+ export {};
31
+ //# sourceMappingURL=sha_256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha_256.d.ts","sourceRoot":"","sources":["../../src/utils/sha_256.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA6LH,+CAA+C;AAC/C,cAAM,UAAU;IACd,OAAO,CAAC,KAAK,CAAU;gBAEX,KAAK,EAAE,MAAM,EAAE;IAI3B,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QAAE,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,CAAA;KAAE,GAAG,MAAM;CAOxE;AAED,qDAAqD;AACrD,eAAO,MAAM,GAAG;uBACK,MAAM,EAAE;CAC5B,CAAA;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAGlD;AAED,gDAAgD;AAChD,eAAO,MAAM,GAAG;;2BAdK,MAAM,EAAE;;CAgB5B,CAAA"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Pure JavaScript SHA-256 implementation
3
+ * Conforms to the crypto-js API for drop-in replacement
4
+ */
5
+ /* eslint-disable no-bitwise */
6
+ // SHA-256 constants (first 32 bits of the fractional parts of the cube roots of the first 64 primes)
7
+ const K = [
8
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
9
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
10
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
11
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
12
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
13
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
14
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
15
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
16
+ ];
17
+ // Initial hash values (first 32 bits of the fractional parts of the square roots of the first 8 primes)
18
+ const H = [
19
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
20
+ ];
21
+ /** Right rotate 32-bit integer */
22
+ function rotr(n, x) {
23
+ return (x >>> n) | (x << (32 - n));
24
+ }
25
+ /** SHA-256 choice function */
26
+ function ch(x, y, z) {
27
+ return (x & y) ^ (~x & z);
28
+ }
29
+ /** SHA-256 majority function */
30
+ function maj(x, y, z) {
31
+ return (x & y) ^ (x & z) ^ (y & z);
32
+ }
33
+ /** SHA-256 Σ0 function */
34
+ function sigma0(x) {
35
+ return rotr(2, x) ^ rotr(13, x) ^ rotr(22, x);
36
+ }
37
+ /** SHA-256 Σ1 function */
38
+ function sigma1(x) {
39
+ return rotr(6, x) ^ rotr(11, x) ^ rotr(25, x);
40
+ }
41
+ /** SHA-256 σ0 function */
42
+ function gamma0(x) {
43
+ return rotr(7, x) ^ rotr(18, x) ^ (x >>> 3);
44
+ }
45
+ /** SHA-256 σ1 function */
46
+ function gamma1(x) {
47
+ return rotr(17, x) ^ rotr(19, x) ^ (x >>> 10);
48
+ }
49
+ /** Convert string to UTF-8 byte array */
50
+ function stringToBytes(str) {
51
+ const bytes = [];
52
+ for (let i = 0; i < str.length; i++) {
53
+ let charCode = str.charCodeAt(i);
54
+ if (charCode < 0x80) {
55
+ bytes.push(charCode);
56
+ }
57
+ else if (charCode < 0x800) {
58
+ bytes.push(0xc0 | (charCode >> 6), 0x80 | (charCode & 0x3f));
59
+ }
60
+ else if (charCode < 0xd800 || charCode >= 0xe000) {
61
+ bytes.push(0xe0 | (charCode >> 12), 0x80 | ((charCode >> 6) & 0x3f), 0x80 | (charCode & 0x3f));
62
+ }
63
+ else {
64
+ // Surrogate pair
65
+ i++;
66
+ charCode = 0x10000 + (((charCode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
67
+ bytes.push(0xf0 | (charCode >> 18), 0x80 | ((charCode >> 12) & 0x3f), 0x80 | ((charCode >> 6) & 0x3f), 0x80 | (charCode & 0x3f));
68
+ }
69
+ }
70
+ return bytes;
71
+ }
72
+ /** Preprocess message: pad and convert to 512-bit blocks */
73
+ function preprocessMessage(message) {
74
+ const messageLength = message.length;
75
+ const bitLength = messageLength * 8;
76
+ // Append the '1' bit (plus zero padding to make 8 bits)
77
+ message.push(0x80);
78
+ // Append zeros until message length ≡ 448 (mod 512)
79
+ // This leaves 64 bits for the length
80
+ while (message.length % 64 !== 56) {
81
+ message.push(0x00);
82
+ }
83
+ // Append original message length as 64-bit big-endian integer
84
+ // JavaScript numbers are 53-bit safe, so we split into two 32-bit parts
85
+ const lengthHigh = Math.floor(bitLength / 0x100000000);
86
+ const lengthLow = bitLength >>> 0;
87
+ for (let i = 24; i >= 0; i -= 8) {
88
+ message.push((lengthHigh >>> i) & 0xff);
89
+ }
90
+ for (let i = 24; i >= 0; i -= 8) {
91
+ message.push((lengthLow >>> i) & 0xff);
92
+ }
93
+ // Convert byte array to 32-bit word array
94
+ const words = new Uint32Array(message.length / 4);
95
+ for (let i = 0; i < message.length; i += 4) {
96
+ words[i / 4] =
97
+ (message[i] << 24) | (message[i + 1] << 16) | (message[i + 2] << 8) | message[i + 3];
98
+ }
99
+ return words;
100
+ }
101
+ /** Process a single 512-bit chunk */
102
+ function processChunk(chunk, hash) {
103
+ const W = new Uint32Array(64);
104
+ // Prepare message schedule
105
+ for (let t = 0; t < 16; t++) {
106
+ W[t] = chunk[t];
107
+ }
108
+ for (let t = 16; t < 64; t++) {
109
+ W[t] = (gamma1(W[t - 2]) + W[t - 7] + gamma0(W[t - 15]) + W[t - 16]) >>> 0;
110
+ }
111
+ // Initialize working variables
112
+ let a = hash[0];
113
+ let b = hash[1];
114
+ let c = hash[2];
115
+ let d = hash[3];
116
+ let e = hash[4];
117
+ let f = hash[5];
118
+ let g = hash[6];
119
+ let h = hash[7];
120
+ // Main loop
121
+ for (let t = 0; t < 64; t++) {
122
+ const T1 = (h + sigma1(e) + ch(e, f, g) + K[t] + W[t]) >>> 0;
123
+ const T2 = (sigma0(a) + maj(a, b, c)) >>> 0;
124
+ h = g;
125
+ g = f;
126
+ f = e;
127
+ e = (d + T1) >>> 0;
128
+ d = c;
129
+ c = b;
130
+ b = a;
131
+ a = (T1 + T2) >>> 0;
132
+ }
133
+ // Add compressed chunk to current hash value
134
+ hash[0] = (hash[0] + a) >>> 0;
135
+ hash[1] = (hash[1] + b) >>> 0;
136
+ hash[2] = (hash[2] + c) >>> 0;
137
+ hash[3] = (hash[3] + d) >>> 0;
138
+ hash[4] = (hash[4] + e) >>> 0;
139
+ hash[5] = (hash[5] + f) >>> 0;
140
+ hash[6] = (hash[6] + g) >>> 0;
141
+ hash[7] = (hash[7] + h) >>> 0;
142
+ }
143
+ /** Compute SHA-256 hash and return as byte array */
144
+ function sha256Raw(message) {
145
+ const bytes = stringToBytes(message);
146
+ const preprocessed = preprocessMessage(bytes);
147
+ const hash = [...H]; // Copy initial hash values
148
+ // Process each 512-bit chunk
149
+ for (let i = 0; i < preprocessed.length; i += 16) {
150
+ const chunk = preprocessed.subarray(i, i + 16);
151
+ processChunk(chunk, hash);
152
+ }
153
+ // Convert hash to byte array
154
+ const result = [];
155
+ for (let i = 0; i < 8; i++) {
156
+ result.push((hash[i] >>> 24) & 0xff);
157
+ result.push((hash[i] >>> 16) & 0xff);
158
+ result.push((hash[i] >>> 8) & 0xff);
159
+ result.push(hash[i] & 0xff);
160
+ }
161
+ return result;
162
+ }
163
+ /** Hash result object with toString methods */
164
+ class HashResult {
165
+ bytes;
166
+ constructor(bytes) {
167
+ this.bytes = bytes;
168
+ }
169
+ /** Convert hash to hexadecimal string */
170
+ toString(encoding) {
171
+ if (encoding === Hex) {
172
+ return this.bytes.map(b => b.toString(16).padStart(2, '0')).join('');
173
+ }
174
+ // Default to hex if no encoding specified
175
+ return this.bytes.map(b => b.toString(16).padStart(2, '0')).join('');
176
+ }
177
+ }
178
+ /** Hex encoding object (mimics crypto-js enc.Hex) */
179
+ export const Hex = {
180
+ stringify: (bytes) => bytes.map(b => b.toString(16).padStart(2, '0')).join(''),
181
+ };
182
+ /**
183
+ * Compute SHA-256 hash of a string
184
+ * @param message - The message to hash
185
+ * @returns HashResult object with toString method
186
+ */
187
+ export function SHA256(message) {
188
+ const hash = sha256Raw(message);
189
+ return new HashResult(hash);
190
+ }
191
+ /** Encoding utilities (mimics crypto-js enc) */
192
+ export const enc = {
193
+ Hex,
194
+ };
195
+ //# sourceMappingURL=sha_256.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha_256.js","sourceRoot":"","sources":["../../src/utils/sha_256.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+BAA+B;AAE/B,qGAAqG;AACrG,MAAM,CAAC,GAAG;IACR,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;CAC/F,CAAA;AAED,wGAAwG;AACxG,MAAM,CAAC,GAAG;IACR,UAAU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,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACtE,CAAC;CACF;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,SAAS,EAAE,CAAC,KAAe,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;CACzF,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAC/B,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;AAC7B,CAAC;AAED,gDAAgD;AAChD,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,GAAG;CACJ,CAAA","sourcesContent":["/**\n * Pure JavaScript SHA-256 implementation\n * Conforms to the crypto-js API for drop-in replacement\n */\n\n/* eslint-disable no-bitwise */\n\n// SHA-256 constants (first 32 bits of the fractional parts of the cube roots of the first 64 primes)\nconst K = [\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\n]\n\n// Initial hash values (first 32 bits of the fractional parts of the square roots of the first 8 primes)\nconst H = [\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,\n]\n\n/** Right rotate 32-bit integer */\nfunction rotr(n: number, x: number): number {\n return (x >>> n) | (x << (32 - n))\n}\n\n/** SHA-256 choice function */\nfunction ch(x: number, y: number, z: number): number {\n return (x & y) ^ (~x & z)\n}\n\n/** SHA-256 majority function */\nfunction maj(x: number, y: number, z: number): number {\n return (x & y) ^ (x & z) ^ (y & z)\n}\n\n/** SHA-256 Σ0 function */\nfunction sigma0(x: number): number {\n return rotr(2, x) ^ rotr(13, x) ^ rotr(22, x)\n}\n\n/** SHA-256 Σ1 function */\nfunction sigma1(x: number): number {\n return rotr(6, x) ^ rotr(11, x) ^ rotr(25, x)\n}\n\n/** SHA-256 σ0 function */\nfunction gamma0(x: number): number {\n return rotr(7, x) ^ rotr(18, x) ^ (x >>> 3)\n}\n\n/** SHA-256 σ1 function */\nfunction gamma1(x: number): number {\n return rotr(17, x) ^ rotr(19, x) ^ (x >>> 10)\n}\n\n/** Convert string to UTF-8 byte array */\nfunction stringToBytes(str: string): number[] {\n const bytes: number[] = []\n for (let i = 0; i < str.length; i++) {\n let charCode = str.charCodeAt(i)\n if (charCode < 0x80) {\n bytes.push(charCode)\n } else if (charCode < 0x800) {\n bytes.push(0xc0 | (charCode >> 6), 0x80 | (charCode & 0x3f))\n } else if (charCode < 0xd800 || charCode >= 0xe000) {\n bytes.push(0xe0 | (charCode >> 12), 0x80 | ((charCode >> 6) & 0x3f), 0x80 | (charCode & 0x3f))\n } else {\n // Surrogate pair\n i++\n charCode = 0x10000 + (((charCode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff))\n bytes.push(\n 0xf0 | (charCode >> 18),\n 0x80 | ((charCode >> 12) & 0x3f),\n 0x80 | ((charCode >> 6) & 0x3f),\n 0x80 | (charCode & 0x3f)\n )\n }\n }\n return bytes\n}\n\n/** Preprocess message: pad and convert to 512-bit blocks */\nfunction preprocessMessage(message: number[]): Uint32Array {\n const messageLength = message.length\n const bitLength = messageLength * 8\n\n // Append the '1' bit (plus zero padding to make 8 bits)\n message.push(0x80)\n\n // Append zeros until message length ≡ 448 (mod 512)\n // This leaves 64 bits for the length\n while (message.length % 64 !== 56) {\n message.push(0x00)\n }\n\n // Append original message length as 64-bit big-endian integer\n // JavaScript numbers are 53-bit safe, so we split into two 32-bit parts\n const lengthHigh = Math.floor(bitLength / 0x100000000)\n const lengthLow = bitLength >>> 0\n\n for (let i = 24; i >= 0; i -= 8) {\n message.push((lengthHigh >>> i) & 0xff)\n }\n for (let i = 24; i >= 0; i -= 8) {\n message.push((lengthLow >>> i) & 0xff)\n }\n\n // Convert byte array to 32-bit word array\n const words = new Uint32Array(message.length / 4)\n for (let i = 0; i < message.length; i += 4) {\n words[i / 4] =\n (message[i] << 24) | (message[i + 1] << 16) | (message[i + 2] << 8) | message[i + 3]\n }\n\n return words\n}\n\n/** Process a single 512-bit chunk */\nfunction processChunk(chunk: Uint32Array, hash: number[]): void {\n const W = new Uint32Array(64)\n\n // Prepare message schedule\n for (let t = 0; t < 16; t++) {\n W[t] = chunk[t]\n }\n for (let t = 16; t < 64; t++) {\n W[t] = (gamma1(W[t - 2]) + W[t - 7] + gamma0(W[t - 15]) + W[t - 16]) >>> 0\n }\n\n // Initialize working variables\n let a = hash[0]\n let b = hash[1]\n let c = hash[2]\n let d = hash[3]\n let e = hash[4]\n let f = hash[5]\n let g = hash[6]\n let h = hash[7]\n\n // Main loop\n for (let t = 0; t < 64; t++) {\n const T1 = (h + sigma1(e) + ch(e, f, g) + K[t] + W[t]) >>> 0\n const T2 = (sigma0(a) + maj(a, b, c)) >>> 0\n h = g\n g = f\n f = e\n e = (d + T1) >>> 0\n d = c\n c = b\n b = a\n a = (T1 + T2) >>> 0\n }\n\n // Add compressed chunk to current hash value\n hash[0] = (hash[0] + a) >>> 0\n hash[1] = (hash[1] + b) >>> 0\n hash[2] = (hash[2] + c) >>> 0\n hash[3] = (hash[3] + d) >>> 0\n hash[4] = (hash[4] + e) >>> 0\n hash[5] = (hash[5] + f) >>> 0\n hash[6] = (hash[6] + g) >>> 0\n hash[7] = (hash[7] + h) >>> 0\n}\n\n/** Compute SHA-256 hash and return as byte array */\nfunction sha256Raw(message: string): number[] {\n const bytes = stringToBytes(message)\n const preprocessed = preprocessMessage(bytes)\n const hash = [...H] // Copy initial hash values\n\n // Process each 512-bit chunk\n for (let i = 0; i < preprocessed.length; i += 16) {\n const chunk = preprocessed.subarray(i, i + 16)\n processChunk(chunk, hash)\n }\n\n // Convert hash to byte array\n const result: number[] = []\n for (let i = 0; i < 8; i++) {\n result.push((hash[i] >>> 24) & 0xff)\n result.push((hash[i] >>> 16) & 0xff)\n result.push((hash[i] >>> 8) & 0xff)\n result.push(hash[i] & 0xff)\n }\n\n return result\n}\n\n/** Hash result object with toString methods */\nclass HashResult {\n private bytes: number[]\n\n constructor(bytes: number[]) {\n this.bytes = bytes\n }\n\n /** Convert hash to hexadecimal string */\n toString(encoding?: { stringify: (bytes: number[]) => string }): string {\n if (encoding === Hex) {\n return this.bytes.map(b => b.toString(16).padStart(2, '0')).join('')\n }\n // Default to hex if no encoding specified\n return this.bytes.map(b => b.toString(16).padStart(2, '0')).join('')\n }\n}\n\n/** Hex encoding object (mimics crypto-js enc.Hex) */\nexport const Hex = {\n stringify: (bytes: number[]) => bytes.map(b => b.toString(16).padStart(2, '0')).join(''),\n}\n\n/**\n * Compute SHA-256 hash of a string\n * @param message - The message to hash\n * @returns HashResult object with toString method\n */\nexport function SHA256(message: string): HashResult {\n const hash = sha256Raw(message)\n return new HashResult(hash)\n}\n\n/** Encoding utilities (mimics crypto-js enc) */\nexport const enc = {\n Hex,\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/chat-react-native",
3
- "version": "3.20.1-rc.1",
3
+ "version": "3.20.1-rc.3",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -58,5 +58,5 @@
58
58
  "react-native-url-polyfill": "^2.0.0",
59
59
  "typescript": "<5.6.0"
60
60
  },
61
- "gitHead": "e0a908049cd839fc176a02a3addbf94ec4b9a42d"
61
+ "gitHead": "7520f2d90eed9880665f5b10f74c99f2841dbf92"
62
62
  }
@@ -1,4 +1,5 @@
1
1
  import { renderHook } from '@testing-library/react-native'
2
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2
3
  import { useTheme } from '../../hooks'
3
4
  import { ChatProvider, CreateChatThemeProps } from '../../contexts/chat_context'
4
5
  import React from 'react'
@@ -10,24 +11,47 @@ let themeProps: CreateChatThemeProps = {
10
11
  colorScheme: 'light',
11
12
  }
12
13
 
14
+ let queryClient: QueryClient
15
+
16
+ beforeEach(() => {
17
+ queryClient = new QueryClient({
18
+ defaultOptions: {
19
+ queries: {
20
+ retry: false,
21
+ refetchInterval: false, // Disable refetch intervals in tests
22
+ refetchOnWindowFocus: false,
23
+ refetchOnReconnect: false,
24
+ },
25
+ },
26
+ })
27
+ })
28
+
29
+ afterEach(() => {
30
+ queryClient.clear()
31
+ queryClient.cancelQueries()
32
+ queryClient.removeQueries()
33
+ })
34
+
13
35
  const Wrapper = ({ children }: { children: React.ReactNode }) => {
14
36
  return (
15
- <ChatProvider
16
- value={{
17
- token: {
18
- access_token: '',
19
- created_at: 0,
20
- expires_in: 0,
21
- scope: '',
22
- refresh_token: '',
23
- token_type: '',
24
- },
25
- onUnauthorizedResponse: () => {},
26
- theme: themeProps,
27
- }}
28
- >
29
- {children}
30
- </ChatProvider>
37
+ <QueryClientProvider client={queryClient}>
38
+ <ChatProvider
39
+ value={{
40
+ token: {
41
+ access_token: '',
42
+ created_at: 0,
43
+ expires_in: 0,
44
+ scope: '',
45
+ refresh_token: '',
46
+ token_type: '',
47
+ },
48
+ onUnauthorizedResponse: () => {},
49
+ theme: themeProps,
50
+ }}
51
+ >
52
+ {children}
53
+ </ChatProvider>
54
+ </QueryClientProvider>
31
55
  )
32
56
  }
33
57
 
@@ -1,10 +1,12 @@
1
1
  import { merge } from 'lodash'
2
2
  import React, { createContext, useMemo } from 'react'
3
3
  import { ColorSchemeName, useColorScheme } from 'react-native'
4
- import { DeepPartial } from '../types'
5
- import { ENV, OauthType, PartialToken, ResponseError, Session } from '../utils'
4
+ import { useQuery } from '@tanstack/react-query'
5
+ import { ApiResource, DeepPartial } from '../types'
6
+ import { Client, ENV, OauthType, PartialToken, ResponseError, Session, Uri } from '../utils'
6
7
  import { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'
7
8
  import { AgeCheckContactInfo } from '../screens/age_check/screen_props'
9
+ import { ProductAnalyticsConfig } from '../types/product_analytics'
8
10
 
9
11
  export interface ChatProviderProps {
10
12
  env?: ENV
@@ -21,6 +23,7 @@ export interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {
21
23
  session: Session
22
24
  theme: ChatTheme
23
25
  onAgeDisqualification: (params: AgeCheckContactInfo) => void
26
+ productAnalyticsConfig: ProductAnalyticsConfig | undefined
24
27
  }
25
28
 
26
29
  export const ChatContext = createContext<ChatContextValue>({
@@ -32,6 +35,7 @@ export const ChatContext = createContext<ChatContextValue>({
32
35
  theme: defaultTheme('light'),
33
36
  token: undefined,
34
37
  edgeToEdge: true,
38
+ productAnalyticsConfig: undefined,
35
39
  })
36
40
 
37
41
  export function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {
@@ -50,7 +54,9 @@ export function ChatProvider({ children, value }: { children: any; value: ChatPr
50
54
  [env, token, tokenType]
51
55
  )
52
56
 
57
+ const productAnalyticsConfig = useProductAnalyticsConfig(session)
53
58
  const contextValue: ChatContextValue = {
59
+ ...value,
54
60
  edgeToEdge,
55
61
  env,
56
62
  giphyApiKey,
@@ -59,6 +65,7 @@ export function ChatProvider({ children, value }: { children: any; value: ChatPr
59
65
  session,
60
66
  theme,
61
67
  token,
68
+ productAnalyticsConfig,
62
69
  }
63
70
 
64
71
  return <ChatContext.Provider value={contextValue}>{children}</ChatContext.Provider>
@@ -89,3 +96,53 @@ export const useCreateChatTheme = ({
89
96
 
90
97
  return theme
91
98
  }
99
+
100
+ interface ProductAnalyticsTokenResponse {
101
+ type: 'ProductAnalyticsToken'
102
+ id: string
103
+ url: string
104
+ metadata: Record<string, unknown>
105
+ }
106
+
107
+ // expiry time comes from here:
108
+ // https://github.com/planningcenter/pco-product-analytics/blob/e5bbc4c31b715b3c329c06a162829ee6967d3094/lib/pco/product/analytics/client_token_provider.rb#L24
109
+ const TOKEN_EXPIRY_TIME = 604800 * 1000 // 7 days in milliseconds
110
+
111
+ const useProductAnalyticsConfig = (session: Session): ProductAnalyticsConfig | undefined => {
112
+ const uri = useMemo(() => new Uri({ session }), [session])
113
+ const apiClient = useMemo(
114
+ () =>
115
+ new Client({
116
+ root: uri.api(`/chat/v2`),
117
+ defaultHeaders: uri.headers,
118
+ version: '2018-11-01',
119
+ }),
120
+ [uri]
121
+ )
122
+
123
+ const { data: config } = useQuery<ProductAnalyticsConfig>({
124
+ queryKey: ['product-analytics-token'],
125
+ queryFn: () =>
126
+ apiClient
127
+ .post<ApiResource<ProductAnalyticsTokenResponse>>({
128
+ url: '/me/product_analytics_authorize',
129
+ data: {
130
+ data: {
131
+ type: 'ProductAnalyticsToken',
132
+ attributes: {},
133
+ },
134
+ },
135
+ })
136
+ .then(res => ({
137
+ token: res.data.id,
138
+ endpoint: res.data.url,
139
+ metadata: res.data.metadata,
140
+ })),
141
+ staleTime: TOKEN_EXPIRY_TIME,
142
+ gcTime: TOKEN_EXPIRY_TIME,
143
+ refetchInterval: TOKEN_EXPIRY_TIME,
144
+ enabled: process.env.NODE_ENV !== 'test',
145
+ })
146
+
147
+ return config
148
+ }
@@ -18,3 +18,4 @@ export * from './use_qualified_by_age'
18
18
  export * from './use_scalable_number_of_lines'
19
19
  export * from './use_submit_age_check'
20
20
  export * from './use_organization'
21
+ export * from './use_product_analytics'
@@ -12,6 +12,7 @@ export const getConversationRequestArgs = ({ conversation_id }: { conversation_i
12
12
  data: {
13
13
  fields: {
14
14
  Conversation: [
15
+ 'analytics_metadata',
15
16
  'created_at',
16
17
  'badges',
17
18
  'conversation_membership',
@@ -29,6 +30,7 @@ export const getConversationRequestArgs = ({ conversation_id }: { conversation_i
29
30
  'unread_count',
30
31
  'updated_at',
31
32
  ],
33
+ AnalyticsMetadata: ['metadata'],
32
34
  MemberAbility: [
33
35
  'can_update',
34
36
  'can_delete',
@@ -40,12 +42,20 @@ export const getConversationRequestArgs = ({ conversation_id }: { conversation_i
40
42
  ConversationBadge: ['app_name', 'pco_resource_type', 'text'],
41
43
  Group: ['type', 'id', 'links', 'name', 'source_app_name', 'source_type'],
42
44
  },
43
- include: ['badges', 'conversation_membership', 'member_ability', 'groups'],
45
+ include: [
46
+ 'badges',
47
+ 'conversation_membership',
48
+ 'member_ability',
49
+ 'groups',
50
+ 'analytics_metadata',
51
+ ],
44
52
  },
45
53
  })
46
54
 
47
55
  export const useConversation = ({ conversation_id }: { conversation_id: number }) => {
48
- return useSuspenseGet<ConversationResource>(getConversationRequestArgs({ conversation_id }))
56
+ const args = getConversationRequestArgs({ conversation_id })
57
+
58
+ return useSuspenseGet<ConversationResource>(args)
49
59
  }
50
60
 
51
61
  export const useConversationMute = ({ conversation_id }: { conversation_id: number }) => {
@@ -43,7 +43,7 @@ export function useMessageCreateOrUpdate({ conversationId, message, replyRootId
43
43
  let attributes: any = {
44
44
  text,
45
45
  ...(attachments ? { attachments } : {}),
46
- ...(replyRootId ? { reply_root: { id: replyRootId } } : {}),
46
+ ...(!isEditing && replyRootId ? { reply_root: { id: replyRootId } } : {}),
47
47
  }
48
48
  if (!isEditing) {
49
49
  const idempotentKey = insecureUUID()
@@ -83,6 +83,7 @@ export function useMessageCreateOrUpdate({ conversationId, message, replyRootId
83
83
  conversationId,
84
84
  message,
85
85
  text,
86
+ replyRootId,
86
87
  })
87
88
 
88
89
  return { message: optimisticMessage }
@@ -0,0 +1,107 @@
1
+ import { useCallback, useEffect, useMemo, useRef } from 'react'
2
+ import { SHA256, enc } from '../utils/sha_256'
3
+ import { useChatContext } from '../contexts/chat_context'
4
+ import { ProductAnalyticsConfig } from '../types/product_analytics'
5
+ import { keysToSnakeCase } from '../utils/client/utils'
6
+ import { AnalyticsMetadataResource } from '../types/resources/analytics_metadata'
7
+
8
+ export interface EventMetadata {
9
+ [key: string]: string | number | boolean | null | undefined
10
+ }
11
+
12
+ interface AnalyticsEvent {
13
+ name: string
14
+ meta: EventMetadata
15
+ }
16
+
17
+ function contentSha256(payload: string): string {
18
+ return SHA256(payload).toString(enc.Hex)
19
+ }
20
+
21
+ function sendEvents(events: AnalyticsEvent[], config: ProductAnalyticsConfig): Promise<Response[]> {
22
+ // Split into chunks of 10 and make parallel requests
23
+ const chunks: AnalyticsEvent[][] = []
24
+ for (let i = 0; i < events.length; i += 10) {
25
+ chunks.push(events.slice(i, i + 10))
26
+ }
27
+
28
+ return Promise.all(
29
+ chunks.map(async chunk => {
30
+ const payload = JSON.stringify({ events: chunk })
31
+ return fetch(config.endpoint, {
32
+ method: 'POST',
33
+ headers: {
34
+ 'Content-Type': 'application/json; charset=utf-8',
35
+ 'X-Authorization': `Bearer ${config.token}`,
36
+ 'X-Amz-Content-Sha256': contentSha256(payload),
37
+ },
38
+ body: payload,
39
+ })
40
+ })
41
+ )
42
+ }
43
+
44
+ const useProductAnalytics = () => {
45
+ const { productAnalyticsConfig } = useChatContext()
46
+
47
+ const snakeCasedBaseMeta = useMemo(
48
+ () => keysToSnakeCase(productAnalyticsConfig?.metadata || {}),
49
+ [productAnalyticsConfig?.metadata]
50
+ )
51
+
52
+ const publishEvent = useCallback(
53
+ (name: string, meta: EventMetadata = {}): Promise<Response[]> => {
54
+ if (!productAnalyticsConfig) {
55
+ if (__DEV__) {
56
+ console.warn('Product Analytics not available')
57
+ }
58
+ return Promise.resolve([])
59
+ }
60
+
61
+ const mergedMeta = { ...snakeCasedBaseMeta, ...meta } as EventMetadata
62
+
63
+ return sendEvents([{ name, meta: mergedMeta }], productAnalyticsConfig)
64
+ },
65
+ [productAnalyticsConfig, snakeCasedBaseMeta]
66
+ )
67
+
68
+ const publishEvents = useCallback(
69
+ (events: Array<{ name: string; meta?: EventMetadata }>): Promise<Response[]> => {
70
+ if (!productAnalyticsConfig) {
71
+ if (__DEV__) {
72
+ console.warn('Product Analytics not available')
73
+ }
74
+ return Promise.resolve([])
75
+ }
76
+
77
+ const eventsWithMeta = events.map(event => ({
78
+ name: event.name,
79
+ meta: { ...snakeCasedBaseMeta, ...event.meta } as EventMetadata,
80
+ }))
81
+
82
+ return sendEvents(eventsWithMeta, productAnalyticsConfig)
83
+ },
84
+ [productAnalyticsConfig, snakeCasedBaseMeta]
85
+ )
86
+
87
+ return { publishEvent, publishEvents }
88
+ }
89
+
90
+ export function usePublishProductAnalyticsEvent(eventName: string, meta: EventMetadata = {}) {
91
+ const { publishEvent } = useProductAnalytics()
92
+ const hasPublishedEventRef = useRef(false)
93
+
94
+ useEffect(() => {
95
+ if (hasPublishedEventRef.current) return
96
+
97
+ hasPublishedEventRef.current = true
98
+
99
+ publishEvent(eventName, meta)
100
+ }, [eventName, meta, publishEvent])
101
+ }
102
+
103
+ export function normalizeAnalyticsMetadata(resource: {
104
+ analyticsMetadata?: AnalyticsMetadataResource
105
+ }) {
106
+ return keysToSnakeCase(resource?.analyticsMetadata?.metadata || {}) as Record<string, unknown>
107
+ }
@@ -14,7 +14,7 @@ import { ResponseError } from '../utils/response_error'
14
14
 
15
15
  interface SuspenseGetOptions extends GetRequest {
16
16
  app?: App
17
- reply_root_id?: string
17
+ reply_root_id?: string | null
18
18
  }
19
19
 
20
20
  export type SuspenseGetQueryOptions<T extends ResourceObject | ResourceObject[]> = Omit<
@@ -24,6 +24,10 @@ import { MessageForm } from '../components/conversation/message_form'
24
24
  import { TypingIndicator } from '../components/conversation/typing_indicator'
25
25
  import { KeyboardView } from '../components/display/keyboard_view'
26
26
  import { useTheme } from '../hooks'
27
+ import {
28
+ normalizeAnalyticsMetadata,
29
+ usePublishProductAnalyticsEvent,
30
+ } from '../hooks/use_product_analytics'
27
31
  import { useConversation } from '../hooks/use_conversation'
28
32
  import { useConversationMessages } from '../hooks/use_conversation_messages'
29
33
  import { useConversationMessagesJoltEvents } from '../hooks/use_conversation_messages_jolt_events'
@@ -56,6 +60,13 @@ export type ConversationScreenProps = StaticScreenProps<ConversationRouteProps>
56
60
  export function ConversationScreen({ route }: ConversationScreenProps) {
57
61
  const { conversation_id, reply_root_id } = route.params
58
62
 
63
+ const { data: conversation } = useConversation({ conversation_id })
64
+
65
+ usePublishProductAnalyticsEvent('chat.mobile.conversations.show.opened', {
66
+ reply_root_id,
67
+ ...normalizeAnalyticsMetadata(conversation),
68
+ })
69
+
59
70
  return (
60
71
  <ConversationContextProvider
61
72
  conversationId={conversation_id}