@distilled.cloud/whatsapp 0.0.0 → 1.0.0-rc.21
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/LICENSE +201 -0
- package/README.md +139 -4
- package/lib/.lazy.json +1 -0
- package/lib/_bundle/lazy.js +4 -0
- package/lib/_bundle/sdk.js +2 -0
- package/lib/_bundle/sdk.js.map +1 -0
- package/lib/credentials.d.ts +67 -0
- package/lib/credentials.d.ts.map +1 -0
- package/lib/credentials.js +1 -0
- package/lib/errors.d.ts +48 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +1 -0
- package/lib/index.d.ts +35 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.lazy.js +8 -0
- package/lib/index.lazy.js.map +1 -0
- package/lib/pagination.d.ts +5 -0
- package/lib/pagination.d.ts.map +1 -0
- package/lib/pagination.js +1 -0
- package/lib/protocol.d.ts +19 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +1 -0
- package/lib/retry.d.ts +53 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +1 -0
- package/lib/services/index.d.ts +2 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +1 -0
- package/lib/services/whatsapp.d.ts +4131 -0
- package/lib/services/whatsapp.d.ts.map +1 -0
- package/lib/services/whatsapp.js +160 -0
- package/lib/services/whatsapp.js.map +1 -0
- package/lib/services.lazy/index.js +3 -0
- package/lib/services.lazy/whatsapp.js +4 -0
- package/lib/traits.d.ts +7 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +1 -0
- package/package.json +84 -2
- package/src/credentials.ts +123 -0
- package/src/errors.ts +62 -0
- package/src/index.ts +45 -0
- package/src/pagination.ts +73 -0
- package/src/protocol.ts +72 -0
- package/src/retry.ts +72 -0
- package/src/services/index.ts +2 -0
- package/src/services/whatsapp.ts +9925 -0
- package/src/traits.ts +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,9 +1,144 @@
|
|
|
1
1
|
# @distilled.cloud/whatsapp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Effect-native [WhatsApp Business Platform](https://developers.facebook.com/documentation/business-messaging/whatsapp/)
|
|
4
|
+
SDK, generated from Meta's official OpenAPI description,
|
|
5
|
+
[`facebook/openapi`](https://github.com/facebook/openapi)
|
|
6
|
+
(`business-messaging-api_v23.0.yaml`). It covers the Cloud API on
|
|
7
|
+
`graph.facebook.com`: 111 operations for messages, media, templates, phone
|
|
8
|
+
numbers, business profiles, Flows, groups, calling, WhatsApp Business
|
|
9
|
+
Accounts, and Tech Provider and Multi-Partner Solution management.
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
## Installation
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
```bash
|
|
14
|
+
npm install @distilled.cloud/whatsapp effect
|
|
15
|
+
```
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { Effect, Layer } from "effect";
|
|
21
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
22
|
+
import * as WhatsApp from "@distilled.cloud/whatsapp";
|
|
23
|
+
|
|
24
|
+
// The business phone number that sends, from WhatsApp Manager or
|
|
25
|
+
// `getWhatsAppBusinessAccountPhoneNumbers`.
|
|
26
|
+
const Phone_Number_ID = "106540352242922";
|
|
27
|
+
|
|
28
|
+
const program = Effect.gen(function* () {
|
|
29
|
+
const number = yield* WhatsApp.getPhoneNumber({ Phone_Number_ID });
|
|
30
|
+
|
|
31
|
+
const sent = yield* WhatsApp.sendMessage({
|
|
32
|
+
Phone_Number_ID,
|
|
33
|
+
body: {
|
|
34
|
+
messaging_product: "whatsapp",
|
|
35
|
+
recipient_type: "individual",
|
|
36
|
+
to: "16505551234",
|
|
37
|
+
type: "text",
|
|
38
|
+
text: { body: "Hello from Effect" },
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Typed failures: an unknown phone number ID is a BadRequest or NotFound.
|
|
43
|
+
const missing = yield* WhatsApp.getPhoneNumber({ Phone_Number_ID: "0" }).pipe(
|
|
44
|
+
Effect.map(() => false),
|
|
45
|
+
Effect.catchTags({
|
|
46
|
+
BadRequest: () => Effect.succeed(true),
|
|
47
|
+
NotFound: () => Effect.succeed(true),
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
from: number.display_phone_number,
|
|
53
|
+
messageId: sent.messages?.[0]?.id,
|
|
54
|
+
missing,
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const WhatsAppLive = Layer.mergeAll(
|
|
59
|
+
FetchHttpClient.layer,
|
|
60
|
+
WhatsApp.CredentialsFromEnv,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
program.pipe(Effect.provide(WhatsAppLive), Effect.runPromise);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Auth
|
|
67
|
+
|
|
68
|
+
`WHATSAPP_ACCESS_TOKEN` is sent as `Authorization: Bearer`. Use a system user
|
|
69
|
+
access token with the `whatsapp_business_messaging` and
|
|
70
|
+
`whatsapp_business_management` permissions, or a business token from
|
|
71
|
+
Embedded Signup. Optional variables:
|
|
72
|
+
|
|
73
|
+
- `WHATSAPP_API_VERSION`: the Graph API version every path starts with.
|
|
74
|
+
The default is `v23.0`, the version the spec describes.
|
|
75
|
+
- `WHATSAPP_API_BASE_URL`: the default is `https://graph.facebook.com`.
|
|
76
|
+
|
|
77
|
+
`WhatsApp.fromAccessToken({ accessToken: Redacted.make(token), apiVersion })`
|
|
78
|
+
builds the same layer from values.
|
|
79
|
+
|
|
80
|
+
## Pagination
|
|
81
|
+
|
|
82
|
+
Graph API lists take `limit` and `after`, and return `paging.cursors.after`
|
|
83
|
+
and, while another page exists, `paging.next`. These lists have `.pages()` and
|
|
84
|
+
`.items()`:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import * as Stream from "effect/Stream";
|
|
88
|
+
|
|
89
|
+
const WABA_ID = "<your WhatsApp Business Account ID>";
|
|
90
|
+
|
|
91
|
+
const templates = WhatsApp.listMessageTemplates
|
|
92
|
+
.items({ WABA_ID, limit: 100, fields: "name,status,language" })
|
|
93
|
+
.pipe(Stream.runCollect);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Errors
|
|
97
|
+
|
|
98
|
+
Failures carry the Graph API `error.code` as `code` and its message as
|
|
99
|
+
`message`. Besides the status classes (`BadRequest`, `Unauthorized`,
|
|
100
|
+
`Forbidden`, `NotFound`, `TooManyRequests`, …), `sendMessage` fails with
|
|
101
|
+
`TemplateNotFound` (132001) and `RecipientNotAllowed` (131030, sent from a
|
|
102
|
+
test number to a recipient outside its allowed list). Meta accepts a message
|
|
103
|
+
sent outside the 24-hour customer service window, then reports it as `failed`
|
|
104
|
+
with code 131047 in a status webhook.
|
|
105
|
+
|
|
106
|
+
## Webhooks
|
|
107
|
+
|
|
108
|
+
`WhatsApp.WebhookPayload` is the TypeScript type of what Meta POSTs to your
|
|
109
|
+
callback URL for messages, statuses and group events. The SDK exports the
|
|
110
|
+
type, not a decoder, so parse the body yourself.
|
|
111
|
+
|
|
112
|
+
It types the webhook fields Meta's OpenAPI spec describes: `messages`,
|
|
113
|
+
`group_lifecycle_update`, `group_settings_update` and
|
|
114
|
+
`group_participant_update`. Other fields you subscribe to in the app
|
|
115
|
+
dashboard, such as `account_update`, `message_template_status_update`,
|
|
116
|
+
`phone_number_name_update` or `security`, arrive in the same envelope, but
|
|
117
|
+
their `value` is not typed.
|
|
118
|
+
|
|
119
|
+
Each customer message is an `IncomingMessage` with `from`, `id`, `timestamp`
|
|
120
|
+
and `type`. The member named by `type` (`text`, `image`, `audio`, `reaction`,
|
|
121
|
+
`location`, `contacts`, …) holds the content, and `context` is set when the
|
|
122
|
+
message quotes an earlier one.
|
|
123
|
+
|
|
124
|
+
The SDK does not verify the `X-Hub-Signature-256` header. Check it against
|
|
125
|
+
your app secret before you trust a payload.
|
|
126
|
+
|
|
127
|
+
## Media
|
|
128
|
+
|
|
129
|
+
Upload with `uploadMedia`, which sends a multipart form:
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
const { id } = yield* WhatsApp.uploadMedia({
|
|
133
|
+
Phone_Number_ID,
|
|
134
|
+
messaging_product: "whatsapp",
|
|
135
|
+
type: "image/png",
|
|
136
|
+
file: new File([bytes], "photo.png", { type: "image/png" }),
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`WhatsApp.getMedia({ Media_ID })` returns a `url` that expires after five
|
|
141
|
+
minutes. Download it with your own `HttpClient` and the same
|
|
142
|
+
`Authorization: Bearer` header. Without the header the download returns 401.
|
|
143
|
+
The SDK has no `downloadMedia` operation, because the spec's version sends the
|
|
144
|
+
URL to the wrong address.
|
package/lib/.lazy.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"serviceDirs":["services"],"twins":["index.js"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{api$D as e,api$call as t,api$error as n,api$named as r,api$newError as i,api$op as a,api$opPaginated as o,category$withAuthError as s,category$withBadRequestError as c,category$withConflictError as l,category$withParseError as u,config$Redacted as d,config$String as f,config$all as ee,config$withDefault as p,pagination$getItems as m,pagination$getPath as h,pagination$isTerminalToken as g,pagination$missingPaginationConfig as _,retry$capped as v,retry$jittered as te,retry$makeDefault as ne,retry$throttlingFactory as re,retry$throttlingOptions as ie,retry$transientFactory as ae,retry$transientOptions as oe,schema_lite_typed$TaggedError as y,schema_lite_typed$Unknown as b,trait$Body as x,trait$FormDataFile as S,trait$Header as C,trait$Http as w,trait$HttpBody as T,trait$KeyDictionary as E,trait$Label as D,trait$Query as O,trait$ResponseCode as k,trait$UnionCases as A,trait$applyErrorMatchers as j,trait$bodySymbol as M,trait$errorMatchersSymbol as N,trait$formDataFileSymbol as P,trait$getErrorMatchers as F,trait$headerSymbol as I,trait$httpBodySymbol as L,trait$httpSymbol as R,trait$keyDictionarySymbol as z,trait$labelSymbol as B,trait$querySymbol as V,trait$responseCodeSymbol as H,trait$unionCasesSymbol as U}from"@distilled.cloud/core/_bundle/base";import{errors$API_ERRORS as W,errors$BadGateway as G,errors$BadRequest as K,errors$ConfigError as q,errors$Conflict as se,errors$DEFAULT_ERRORS as ce,errors$Forbidden as le,errors$GatewayTimeout as ue,errors$HTTP_STATUS_MAP as de,errors$InternalServerError as fe,errors$Locked as pe,errors$NotFound as me,errors$ServiceUnavailable as he,errors$TooManyRequests as ge,errors$Unauthorized as _e,errors$UnknownErrorFields as ve,errors$UnprocessableEntity as ye,protocol_http$invalidLabel as be,protocol_rest$RawResponse as xe,protocol_rest$RawResponseRoot as Se,protocol_rest$SensitiveValue as Ce,protocol_rest$rawResponseRootSymbol as we,protocol_rest$rawResponseSymbol as Te,protocol_rest$restProtocol as Ee,protocol_rest$sensitiveValueSymbol as De,protocol_rest$unknownErrorProps as Oe,schema_lite$Array as ke,schema_lite$Boolean as Ae,schema_lite$NullOr as je,schema_lite$Number as Me,schema_lite$Record as Ne,schema_lite$String as Pe,schema_lite$Struct as Fe,schema_lite$TaggedError as Ie,schema_lite$Union as Le,schema_lite$Unknown as Re,schema_lite$at as ze,schema_lite$instanceOf as Be,schema_lite$optional as Ve,schema_lite$suspend as He}from"@distilled.cloud/core/_bundle/rest";import*as J from"effect/Context";import*as Y from"effect/Effect";import*as X from"effect/Layer";import*as Ue from"effect/Redacted";import*as We from"effect/Stream";const Z=`https://graph.facebook.com`;const Q=`v23.0`;var Credentials=class extends (/*@__PURE__*/ J.Service()(`WhatsAppCredentials`)){};const check=e=>be(`apiVersion`,e.apiVersion)===void 0?Y.succeed(e):Y.fail(new q({message:`The configured WhatsApp API version ${JSON.stringify(e.apiVersion)} cannot be a URL path segment`}));const layer=e=>X.effect(Credentials,Y.map(Y.flatMap(e,check),e=>Y.succeed(e)));const trimSlash=e=>e.replace(/\/+$/,``);const fromAccessToken=e=>layer(Y.succeed({accessToken:e.accessToken,apiVersion:e.apiVersion??`v23.0`,apiBaseUrl:trimSlash(e.apiBaseUrl??`https://graph.facebook.com`)}));const $=/*@__PURE__*/ ee({accessToken:/*@__PURE__*/ d(`WHATSAPP_ACCESS_TOKEN`),apiVersion:/*@__PURE__*/ f(`WHATSAPP_API_VERSION`).pipe(/*@__PURE__*/ p(Q)),apiBaseUrl:/*@__PURE__*/ f(`WHATSAPP_API_BASE_URL`).pipe(/*@__PURE__*/ p(Z))});const Ge=/*@__PURE__*/ layer(/*@__PURE__*/ $.pipe(/*@__PURE__*/ Y.mapError(e=>new q({message:`WhatsApp credentials require WHATSAPP_ACCESS_TOKEN: ${e.message}`})),/*@__PURE__*/ Y.map(({accessToken:e,apiVersion:t,apiBaseUrl:n})=>({accessToken:e,apiVersion:t,apiBaseUrl:trimSlash(n)}))));var UnknownWhatsAppError=class extends (/*@__PURE__*/ y()(`UnknownWhatsAppError`,ve)){};var WhatsAppParseError=class extends (/*@__PURE__*/ y()(`WhatsAppParseError`,{body:b,cause:b}).pipe(u)){};const Ke=W;const nextPath=e=>{const t=e.split(`.`);const n=t.lastIndexOf(`cursors`);return[...t.slice(0,n===-1?-1:n),`next`].join(`.`)};const paginateGraph=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return _(`Graph API pagination requires inputToken and outputToken`);const a=n.hasNextPage??nextPath(i);const o=typeof t[r]===`string`?t[r]:void 0;return We.unfold({cursor:o,done:false},o=>Y.gen(function*(){if(o.done)return void 0;const s=yield*e({...t,...o.cursor?{[r]:o.cursor}:{}});const c=h(s,i);const l=h(s,a);const u=typeof l===`string`&&l!==``;const d=n.items!==void 0&&m(s,n.items).length===0;const f=o.cursor!==void 0&&c===o.cursor;return[s,{cursor:c??void 0,done:!u||g(c)||d||f}]}))};const isRecord=e=>typeof e===`object`&&e!==null;const graphError=e=>{const t=isRecord(e)&&isRecord(e.error)?e.error:void 0;if(t===void 0)return void 0;const n=typeof t.code===`number`?t.code:void 0;const r=typeof t.message===`string`&&t.message!==``?t.message:void 0;return n===void 0&&r===void 0?void 0:{code:n,message:r}};const baseUrlFor=e=>`${e.apiBaseUrl}/${encodeURIComponent(e.apiVersion)}`;const qe=/*@__PURE__*/ Ee({credentials:/*@__PURE__*/ Y.flatten(Credentials),baseUrl:baseUrlFor,headers:e=>({Authorization:`Bearer ${Ue.value(e.accessToken)}`,Accept:`application/json`}),errorEnvelope:graphError,errorFieldsAt:`/error`,unknownError:e=>new UnknownWhatsAppError(Oe(e)),parseError:({body:e,cause:t})=>new WhatsAppParseError({body:e,cause:t})});var Retry=class extends (/*@__PURE__*/ J.Service()(`WhatsAppRetry`)){};const policy=e=>Y.provide(X.succeed(Retry,e));const Je=/*@__PURE__*/ Y.provide(/*@__PURE__*/ X.succeed(Retry,{while:()=>false}));const Ye=ne;const Xe=te;const Ze=v;const Qe=ie;const $e=/*@__PURE__*/ policy(re);const et=oe;const tt=/*@__PURE__*/ policy(ae);export{l as Ca,ke as Xc,Ae as Yc,e as a,t as b,Credentials as credentials$Credentials,Ge as credentials$CredentialsFromEnv,Z as credentials$DEFAULT_API_BASE_URL,Q as credentials$DEFAULT_API_VERSION,check as credentials$check,fromAccessToken as credentials$fromAccessToken,W as errors$API_ERRORS,G as errors$BadGateway,K as errors$BadRequest,q as errors$ConfigError,se as errors$Conflict,ce as errors$DEFAULT_ERRORS,le as errors$Forbidden,ue as errors$GatewayTimeout,de as errors$HTTP_STATUS_MAP,fe as errors$InternalServerError,pe as errors$Locked,me as errors$NotFound,he as errors$ServiceUnavailable,ge as errors$TooManyRequests,_e as errors$Unauthorized,UnknownWhatsAppError as errors$UnknownWhatsAppError,ye as errors$UnprocessableEntity,WhatsAppParseError as errors$WhatsAppParseError,Ke as errors$WhatsAppServiceErrors,n as f,je as fd,Me as gd,Ne as hd,Pe as jd,Fe as kd,r as l,i as m,Ie as md,a as n,o,Le as od,m as pagination$getItems,paginateGraph as pagination$paginateGraph,Re as pd,qe as protocol$WhatsAppProtocol,ze as rd,Retry as retry$Retry,Ze as retry$capped,Xe as retry$jittered,Ye as retry$makeDefault,Je as retry$none,policy as retry$policy,$e as retry$throttling,Qe as retry$throttlingOptions,tt as retry$transient,et as retry$transientOptions,x as traits$Body,S as traits$FormDataFile,C as traits$Header,w as traits$Http,T as traits$HttpBody,E as traits$KeyDictionary,D as traits$Label,O as traits$Query,xe as traits$RawResponse,Se as traits$RawResponseRoot,k as traits$ResponseCode,Ce as traits$SensitiveValue,A as traits$UnionCases,j as traits$applyErrorMatchers,M as traits$bodySymbol,N as traits$errorMatchersSymbol,P as traits$formDataFileSymbol,F as traits$getErrorMatchers,I as traits$headerSymbol,L as traits$httpBodySymbol,R as traits$httpSymbol,z as traits$keyDictionarySymbol,B as traits$labelSymbol,V as traits$querySymbol,we as traits$rawResponseRootSymbol,Te as traits$rawResponseSymbol,H as traits$responseCodeSymbol,De as traits$sensitiveValueSymbol,U as traits$unionCasesSymbol,Be as ud,Ve as wd,He as xd,s as ya,c as za};
|
|
2
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","names":["Schema.Unknown","Category.withParseError","Retries.makeDefault","Retries.jittered","Retries.capped","Retries.throttlingOptions","Retries.throttlingFactory","Retries.transientOptions","Retries.transientFactory","D","call","error","named","newError","op","opPaginated","withAuthError","withBadRequestError","withConflictError","withParseError","Redacted$3","String$2","all$1","withDefault","getItems","getPath","isTerminalToken","missingPaginationConfig","capped$1","jittered$1","makeDefault$1","throttlingFactory","throttlingOptions$1","transientFactory","transientOptions$1","TaggedError$1","Unknown$1","Body","FormDataFile","Header","Http","HttpBody","KeyDictionary","Label","Query","ResponseCode","UnionCases","applyErrorMatchers","bodySymbol","errorMatchersSymbol","formDataFileSymbol","getErrorMatchers","headerSymbol","httpBodySymbol","httpSymbol","keyDictionarySymbol","labelSymbol","querySymbol","responseCodeSymbol","unionCasesSymbol","API_ERRORS","BadGateway","BadRequest","ConfigError","Conflict","DEFAULT_ERRORS","Forbidden","GatewayTimeout","HTTP_STATUS_MAP","InternalServerError","Locked","NotFound","ServiceUnavailable","TooManyRequests","Unauthorized","UnknownErrorFields","UnprocessableEntity","invalidLabel","RawResponse","RawResponseRoot","SensitiveValue","rawResponseRootSymbol","rawResponseSymbol","restProtocol","sensitiveValueSymbol","unknownErrorProps","Array","Boolean","NullOr","Number","Record","String","Struct","TaggedError","Union","Unknown","at","instanceOf","optional","suspend","Context","Effect","Layer","Redacted","Stream","DEFAULT_API_BASE_URL","DEFAULT_API_VERSION","config","checked","url","envConfig","CredentialsFromEnv","apiBaseUrl","WhatsAppServiceErrors","parts","outputToken","cursors","inputToken","pagination","hasNextPath","start","input","state","response","operation","cursor","next","hasNext","empty","stuck","v","body","code","message","creds","WhatsAppProtocol","info","optionsOrFactory","none","makeDefault","jittered","capped","throttlingOptions","throttling","transientOptions","transient"],"sources":["../../src/credentials.ts","../../src/errors.ts","../../src/pagination.ts","../../src/protocol.ts","../../src/retry.ts"],"mappings":"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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Checked } from "@distilled.cloud/core/config";
|
|
2
|
+
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
3
|
+
/**
|
|
4
|
+
* WhatsApp credentials -- hand-written.
|
|
5
|
+
*
|
|
6
|
+
* The WhatsApp Business Platform authenticates every call with the one
|
|
7
|
+
* scheme its OpenAPI spec declares: an access token sent as
|
|
8
|
+
* `Authorization: Bearer`. That is usually a system user access token with
|
|
9
|
+
* the `whatsapp_business_messaging` and `whatsapp_business_management`
|
|
10
|
+
* permissions, or a business token a Tech Provider obtained through
|
|
11
|
+
* Embedded Signup.
|
|
12
|
+
*
|
|
13
|
+
* Every Graph API path starts with a version (`/v23.0/...`). The protocol
|
|
14
|
+
* puts {@link Config.apiVersion} there; it defaults to
|
|
15
|
+
* {@link DEFAULT_API_VERSION}, the version the mirrored spec describes.
|
|
16
|
+
*
|
|
17
|
+
* Following the core convention the `Credentials` service holds an *effect*
|
|
18
|
+
* resolving the current config, which the protocol runs per request on
|
|
19
|
+
* the calling fiber.
|
|
20
|
+
*
|
|
21
|
+
* A layer here reads and checks its configuration when it is built
|
|
22
|
+
* ({@link check}): a missing access token or a version that can't be a URL
|
|
23
|
+
* path segment is a `ConfigError` at setup, and no call fails for it.
|
|
24
|
+
*/
|
|
25
|
+
import * as Context from "effect/Context";
|
|
26
|
+
import * as Effect from "effect/Effect";
|
|
27
|
+
import * as Layer from "effect/Layer";
|
|
28
|
+
import * as Redacted from "effect/Redacted";
|
|
29
|
+
/** The Graph API origin (the spec's only server). */
|
|
30
|
+
export declare const DEFAULT_API_BASE_URL = "https://graph.facebook.com";
|
|
31
|
+
/**
|
|
32
|
+
* The Graph API version the generated operations describe: the spec's
|
|
33
|
+
* `info.version`. Update it with the spec.
|
|
34
|
+
*/
|
|
35
|
+
export declare const DEFAULT_API_VERSION = "v23.0";
|
|
36
|
+
export interface Config {
|
|
37
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
38
|
+
/** Graph API version, e.g. `v23.0`, sent as the first path segment. */
|
|
39
|
+
readonly apiVersion: string;
|
|
40
|
+
readonly apiBaseUrl: string;
|
|
41
|
+
}
|
|
42
|
+
declare const Credentials_base: Context.ServiceClass<Credentials, "WhatsAppCredentials", Effect.Effect<Checked<Config>, never, never>>;
|
|
43
|
+
/** What the service resolves: a {@link Config} that passed {@link check}. */
|
|
44
|
+
export declare class Credentials extends /*@__PURE__*/ Credentials_base {
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check `config`: fails with `ConfigError` for a version that can't be a
|
|
48
|
+
* URL path segment (`""`, `.`, `..`, a lone UTF-16 surrogate). For a
|
|
49
|
+
* `Credentials` layer of your own, for example one that rotates tokens.
|
|
50
|
+
*/
|
|
51
|
+
export declare const check: (config: Config) => Effect.Effect<Checked<Config>, ConfigError>;
|
|
52
|
+
/** Layer from a redacted access token, with an optional version and base URL. */
|
|
53
|
+
export declare const fromAccessToken: (config: {
|
|
54
|
+
readonly accessToken: Redacted.Redacted<string>;
|
|
55
|
+
readonly apiVersion?: string;
|
|
56
|
+
readonly apiBaseUrl?: string;
|
|
57
|
+
}) => Layer.Layer<Credentials, ConfigError>;
|
|
58
|
+
/**
|
|
59
|
+
* Reads `WHATSAPP_ACCESS_TOKEN` (required), `WHATSAPP_API_VERSION` and
|
|
60
|
+
* `WHATSAPP_API_BASE_URL` (optional) through Effect `Config` -- so it follows
|
|
61
|
+
* whatever `ConfigProvider` is installed (in a Worker, one built from `env`).
|
|
62
|
+
* The environment is read, and the values checked, once: when the layer is
|
|
63
|
+
* built.
|
|
64
|
+
*/
|
|
65
|
+
export declare const CredentialsFromEnv: Layer.Layer<Credentials, ConfigError>;
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sources":["../src/credentials.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C,qDAAqD;AACrD,eAAO,MAAM,oBAAoB,+BAA+B,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChD,uEAAuE;IACvE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;;AAED,6EAA6E;AAC7E,qBAAa,WACX,SAAQ,aAAa,CAAC,gBAErB;CAAG;AAEN;;;;GAIG;AACH,eAAO,MAAM,KAAK,WAAY,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,CAQ1E,CAAC;AAWR,iFAAiF;AACjF,eAAO,MAAM,eAAe,WAAY;IACtC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAOrC,CAAC;AAYJ;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAcpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { credentials$Credentials as Credentials, credentials$CredentialsFromEnv as CredentialsFromEnv, credentials$DEFAULT_API_BASE_URL as DEFAULT_API_BASE_URL, credentials$DEFAULT_API_VERSION as DEFAULT_API_VERSION, credentials$check as check, credentials$fromAccessToken as fromAccessToken } from "./_bundle/sdk.js";
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhatsApp error types.
|
|
3
|
+
*
|
|
4
|
+
* Failures arrive as the Graph API error object
|
|
5
|
+
*
|
|
6
|
+
* { "error": { "message": "...", "type": "OAuthException", "code": 190,
|
|
7
|
+
* "error_subcode": 463, "fbtrace_id": "..." } }
|
|
8
|
+
*
|
|
9
|
+
* and map by status onto the core classes re-exported here: `BadRequest`,
|
|
10
|
+
* `Unauthorized`, `Forbidden`, `NotFound`, `TooManyRequests` and the 5xx
|
|
11
|
+
* family, the last two retryable. Operations that declare a status get a
|
|
12
|
+
* generated class with the same `_tag`, so `catchTag` works against either.
|
|
13
|
+
*/
|
|
14
|
+
export { BadGateway, BadRequest, Conflict, ConfigError, Forbidden, GatewayTimeout, InternalServerError, Locked, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity, HTTP_STATUS_MAP, DEFAULT_ERRORS, API_ERRORS, } from "@distilled.cloud/core/errors";
|
|
15
|
+
export type { DefaultErrors } from "@distilled.cloud/core/errors";
|
|
16
|
+
import * as Schema from "@distilled.cloud/core/schema-lite-typed";
|
|
17
|
+
declare const UnknownWhatsAppError_base: Schema.TaggedErrorClass<"UnknownWhatsAppError", {
|
|
18
|
+
status: import("effect/Schema").Number;
|
|
19
|
+
code: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
20
|
+
message: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
21
|
+
body: import("effect/Schema").Unknown;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* A non-2xx, non-5xx status that neither the operation nor the core map
|
|
25
|
+
* covers. `code` is the Graph API's numeric `error.code` when the body
|
|
26
|
+
* carries one.
|
|
27
|
+
*/
|
|
28
|
+
export declare class UnknownWhatsAppError extends /*@__PURE__*/ UnknownWhatsAppError_base {
|
|
29
|
+
}
|
|
30
|
+
declare const WhatsAppParseError_base: Schema.TaggedErrorClass<"WhatsAppParseError", {
|
|
31
|
+
readonly body: import("effect/Schema").Unknown;
|
|
32
|
+
readonly cause: import("effect/Schema").Unknown;
|
|
33
|
+
}> & (new (...args: any[]) => {
|
|
34
|
+
"@distilled.cloud/error/categories": {
|
|
35
|
+
ParseError: true;
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
/** A 2xx response that does not match the operation's output schema. */
|
|
39
|
+
export declare class WhatsAppParseError extends /*@__PURE__*/ WhatsAppParseError_base {
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The errors declared on the WhatsApp service: any operation can return them,
|
|
43
|
+
* and every generated operation lists them as its `serviceErrors`. Today that
|
|
44
|
+
* is each of core's status classes (401, 403, 404, 429, the 5xx ...).
|
|
45
|
+
*/
|
|
46
|
+
export declare const WhatsAppServiceErrors: readonly [typeof import("@distilled.cloud/core/errors").Unauthorized, typeof import("@distilled.cloud/core/errors").Forbidden, typeof import("@distilled.cloud/core/errors").NotFound, typeof import("@distilled.cloud/core/errors").BadRequest, typeof import("@distilled.cloud/core/errors").Conflict, typeof import("@distilled.cloud/core/errors").UnprocessableEntity, typeof import("@distilled.cloud/core/errors").TooManyRequests, typeof import("@distilled.cloud/core/errors").Locked, typeof import("@distilled.cloud/core/errors").InternalServerError, typeof import("@distilled.cloud/core/errors").BadGateway, typeof import("@distilled.cloud/core/errors").ServiceUnavailable, typeof import("@distilled.cloud/core/errors").GatewayTimeout];
|
|
47
|
+
export type WhatsAppServiceError = InstanceType<(typeof WhatsAppServiceErrors)[number]>;
|
|
48
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,MAAM,EACN,QAAQ,EACR,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,GACX,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAIlE,OAAO,KAAK,MAAM,MAAM,yCAAyC,CAAC;;;;;;;AAElE;;;;GAIG;AACH,qBAAa,oBACX,SAAQ,aAAa,CAAC,yBAGrB;CAAG;;;;;;;;;AAEN,wEAAwE;AACxE,qBAAa,kBACX,SAAQ,aAAa,CAAC,uBAGU;CAAG;AAErC;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,+tBAAa,CAAC;AAChD,MAAM,MAAM,oBAAoB,GAAG,YAAY,CAAC,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { errors$API_ERRORS as API_ERRORS, errors$BadGateway as BadGateway, errors$BadRequest as BadRequest, errors$ConfigError as ConfigError, errors$Conflict as Conflict, errors$DEFAULT_ERRORS as DEFAULT_ERRORS, errors$Forbidden as Forbidden, errors$GatewayTimeout as GatewayTimeout, errors$HTTP_STATUS_MAP as HTTP_STATUS_MAP, errors$InternalServerError as InternalServerError, errors$Locked as Locked, errors$NotFound as NotFound, errors$ServiceUnavailable as ServiceUnavailable, errors$TooManyRequests as TooManyRequests, errors$Unauthorized as Unauthorized, errors$UnknownWhatsAppError as UnknownWhatsAppError, errors$UnprocessableEntity as UnprocessableEntity, errors$WhatsAppParseError as WhatsAppParseError, errors$WhatsAppServiceErrors as WhatsAppServiceErrors } from "./_bundle/sdk.js";
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @distilled.cloud/whatsapp -- WhatsApp Business Platform SDK for Effect.
|
|
3
|
+
*
|
|
4
|
+
* `./services` is generated by `scripts/generate.ts` from the Smithy model
|
|
5
|
+
* that `scripts/convert.ts` converts from Meta's OpenAPI spec
|
|
6
|
+
* (https://github.com/facebook/openapi), mirrored at
|
|
7
|
+
* `specs/spec-mirror-whatsapp/specs/openapi.yaml`. Everything else in this
|
|
8
|
+
* folder is hand-written.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import * as Effect from "effect/Effect";
|
|
13
|
+
* import * as Layer from "effect/Layer";
|
|
14
|
+
* import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
15
|
+
* import * as WhatsApp from "@distilled.cloud/whatsapp";
|
|
16
|
+
*
|
|
17
|
+
* const program = WhatsApp.getPhoneNumber({ Phone_Number_ID: "106540352242922" });
|
|
18
|
+
*
|
|
19
|
+
* program.pipe(
|
|
20
|
+
* Effect.provide(
|
|
21
|
+
* Layer.mergeAll(FetchHttpClient.layer, WhatsApp.CredentialsFromEnv),
|
|
22
|
+
* ),
|
|
23
|
+
* Effect.runPromise,
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export * from "./credentials.ts";
|
|
28
|
+
export * from "./errors.ts";
|
|
29
|
+
export * as T from "./traits.ts";
|
|
30
|
+
export { WhatsAppProtocol, type WhatsAppOpError, type WhatsAppOpContext } from "./protocol.ts";
|
|
31
|
+
export { paginateGraph } from "./pagination.ts";
|
|
32
|
+
export * as Retry from "./retry.ts";
|
|
33
|
+
export * from "./services/whatsapp.ts";
|
|
34
|
+
export { BadRequest, Conflict, Forbidden, NotFound, UnprocessableEntity, } from "./services/whatsapp.ts";
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAMpC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EACL,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,mBAAmB,GACpB,MAAM,wBAAwB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./credentials.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * as T from "./traits.js";
|
|
4
|
+
export { WhatsAppProtocol } from "./protocol.js";
|
|
5
|
+
export { paginateGraph } from "./pagination.js";
|
|
6
|
+
export * as Retry from "./retry.js";
|
|
7
|
+
export * from "./services/whatsapp.js";
|
|
8
|
+
export { BadRequest, Conflict, Forbidden, NotFound, UnprocessableEntity } from "./services/whatsapp.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./credentials.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * as T from "./traits.js";
|
|
4
|
+
export { WhatsAppProtocol } from "./protocol.js";
|
|
5
|
+
export { paginateGraph } from "./pagination.js";
|
|
6
|
+
export * as Retry from "./retry.js";
|
|
7
|
+
export * from "./services.lazy/whatsapp.js";
|
|
8
|
+
export { BadRequest, Conflict, Forbidden, NotFound, UnprocessableEntity } from "./services.lazy/whatsapp.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAgD,MAAM,eAAe,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,uEAAuE;AACvE,0EAA0E;AAC1E,yEAAyE;AACzE,yEAAyE;AACzE,wDAAwD;AACxD,cAAc,wBAAwB,CAAC;AACvC,OAAO,EACL,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,mBAAmB,GACpB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type PaginationStrategy } from "@distilled.cloud/core/pagination";
|
|
2
|
+
export { getItems } from "@distilled.cloud/core/pagination";
|
|
3
|
+
/** Stream of pages: `after` = the previous page's cursor, while `paging.next` is set. */
|
|
4
|
+
export declare const paginateGraph: PaginationStrategy;
|
|
5
|
+
//# sourceMappingURL=pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,kCAAkC,CAAC;AAoB1C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAS5D,yFAAyF;AACzF,eAAO,MAAM,aAAa,EAAE,kBAoC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pagination$getItems as getItems, pagination$paginateGraph as paginateGraph } from "./_bundle/sdk.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ErrorOf } from "@distilled.cloud/core/protocol";
|
|
2
|
+
import type * as HttpClient from "effect/http/HttpClient";
|
|
3
|
+
import { Credentials } from "./credentials.ts";
|
|
4
|
+
import { UnknownWhatsAppError, WhatsAppParseError, type WhatsAppServiceError } from "./errors.ts";
|
|
5
|
+
/**
|
|
6
|
+
* What every generated WhatsApp operation fails with besides its own errors:
|
|
7
|
+
* the errors declared on the service, and the errors declared on the protocol.
|
|
8
|
+
* Nobody lists the protocol's: its type carries what its code fails with (a
|
|
9
|
+
* response that does not match its schema, a failed response nothing declares,
|
|
10
|
+
* core's REST errors, and what resolving the credentials fails with).
|
|
11
|
+
* Generated service files annotate operations with `API.OperationMethod<I, O,
|
|
12
|
+
* WhatsAppOpError, WhatsAppOpContext>` explicitly so the compiler never infers
|
|
13
|
+
* these back out of the schema generics.
|
|
14
|
+
*/
|
|
15
|
+
export type WhatsAppOpError = WhatsAppServiceError | ErrorOf<typeof WhatsAppProtocol>;
|
|
16
|
+
/** Context (requirements) shared by every generated WhatsApp operation. */
|
|
17
|
+
export type WhatsAppOpContext = Credentials | HttpClient.HttpClient;
|
|
18
|
+
export declare const WhatsAppProtocol: import("@distilled.cloud/core/protocol").Protocol<UnknownWhatsAppError | WhatsAppParseError | import("@distilled.cloud/core/protocol-rest").RestProtocolError, Credentials>;
|
|
19
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sources":["../src/protocol.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAiB9D,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAElG;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,oBAAoB,GAAG,OAAO,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEtF,2EAA2E;AAC3E,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,UAAU,CAAC,UAAU,CAAC;AAsBpE,eAAO,MAAM,gBAAgB,6KAa3B,CAAC"}
|
package/lib/protocol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { protocol$WhatsAppProtocol as WhatsAppProtocol } from "./_bundle/sdk.js";
|