@ariaflowagents/messaging-meta 0.8.1

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 (106) hide show
  1. package/README.md +236 -0
  2. package/dist/graph-api/client.d.ts +125 -0
  3. package/dist/graph-api/client.d.ts.map +1 -0
  4. package/dist/graph-api/client.js +204 -0
  5. package/dist/graph-api/client.js.map +1 -0
  6. package/dist/graph-api/errors.d.ts +41 -0
  7. package/dist/graph-api/errors.d.ts.map +1 -0
  8. package/dist/graph-api/errors.js +72 -0
  9. package/dist/graph-api/errors.js.map +1 -0
  10. package/dist/graph-api/index.d.ts +15 -0
  11. package/dist/graph-api/index.d.ts.map +1 -0
  12. package/dist/graph-api/index.js +11 -0
  13. package/dist/graph-api/index.js.map +1 -0
  14. package/dist/graph-api/rate-limiter.d.ts +90 -0
  15. package/dist/graph-api/rate-limiter.d.ts.map +1 -0
  16. package/dist/graph-api/rate-limiter.js +172 -0
  17. package/dist/graph-api/rate-limiter.js.map +1 -0
  18. package/dist/graph-api/retry.d.ts +55 -0
  19. package/dist/graph-api/retry.d.ts.map +1 -0
  20. package/dist/graph-api/retry.js +103 -0
  21. package/dist/graph-api/retry.js.map +1 -0
  22. package/dist/index.d.ts +36 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +38 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/instagram/client.d.ts +365 -0
  27. package/dist/instagram/client.d.ts.map +1 -0
  28. package/dist/instagram/client.js +857 -0
  29. package/dist/instagram/client.js.map +1 -0
  30. package/dist/instagram/format.d.ts +62 -0
  31. package/dist/instagram/format.d.ts.map +1 -0
  32. package/dist/instagram/format.js +92 -0
  33. package/dist/instagram/format.js.map +1 -0
  34. package/dist/instagram/ice-breakers.d.ts +63 -0
  35. package/dist/instagram/ice-breakers.d.ts.map +1 -0
  36. package/dist/instagram/ice-breakers.js +87 -0
  37. package/dist/instagram/ice-breakers.js.map +1 -0
  38. package/dist/instagram/index.d.ts +44 -0
  39. package/dist/instagram/index.d.ts.map +1 -0
  40. package/dist/instagram/index.js +46 -0
  41. package/dist/instagram/index.js.map +1 -0
  42. package/dist/instagram/types.d.ts +188 -0
  43. package/dist/instagram/types.d.ts.map +1 -0
  44. package/dist/instagram/types.js +19 -0
  45. package/dist/instagram/types.js.map +1 -0
  46. package/dist/messenger/client.d.ts +339 -0
  47. package/dist/messenger/client.d.ts.map +1 -0
  48. package/dist/messenger/client.js +782 -0
  49. package/dist/messenger/client.js.map +1 -0
  50. package/dist/messenger/format.d.ts +69 -0
  51. package/dist/messenger/format.d.ts.map +1 -0
  52. package/dist/messenger/format.js +98 -0
  53. package/dist/messenger/format.js.map +1 -0
  54. package/dist/messenger/index.d.ts +34 -0
  55. package/dist/messenger/index.d.ts.map +1 -0
  56. package/dist/messenger/index.js +35 -0
  57. package/dist/messenger/index.js.map +1 -0
  58. package/dist/messenger/types.d.ts +181 -0
  59. package/dist/messenger/types.d.ts.map +1 -0
  60. package/dist/messenger/types.js +10 -0
  61. package/dist/messenger/types.js.map +1 -0
  62. package/dist/server.d.ts +31 -0
  63. package/dist/server.d.ts.map +1 -0
  64. package/dist/server.js +29 -0
  65. package/dist/server.js.map +1 -0
  66. package/dist/webhook/index.d.ts +10 -0
  67. package/dist/webhook/index.d.ts.map +1 -0
  68. package/dist/webhook/index.js +8 -0
  69. package/dist/webhook/index.js.map +1 -0
  70. package/dist/webhook/normalizer.d.ts +169 -0
  71. package/dist/webhook/normalizer.d.ts.map +1 -0
  72. package/dist/webhook/normalizer.js +301 -0
  73. package/dist/webhook/normalizer.js.map +1 -0
  74. package/dist/webhook/verifier.d.ts +45 -0
  75. package/dist/webhook/verifier.d.ts.map +1 -0
  76. package/dist/webhook/verifier.js +62 -0
  77. package/dist/webhook/verifier.js.map +1 -0
  78. package/dist/whatsapp/client.d.ts +481 -0
  79. package/dist/whatsapp/client.d.ts.map +1 -0
  80. package/dist/whatsapp/client.js +1043 -0
  81. package/dist/whatsapp/client.js.map +1 -0
  82. package/dist/whatsapp/flows.d.ts +74 -0
  83. package/dist/whatsapp/flows.d.ts.map +1 -0
  84. package/dist/whatsapp/flows.js +77 -0
  85. package/dist/whatsapp/flows.js.map +1 -0
  86. package/dist/whatsapp/format.d.ts +78 -0
  87. package/dist/whatsapp/format.d.ts.map +1 -0
  88. package/dist/whatsapp/format.js +195 -0
  89. package/dist/whatsapp/format.js.map +1 -0
  90. package/dist/whatsapp/index.d.ts +39 -0
  91. package/dist/whatsapp/index.d.ts.map +1 -0
  92. package/dist/whatsapp/index.js +42 -0
  93. package/dist/whatsapp/index.js.map +1 -0
  94. package/dist/whatsapp/split.d.ts +35 -0
  95. package/dist/whatsapp/split.d.ts.map +1 -0
  96. package/dist/whatsapp/split.js +76 -0
  97. package/dist/whatsapp/split.js.map +1 -0
  98. package/dist/whatsapp/templates.d.ts +129 -0
  99. package/dist/whatsapp/templates.d.ts.map +1 -0
  100. package/dist/whatsapp/templates.js +125 -0
  101. package/dist/whatsapp/templates.js.map +1 -0
  102. package/dist/whatsapp/types.d.ts +440 -0
  103. package/dist/whatsapp/types.d.ts.map +1 -0
  104. package/dist/whatsapp/types.js +11 -0
  105. package/dist/whatsapp/types.js.map +1 -0
  106. package/package.json +31 -0
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @module whatsapp/split
3
+ *
4
+ * Smart message splitting for WhatsApp's 4096-character limit.
5
+ *
6
+ * Splits long messages at natural boundaries (paragraph breaks, line breaks)
7
+ * to maintain readability. Falls back to hard splitting only when no natural
8
+ * boundary exists within the allowed range.
9
+ */
10
+ /** Maximum character length for a single WhatsApp text message. */
11
+ const MAX_LENGTH = 4096;
12
+ /**
13
+ * Split a text message into chunks that fit within WhatsApp's character limit.
14
+ *
15
+ * The splitting strategy prioritises readability:
16
+ * 1. Paragraph boundaries (`\n\n`) within the first `maxLength` characters.
17
+ * 2. Line boundaries (`\n`) if no paragraph break is available.
18
+ * 3. Word boundaries (last space character) as a third preference.
19
+ * 4. Hard split at `maxLength` as a last resort.
20
+ *
21
+ * A split point is only used if it falls in the latter half of the chunk
22
+ * to avoid producing very short fragments.
23
+ *
24
+ * @param text - The full message text.
25
+ * @param maxLength - Maximum characters per chunk. Default `4096`.
26
+ * @returns An array of text chunks, each within `maxLength`.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const chunks = splitMessage(longReport);
31
+ * for (const chunk of chunks) {
32
+ * await client.sendText(to, chunk);
33
+ * }
34
+ * ```
35
+ */
36
+ export function splitMessage(text, maxLength = MAX_LENGTH) {
37
+ if (text.length <= maxLength) {
38
+ return [text];
39
+ }
40
+ const chunks = [];
41
+ let remaining = text;
42
+ const minSplit = Math.floor(maxLength / 2);
43
+ while (remaining.length > maxLength) {
44
+ let splitIndex = -1;
45
+ // 1. Try paragraph boundary (\n\n)
46
+ splitIndex = remaining.lastIndexOf('\n\n', maxLength);
47
+ if (splitIndex > 0 && splitIndex >= minSplit) {
48
+ // Include the first newline as part of the chunk
49
+ chunks.push(remaining.slice(0, splitIndex).trimEnd());
50
+ remaining = remaining.slice(splitIndex + 2).trimStart();
51
+ continue;
52
+ }
53
+ // 2. Try line boundary (\n)
54
+ splitIndex = remaining.lastIndexOf('\n', maxLength);
55
+ if (splitIndex > 0 && splitIndex >= minSplit) {
56
+ chunks.push(remaining.slice(0, splitIndex).trimEnd());
57
+ remaining = remaining.slice(splitIndex + 1).trimStart();
58
+ continue;
59
+ }
60
+ // 3. Try word boundary (space)
61
+ splitIndex = remaining.lastIndexOf(' ', maxLength);
62
+ if (splitIndex > 0 && splitIndex >= minSplit) {
63
+ chunks.push(remaining.slice(0, splitIndex).trimEnd());
64
+ remaining = remaining.slice(splitIndex + 1).trimStart();
65
+ continue;
66
+ }
67
+ // 4. Hard split at max length
68
+ chunks.push(remaining.slice(0, maxLength));
69
+ remaining = remaining.slice(maxLength);
70
+ }
71
+ if (remaining.length > 0) {
72
+ chunks.push(remaining);
73
+ }
74
+ return chunks;
75
+ }
76
+ //# sourceMappingURL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CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACtD,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;YACxD,SAAS;QACX,CAAC;QAED,+BAA+B;QAC/B,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACnD,IAAI,UAAU,GAAG,CAAC,IAAI,UAAU,IAAI,QAAQ,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACtD,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;YACxD,SAAS;QACX,CAAC;QAED,8BAA8B;QAC9B,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;QAC3C,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @module whatsapp/templates
3
+ *
4
+ * Builder utilities for constructing WhatsApp template message payloads.
5
+ *
6
+ * Provides both a **typed builder** (structured config with type-safe
7
+ * header/body/button definitions) and a **raw builder** (passthrough with
8
+ * minimal normalization) for maximum flexibility.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // Typed builder
13
+ * const payload = buildTemplateSendPayload({
14
+ * name: 'order_confirmation',
15
+ * language: 'en_US',
16
+ * body: [
17
+ * { type: 'text', text: 'John' },
18
+ * { type: 'text', text: 'ORD-12345' },
19
+ * ],
20
+ * });
21
+ *
22
+ * await client.sendTemplate(to, payload);
23
+ * ```
24
+ */
25
+ import type { TemplateMessage, TemplateComponent, TemplateParameter, MediaObject } from './types.js';
26
+ /**
27
+ * Typed configuration for building a template send payload.
28
+ *
29
+ * Provides a structured way to specify header, body, and button parameters
30
+ * without manually constructing the `components` array.
31
+ */
32
+ export interface TypedTemplateConfig {
33
+ /** Template name (must match an approved template). */
34
+ name: string;
35
+ /** BCP 47 language code (e.g. `"en_US"`). */
36
+ language: string;
37
+ /** Header parameter — text or media. */
38
+ header?: {
39
+ type: 'text';
40
+ text: string;
41
+ } | {
42
+ type: 'image';
43
+ image: MediaObject;
44
+ } | {
45
+ type: 'video';
46
+ video: MediaObject;
47
+ } | {
48
+ type: 'document';
49
+ document: MediaObject;
50
+ };
51
+ /** Body parameters (positional, matching `{{1}}`, `{{2}}`, etc.). */
52
+ body?: TemplateParameter[];
53
+ /** Button parameters (for dynamic URL suffixes or quick-reply payloads). */
54
+ buttons?: Array<{
55
+ /** Must be `"button"`. */
56
+ type: 'button';
57
+ /** Button sub-type (e.g. `"url"`, `"quick_reply"`). */
58
+ subType: string;
59
+ /** Zero-based button index. */
60
+ index: number;
61
+ /** Parameters for this button. */
62
+ parameters: TemplateParameter[];
63
+ }>;
64
+ }
65
+ /**
66
+ * Build a template message payload from a typed configuration.
67
+ *
68
+ * Converts the structured {@link TypedTemplateConfig} into Meta's
69
+ * `components` array format for the WhatsApp Cloud API.
70
+ *
71
+ * @param config - The typed template configuration.
72
+ * @returns A {@link TemplateMessage} ready to send via the API.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const payload = buildTemplateSendPayload({
77
+ * name: 'hello_world',
78
+ * language: 'en_US',
79
+ * header: { type: 'text', text: 'Welcome!' },
80
+ * body: [
81
+ * { type: 'text', text: 'John Doe' },
82
+ * ],
83
+ * buttons: [
84
+ * { type: 'button', subType: 'url', index: 0, parameters: [{ type: 'text', text: '/track/123' }] },
85
+ * ],
86
+ * });
87
+ * ```
88
+ */
89
+ export declare function buildTemplateSendPayload(config: TypedTemplateConfig): TemplateMessage;
90
+ /**
91
+ * Raw template components configuration.
92
+ *
93
+ * A minimal wrapper around Meta's native `components` format for cases
94
+ * where the caller wants full control over the payload structure.
95
+ */
96
+ export interface RawTemplateComponents {
97
+ /** Template name. */
98
+ name: string;
99
+ /** Language specification. */
100
+ language: {
101
+ code: string;
102
+ policy?: string;
103
+ };
104
+ /** Raw components array in Meta's format. */
105
+ components: TemplateComponent[];
106
+ }
107
+ /**
108
+ * Build a template message payload from raw components.
109
+ *
110
+ * This is a passthrough builder that accepts Meta's native format directly,
111
+ * performing only minimal validation. Use this when you need full control
112
+ * over the payload or when the typed builder does not cover a specific case.
113
+ *
114
+ * @param config - The raw template configuration.
115
+ * @returns A {@link TemplateMessage} ready to send via the API.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const payload = buildTemplatePayload({
120
+ * name: 'custom_template',
121
+ * language: { code: 'en' },
122
+ * components: [
123
+ * { type: 'body', parameters: [{ type: 'text', text: 'Hello' }] },
124
+ * ],
125
+ * });
126
+ * ```
127
+ */
128
+ export declare function buildTemplatePayload(config: RawTemplateComponents): TemplateMessage;
129
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/whatsapp/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACZ,MAAM,YAAY,CAAC;AAMpB;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,MAAM,CAAC,EACH;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC9B;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,WAAW,CAAA;KAAE,GACrC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,WAAW,CAAA;KAAE,GACrC;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,WAAW,CAAA;KAAE,CAAC;IAChD,qEAAqE;IACrE,IAAI,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC3B,4EAA4E;IAC5E,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,0BAA0B;QAC1B,IAAI,EAAE,QAAQ,CAAC;QACf,uDAAuD;QACvD,OAAO,EAAE,MAAM,CAAC;QAChB,+BAA+B;QAC/B,KAAK,EAAE,MAAM,CAAC;QACd,kCAAkC;QAClC,UAAU,EAAE,iBAAiB,EAAE,CAAC;KACjC,CAAC,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,mBAAmB,GAAG,eAAe,CAqDrF;AAMD;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,6CAA6C;IAC7C,UAAU,EAAE,iBAAiB,EAAE,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,qBAAqB,GAAG,eAAe,CAMnF"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @module whatsapp/templates
3
+ *
4
+ * Builder utilities for constructing WhatsApp template message payloads.
5
+ *
6
+ * Provides both a **typed builder** (structured config with type-safe
7
+ * header/body/button definitions) and a **raw builder** (passthrough with
8
+ * minimal normalization) for maximum flexibility.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * // Typed builder
13
+ * const payload = buildTemplateSendPayload({
14
+ * name: 'order_confirmation',
15
+ * language: 'en_US',
16
+ * body: [
17
+ * { type: 'text', text: 'John' },
18
+ * { type: 'text', text: 'ORD-12345' },
19
+ * ],
20
+ * });
21
+ *
22
+ * await client.sendTemplate(to, payload);
23
+ * ```
24
+ */
25
+ /**
26
+ * Build a template message payload from a typed configuration.
27
+ *
28
+ * Converts the structured {@link TypedTemplateConfig} into Meta's
29
+ * `components` array format for the WhatsApp Cloud API.
30
+ *
31
+ * @param config - The typed template configuration.
32
+ * @returns A {@link TemplateMessage} ready to send via the API.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const payload = buildTemplateSendPayload({
37
+ * name: 'hello_world',
38
+ * language: 'en_US',
39
+ * header: { type: 'text', text: 'Welcome!' },
40
+ * body: [
41
+ * { type: 'text', text: 'John Doe' },
42
+ * ],
43
+ * buttons: [
44
+ * { type: 'button', subType: 'url', index: 0, parameters: [{ type: 'text', text: '/track/123' }] },
45
+ * ],
46
+ * });
47
+ * ```
48
+ */
49
+ export function buildTemplateSendPayload(config) {
50
+ const components = [];
51
+ // Header component
52
+ if (config.header) {
53
+ const headerComponent = {
54
+ type: 'header',
55
+ parameters: [],
56
+ };
57
+ switch (config.header.type) {
58
+ case 'text':
59
+ headerComponent.parameters = [{ type: 'text', text: config.header.text }];
60
+ break;
61
+ case 'image':
62
+ headerComponent.parameters = [{ type: 'image', image: config.header.image }];
63
+ break;
64
+ case 'video':
65
+ headerComponent.parameters = [{ type: 'video', video: config.header.video }];
66
+ break;
67
+ case 'document':
68
+ headerComponent.parameters = [{ type: 'document', document: config.header.document }];
69
+ break;
70
+ }
71
+ components.push(headerComponent);
72
+ }
73
+ // Body component
74
+ if (config.body && config.body.length > 0) {
75
+ components.push({
76
+ type: 'body',
77
+ parameters: config.body,
78
+ });
79
+ }
80
+ // Button components
81
+ if (config.buttons) {
82
+ for (const button of config.buttons) {
83
+ components.push({
84
+ type: 'button',
85
+ sub_type: button.subType,
86
+ index: button.index,
87
+ parameters: button.parameters,
88
+ });
89
+ }
90
+ }
91
+ return {
92
+ name: config.name,
93
+ language: { code: config.language },
94
+ components: components.length > 0 ? components : undefined,
95
+ };
96
+ }
97
+ /**
98
+ * Build a template message payload from raw components.
99
+ *
100
+ * This is a passthrough builder that accepts Meta's native format directly,
101
+ * performing only minimal validation. Use this when you need full control
102
+ * over the payload or when the typed builder does not cover a specific case.
103
+ *
104
+ * @param config - The raw template configuration.
105
+ * @returns A {@link TemplateMessage} ready to send via the API.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const payload = buildTemplatePayload({
110
+ * name: 'custom_template',
111
+ * language: { code: 'en' },
112
+ * components: [
113
+ * { type: 'body', parameters: [{ type: 'text', text: 'Hello' }] },
114
+ * ],
115
+ * });
116
+ * ```
117
+ */
118
+ export function buildTemplatePayload(config) {
119
+ return {
120
+ name: config.name,
121
+ language: config.language,
122
+ components: config.components,
123
+ };
124
+ }
125
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/whatsapp/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AA6CH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAA2B;IAClE,MAAM,UAAU,GAAwB,EAAE,CAAC;IAE3C,mBAAmB;IACnB,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,eAAe,GAAsB;YACzC,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;SACf,CAAC;QAEF,QAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC3B,KAAK,MAAM;gBACT,eAAe,CAAC,UAAU,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC1E,MAAM;YACR,KAA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