@distilled.cloud/mailchimp 0.0.0 → 1.0.0-rc.20

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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +102 -4
  3. package/lib/.lazy.json +1 -0
  4. package/lib/_bundle/lazy.js +4 -0
  5. package/lib/_bundle/sdk.js +2 -0
  6. package/lib/_bundle/sdk.js.map +1 -0
  7. package/lib/credentials.d.ts +59 -0
  8. package/lib/credentials.d.ts.map +1 -0
  9. package/lib/credentials.js +1 -0
  10. package/lib/errors.d.ts +66 -0
  11. package/lib/errors.d.ts.map +1 -0
  12. package/lib/errors.js +1 -0
  13. package/lib/index.d.ts +44 -0
  14. package/lib/index.d.ts.map +1 -0
  15. package/lib/index.js +10 -0
  16. package/lib/index.lazy.js +10 -0
  17. package/lib/index.lazy.js.map +1 -0
  18. package/lib/pagination.d.ts +11 -0
  19. package/lib/pagination.d.ts.map +1 -0
  20. package/lib/pagination.js +1 -0
  21. package/lib/protocol.d.ts +25 -0
  22. package/lib/protocol.d.ts.map +1 -0
  23. package/lib/protocol.js +1 -0
  24. package/lib/retry.d.ts +53 -0
  25. package/lib/retry.d.ts.map +1 -0
  26. package/lib/retry.js +1 -0
  27. package/lib/services/index.d.ts +3 -0
  28. package/lib/services/index.d.ts.map +1 -0
  29. package/lib/services/index.js +2 -0
  30. package/lib/services/marketing.d.ts +24805 -0
  31. package/lib/services/marketing.d.ts.map +1 -0
  32. package/lib/services/marketing.js +409 -0
  33. package/lib/services/marketing.js.map +1 -0
  34. package/lib/services/transactional.d.ts +3805 -0
  35. package/lib/services/transactional.d.ts.map +1 -0
  36. package/lib/services/transactional.js +143 -0
  37. package/lib/services/transactional.js.map +1 -0
  38. package/lib/services.lazy/index.js +3 -0
  39. package/lib/services.lazy/marketing.js +3 -0
  40. package/lib/services.lazy/transactional.js +4 -0
  41. package/lib/subscriber-hash.d.ts +11 -0
  42. package/lib/subscriber-hash.d.ts.map +1 -0
  43. package/lib/subscriber-hash.js +2 -0
  44. package/lib/subscriber-hash.js.map +1 -0
  45. package/lib/traits.d.ts +7 -0
  46. package/lib/traits.d.ts.map +1 -0
  47. package/lib/traits.js +1 -0
  48. package/package.json +88 -2
  49. package/src/credentials.ts +156 -0
  50. package/src/errors.ts +80 -0
  51. package/src/index.ts +50 -0
  52. package/src/pagination.ts +69 -0
  53. package/src/protocol.ts +194 -0
  54. package/src/retry.ts +72 -0
  55. package/src/services/index.ts +3 -0
  56. package/src/services/marketing.ts +43348 -0
  57. package/src/services/transactional.ts +7512 -0
  58. package/src/subscriber-hash.ts +87 -0
  59. 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,107 @@
1
1
  # @distilled.cloud/mailchimp
2
2
 
3
- 🐣 This package name has been claimed with [fledgling](https://github.com/dmno-dev/fledgling) for [https://github.com/alchemy-run/distilled](https://github.com/alchemy-run/distilled), and a real release will land here soon.
3
+ Effect-native SDK for the [Mailchimp Marketing API](https://mailchimp.com/developer/marketing/api/) (v3.0) and the [Mailchimp Transactional API](https://mailchimp.com/developer/transactional/api/) (formerly Mandrill).
4
4
 
5
- This is a placeholder — there is nothing to install yet.
5
+ ## Installation
6
6
 
7
- ---
7
+ ```bash
8
+ npm install @distilled.cloud/mailchimp effect
9
+ ```
8
10
 
9
- Want to claim a name of your own? Run `npx fledgling add <name> --new --yes` — it reserves the name on npm and can set up token-less (OIDC trusted) publishing for when you are ready.
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { Effect, Layer } from "effect";
15
+ import * as FetchHttpClient from "effect/http/FetchHttpClient";
16
+ import * as Mailchimp from "@distilled.cloud/mailchimp";
17
+
18
+ const email = "ada@example.com";
19
+
20
+ const program = Effect.gen(function* () {
21
+ yield* Mailchimp.setListMember({
22
+ list_id: "a1b2c3d4e5",
23
+ subscriber_hash: Mailchimp.subscriberHash(email),
24
+ email_address: email,
25
+ status_if_new: "subscribed",
26
+ merge_fields: { FNAME: "Ada" },
27
+ });
28
+ yield* Mailchimp.updateListMemberTags({
29
+ list_id: "a1b2c3d4e5",
30
+ subscriber_hash: Mailchimp.subscriberHash(email),
31
+ tags: [{ name: "customer", status: "active" }],
32
+ });
33
+ });
34
+
35
+ const Live = Layer.mergeAll(
36
+ FetchHttpClient.layer,
37
+ Mailchimp.CredentialsFromEnv,
38
+ );
39
+
40
+ program.pipe(Effect.provide(Live), Effect.runPromise);
41
+ ```
42
+
43
+ ## Auth
44
+
45
+ Required: `MAILCHIMP_API_KEY`. Optional: `MAILCHIMP_SERVER_PREFIX`. Sent as
46
+ HTTP basic auth. `CredentialsFromEnv` reads through Effect `Config`, so it
47
+ follows whatever `ConfigProvider` is installed.
48
+
49
+ The data centre comes from the key's suffix: `…-us21` calls
50
+ `https://us21.api.mailchimp.com/3.0`. Override it with
51
+ `fromApiKey({ apiKey, serverPrefix: "us21" })` or a full `apiBaseUrl`. A key
52
+ with no suffix and no override fails with `ConfigError`.
53
+
54
+ ## Transactional API
55
+
56
+ The Transactional API has its own key, issued in the Transactional app, and
57
+ lives under `Mailchimp.Transactional` (or `@distilled.cloud/mailchimp/transactional`).
58
+
59
+ ```ts
60
+ import * as Mailchimp from "@distilled.cloud/mailchimp";
61
+
62
+ const send = Mailchimp.Transactional.sendMessage({
63
+ message: {
64
+ from_email: "hello@example.com",
65
+ to: [{ email: "ada@example.com" }],
66
+ subject: "Welcome",
67
+ text: "Hi Ada",
68
+ },
69
+ });
70
+
71
+ send.pipe(
72
+ Effect.provide(Mailchimp.TransactionalCredentialsFromEnv),
73
+ Effect.provide(FetchHttpClient.layer),
74
+ Effect.runPromise,
75
+ );
76
+ ```
77
+
78
+ Required: `MAILCHIMP_TRANSACTIONAL_API_KEY` (`MANDRILL_API_KEY` is read as a
79
+ fallback), or `fromTransactionalApiKey({ apiKey })`. The key is sent in each
80
+ request body; it is never part of an operation's input. Failures arrive as
81
+ `{ status: "error", code, name, message }` under a real HTTP status and map
82
+ by status onto the operation's declared error classes (exported from
83
+ `Mailchimp.Transactional`) or the shared ones, with the vendor's `name` kept
84
+ in the message (`Invalid_Key: Invalid API key`). Each operation's error channel lists only
85
+ what Mailchimp declares for that route: `getTemplate` can fail with
86
+ `NotFound`, `sendMessage` with `PaymentRequired` (a 402, with the vendor
87
+ `code`) and `NotFound`, `ping` with the defaults alone. A status outside the
88
+ shared map becomes `MailchimpTransactionalError`, which carries `name` and
89
+ `code`.
90
+
91
+ ## Notes
92
+
93
+ - **Operation names** are the ones Mailchimp's own clients use
94
+ (`x-custom-config.methodNameCamel`, e.g. `setListMember`), except where that
95
+ name repeats across resources (`campaigns.list`, `templates.list`); those
96
+ fall back to verbNoun (`getCampaigns`). Inputs and outputs keep the wire's
97
+ snake_case names.
98
+ - **`subscriberHash(email)`** is the MD5 of the lowercased address, the
99
+ member id in `/members/{subscriber_hash}` paths. Pure TypeScript, since Web
100
+ Crypto has no MD5.
101
+ - **Errors** are RFC 7807 problem documents, mapped by status onto the shared
102
+ classes (`NotFound`, `BadRequest`, `TooManyRequests`, …). A 400's
103
+ `errors: [{ field, message }]` are appended to the message.
104
+ - **Pagination** is `count`/`offset`; paginated operations expose `.pages`
105
+ and `.items`, which stop at `total_items`, an empty page or a short page.
106
+ - **Optional response fields accept `null`**, because the spec marks nothing
107
+ nullable.
package/lib/.lazy.json ADDED
@@ -0,0 +1 @@
1
+ {"serviceDirs":["services"],"twins":["index.js"]}
@@ -0,0 +1,4 @@
1
+ import*as $0 from"./sdk.js";
2
+ import{api$lazyService as L}from"@distilled.cloud/core/_bundle/base";
3
+ const u=import.meta.url,N=[$0];
4
+ export const $L=(s,k,a,l,x)=>L(u,s,k,a===void 0?void 0:x?N.concat(x):N,a,l);
@@ -0,0 +1,2 @@
1
+ import{errors$API_ERRORS as e,errors$BadGateway as t,errors$BadRequest as n,errors$ConfigError as r,errors$Conflict as i,errors$DEFAULT_ERRORS as a,errors$Forbidden as o,errors$GatewayTimeout as s,errors$HTTP_STATUS_MAP as c,errors$InternalServerError as l,errors$Locked as u,errors$NotFound as d,errors$ServiceUnavailable as ee,errors$TooManyRequests as te,errors$Unauthorized as ne,errors$UnknownErrorFields as re,errors$UnprocessableEntity as ie,protocol_rest$RawResponse as ae,protocol_rest$RawResponseRoot as oe,protocol_rest$SensitiveValue as se,protocol_rest$makeRestProtocol as f,protocol_rest$rawResponseRootSymbol as ce,protocol_rest$rawResponseSymbol as le,protocol_rest$sensitiveValueSymbol as ue,protocol_rest$unknownErrorProps as p,schema_lite$Array as m,schema_lite$Boolean as de,schema_lite$NullOr as fe,schema_lite$Number as pe,schema_lite$Record as h,schema_lite$String as g,schema_lite$Struct as _,schema_lite$TaggedError as v,schema_lite$Unknown as y,schema_lite$at as b,schema_lite$optional as x,schema_lite$suspend as S}from"@distilled.cloud/core/_bundle/rest";import{api$D as C,api$Protocol as w,api$call as T,api$error as E,api$named as D,api$newError as O,api$op as k,api$opPaginated as A,category$withAuthError as j,category$withBadRequestError as M,category$withParseError as N,category$withQuotaError as P,pagination$getItems as F,pagination$getPath as I,retry$capped as L,retry$jittered as R,retry$makeDefault as z,retry$throttlingFactory as B,retry$throttlingOptions as me,retry$transientFactory as he,retry$transientOptions as ge,schema_lite_typed$Number as V,schema_lite_typed$String as H,schema_lite_typed$TaggedError as U,schema_lite_typed$Unknown as W,schema_lite_typed$optional as G,trait$Body as _e,trait$FormDataFile as ve,trait$Header as ye,trait$Http as K,trait$HttpBody as be,trait$KeyDictionary as xe,trait$Label as Se,trait$Query as Ce,trait$ResponseCode as we,trait$UnionCases as Te,trait$applyErrorMatchers as Ee,trait$bodySymbol as De,trait$errorMatchersSymbol as Oe,trait$formDataFileSymbol as ke,trait$getErrorMatchers as Ae,trait$headerSymbol as je,trait$httpBodySymbol as Me,trait$httpSymbol as Ne,trait$keyDictionarySymbol as Pe,trait$labelSymbol as Fe,trait$querySymbol as Ie,trait$responseCodeSymbol as Le,trait$unionCasesSymbol as Re}from"@distilled.cloud/core/_bundle/base";import*as q from"effect/Config";import*as J from"effect/Context";import*as Y from"effect/Effect";import*as X from"effect/Layer";import*as ze from"effect/Option";import*as Z from"effect/Redacted";import*as Be from"effect/Stream";var Credentials=class extends (/*@__PURE__*/ J.Service()(`MailchimpCredentials`)){};const serverPrefixFromApiKey=e=>{const t=e.lastIndexOf(`-`);if(t<0)return void 0;const n=e.slice(t+1);return/^[a-z]+[0-9]+$/i.test(n)?n.toLowerCase():void 0};const apiBaseUrlFor=e=>`https://${e}.api.mailchimp.com/3.0`;const trimSlash=e=>e.replace(/\/+$/,``);const resolve=e=>{const t=Z.isRedacted(e.apiKey)?e.apiKey:Z.make(e.apiKey);if(e.apiBaseUrl!==void 0)return Y.succeed({apiKey:t,apiBaseUrl:trimSlash(e.apiBaseUrl)});const n=e.serverPrefix??serverPrefixFromApiKey(Z.value(t));if(n===void 0)return Y.fail(new r({message:"Mailchimp API key has no data-centre suffix (expected `<key>-<dc>`, e.g. `...-us21`); pass serverPrefix"}));return Y.succeed({apiKey:t,apiBaseUrl:apiBaseUrlFor(n)})};const fromApiKey=e=>X.succeed(Credentials,resolve(e));const Ve=/*@__PURE__*/ X.succeed(Credentials,Y.gen(function*(){const e=yield*q.Redacted(`MAILCHIMP_API_KEY`);const t=yield*q.option(q.String(`MAILCHIMP_SERVER_PREFIX`));return{apiKey:e,serverPrefix:ze.getOrUndefined(t)}}).pipe(Y.mapError(e=>new r({message:`Mailchimp credentials require MAILCHIMP_API_KEY: ${e.message}`})),Y.flatMap(resolve)));const He=`https://mandrillapp.com/api/1.0`;var TransactionalCredentials=class extends (/*@__PURE__*/ J.Service()(`MailchimpTransactionalCredentials`)){};const resolveTransactional$1=e=>({apiKey:Z.isRedacted(e.apiKey)?e.apiKey:Z.make(e.apiKey),apiBaseUrl:trimSlash(e.apiBaseUrl??`https://mandrillapp.com/api/1.0`)});const fromTransactionalApiKey=e=>X.succeed(TransactionalCredentials,Y.succeed(resolveTransactional$1(e)));const Ue=/*@__PURE__*/ X.succeed(TransactionalCredentials,Y.gen(function*(){const e=yield*q.Redacted(`MAILCHIMP_TRANSACTIONAL_API_KEY`).pipe(q.orElse(()=>q.Redacted(`MANDRILL_API_KEY`)));return resolveTransactional$1({apiKey:e})}).pipe(Y.mapError(e=>new r({message:`Mailchimp Transactional credentials require MAILCHIMP_TRANSACTIONAL_API_KEY: ${e.message}`}))));const Q={...re,type:/*@__PURE__*/ G(H),title:/*@__PURE__*/ G(H),instance:/*@__PURE__*/ G(H)};var MailchimpApiError=class extends (/*@__PURE__*/ U()(`MailchimpApiError`,Q)){};var UnknownMailchimpError=class extends (/*@__PURE__*/ U()(`UnknownMailchimpError`,Q)){};var MailchimpParseError=class extends (/*@__PURE__*/ U()(`MailchimpParseError`,{body:W,cause:W}).pipe(N)){};var MailchimpTransactionalError=class extends (/*@__PURE__*/ U()(`MailchimpTransactionalError`,{status:V,code:/*@__PURE__*/ G(V),name:/*@__PURE__*/ G(H),message:H,body:W})){};const toNumber=e=>typeof e===`number`&&Number.isFinite(e)?e:void 0;const paginateOffset=(e,t,n)=>{const r=n.inputToken??`offset`;const i=n.pageSize??`count`;const a=toNumber(t[i]);return Be.unfold({offset:toNumber(t[r])??0,done:false},i=>Y.gen(function*(){if(i.done)return void 0;const o=yield*e({...t,[r]:i.offset});const s=n.outputToken?toNumber(I(o,n.outputToken)):void 0;const c=n.items?I(o,n.items):void 0;const l=Array.isArray(c)?c.length:0;const u=i.offset+l;return[o,{offset:u,done:l===0||s!==void 0&&u>=s||a!==void 0&&l<a}]}))};const isRecord=e=>typeof e===`object`&&e!==null;const str=e=>typeof e===`string`&&e!==``?e:void 0;const fieldErrors=e=>Array.isArray(e.errors)?e.errors.flatMap(e=>isRecord(e)&&str(e.message)?[str(e.field)?`${e.field}: ${e.message}`:String(e.message)]:[]):[];const problemMessage=e=>{if(!isRecord(e))return void 0;const t=str(e.detail)??str(e.title);if(t===void 0)return void 0;const n=fieldErrors(e);return n.length?`${t} (${n.join(`; `)})`:t};const We=/*@__PURE__*/ f({credentials:/*@__PURE__*/ Y.flatMap(Credentials,e=>e),baseUrl:e=>e.apiBaseUrl,headers:e=>({Authorization:`Basic ${btoa(`anystring:${Z.value(e.apiKey)}`)}`}),errorEnvelope:e=>{const t=problemMessage(e);return t===void 0?void 0:{message:t}},unknownError:e=>{const t=isRecord(e.body)?e.body:void 0;const n={...p(e),type:str(t?.type),title:str(t?.title),instance:str(t?.instance)};return problemMessage(e.body)!==void 0?new MailchimpApiError(n):new UnknownMailchimpError(n)},parseError:({body:e,cause:t})=>new MailchimpParseError({body:e,cause:t})});const $=/*@__PURE__*/ Y.flatMap(TransactionalCredentials,e=>e);const transactionalFailure=e=>isRecord(e)&&e.status===`error`?e:void 0;const transactionalMessage=e=>{const t=str(e.name);const n=str(e.message);return t!==void 0&&n!==void 0?`${t}: ${n}`:t??n};const Ge=/*@__PURE__*/ f({credentials:$,baseUrl:e=>e.apiBaseUrl,headers:()=>({}),errorEnvelope:e=>{const t=transactionalFailure(e);if(t===void 0)return void 0;const n=transactionalMessage(t);return n===void 0?void 0:{message:n,code:typeof t.code===`number`?t.code:void 0}},unknownError:({status:e,code:t,message:n,body:r,headers:i})=>{const a=transactionalFailure(r);return a!==void 0?new MailchimpTransactionalError({status:e,code:typeof t===`number`?t:void 0,name:str(a.name),message:n,body:r}):new UnknownMailchimpError(p({status:e,code:t,message:n,body:r,headers:i}))},parseError:({body:e,cause:t})=>new MailchimpParseError({body:e,cause:t})});const Ke=/*@__PURE__*/ X.effect(w,Y.gen(function*(){const e=yield*w;return w.of({encode:t=>Y.gen(function*(){const n=yield*$;return yield*e.encode({...t,input:{...isRecord(t.input)?t.input:{},key:n.apiKey}})}),decode:e.decode})})).pipe(X.provide(Ge));var Retry=class extends (/*@__PURE__*/ J.Service()(`MailchimpRetry`)){};const policy=e=>Y.provide(X.succeed(Retry,e));const qe=/*@__PURE__*/ Y.provide(/*@__PURE__*/ X.succeed(Retry,{while:()=>false}));const Je=z;const Ye=R;const Xe=L;const Ze=me;const Qe=/*@__PURE__*/ policy(B);const $e=ge;const et=/*@__PURE__*/ policy(he);export{x as Cc,S as Dc,P as Ha,C as a,T as c,Credentials as credentials$Credentials,Ve as credentials$CredentialsFromEnv,He as credentials$DEFAULT_TRANSACTIONAL_API_BASE_URL,TransactionalCredentials as credentials$TransactionalCredentials,Ue as credentials$TransactionalCredentialsFromEnv,apiBaseUrlFor as credentials$apiBaseUrlFor,fromApiKey as credentials$fromApiKey,fromTransactionalApiKey as credentials$fromTransactionalApiKey,serverPrefixFromApiKey as credentials$serverPrefixFromApiKey,m as dc,E as e,de as ec,e as errors$API_ERRORS,t as errors$BadGateway,n as errors$BadRequest,r as errors$ConfigError,i as errors$Conflict,a as errors$DEFAULT_ERRORS,o as errors$Forbidden,s as errors$GatewayTimeout,c as errors$HTTP_STATUS_MAP,l as errors$InternalServerError,u as errors$Locked,MailchimpApiError as errors$MailchimpApiError,MailchimpParseError as errors$MailchimpParseError,MailchimpTransactionalError as errors$MailchimpTransactionalError,d as errors$NotFound,ee as errors$ServiceUnavailable,te as errors$TooManyRequests,ne as errors$Unauthorized,UnknownMailchimpError as errors$UnknownMailchimpError,ie as errors$UnprocessableEntity,D as k,O as l,fe as lc,k as m,pe as mc,A as n,h as nc,F as pagination$getItems,paginateOffset as pagination$paginateOffset,g as pc,We as protocol$MailchimpProtocol,Ke as protocol$MailchimpTransactionalProtocol,_ as qc,Retry as retry$Retry,Xe as retry$capped,Ye as retry$jittered,Je as retry$makeDefault,qe as retry$none,policy as retry$policy,Qe as retry$throttling,Ze as retry$throttlingOptions,et as retry$transient,$e as retry$transientOptions,v as sc,_e as traits$Body,ve as traits$FormDataFile,ye as traits$Header,K as traits$Http,be as traits$HttpBody,xe as traits$KeyDictionary,Se as traits$Label,Ce as traits$Query,ae as traits$RawResponse,oe as traits$RawResponseRoot,we as traits$ResponseCode,se as traits$SensitiveValue,Te as traits$UnionCases,Ee as traits$applyErrorMatchers,De as traits$bodySymbol,Oe as traits$errorMatchersSymbol,ke as traits$formDataFileSymbol,Ae as traits$getErrorMatchers,je as traits$headerSymbol,Me as traits$httpBodySymbol,Ne as traits$httpSymbol,Pe as traits$keyDictionarySymbol,Fe as traits$labelSymbol,Ie as traits$querySymbol,ce as traits$rawResponseRootSymbol,le as traits$rawResponseSymbol,Le as traits$responseCodeSymbol,ue as traits$sensitiveValueSymbol,Re as traits$unionCasesSymbol,y as vc,j as xa,b as xc,M as ya};
2
+ //# sourceMappingURL=sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.js","names":["resolveTransactional","Schema.String","Schema.Unknown","Category.withParseError","Schema.Number","API.Protocol","Retries.makeDefault","Retries.jittered","Retries.capped","Retries.throttlingOptions","Retries.throttlingFactory","Retries.transientOptions","Retries.transientFactory","API_ERRORS","BadGateway","BadRequest","ConfigError","Conflict","DEFAULT_ERRORS","Forbidden","GatewayTimeout","HTTP_STATUS_MAP","InternalServerError","Locked","NotFound","ServiceUnavailable","TooManyRequests","Unauthorized","UnknownErrorFields","UnprocessableEntity","RawResponse","RawResponseRoot","SensitiveValue","makeRestProtocol","rawResponseRootSymbol","rawResponseSymbol","sensitiveValueSymbol","unknownErrorProps","Array$1","Boolean","NullOr","Number$1","Record","String$1","Struct","TaggedError","Unknown","at","optional","suspend","D","Protocol","call","error","named","newError","op","opPaginated","withAuthError","withBadRequestError","withParseError","withQuotaError","getItems","getPath","capped$1","jittered$1","makeDefault$1","throttlingFactory","throttlingOptions$1","transientFactory","transientOptions$1","Number$2","String$2","TaggedError$1","Unknown$1","optional$1","Body","FormDataFile","Header","Http","HttpBody","KeyDictionary","Label","Query","ResponseCode","UnionCases","applyErrorMatchers","bodySymbol","errorMatchersSymbol","formDataFileSymbol","getErrorMatchers","headerSymbol","httpBodySymbol","httpSymbol","keyDictionarySymbol","labelSymbol","querySymbol","responseCodeSymbol","unionCasesSymbol","EffectConfig","Context","Effect","Layer","Option","Redacted","Stream","dash","apiKey","dc","serverPrefix","url","config","server","CredentialsFromEnv","DEFAULT_TRANSACTIONAL_API_BASE_URL","TransactionalCredentialsFromEnv","ProblemFields","v","offsetKey","pagination","countKey","requested","input","state","response","operation","total","items","received","next","body","head","fields","MailchimpProtocol","resolve","creds","message","problem","info","resolveTransactional","name","failure","TransactionalRest","code","MailchimpTransactionalProtocol","rest","args","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":"6/EA0BA,IAAa,YAAb,eACwB,gBAAQ,QAAyD,CAAC,CACtF,sBACF,EAAA,AAAE,CAAC,EAGL,MAAa,uBAA0B,GAAuC,CAC5E,MAAM0G,EAAOC,EAAO,YAAY,GAAG,EACnC,GAAID,EAAO,EAAG,OAAO,IAAA,GACrB,MAAME,EAAKD,EAAO,MAAMD,EAAO,CAAC,EAChC,MAAO,kBAAkB,KAAKE,CAAE,EAAIA,EAAG,YAAY,EAAI,IAAA,EACzD,EAEA,MAAa,cAAiB,GAC5B,WAAWC,EAAa,wBAE1B,MAAM,UAAa,GAAwBC,EAAI,QAAQ,OAAQ,EAAE,EAEjE,MAAM,QAAW,GAIyB,CACxC,MAAMH,EAASH,EAAS,WAAWO,EAAO,MAAM,EAAIA,EAAO,OAASP,EAAS,KAAKO,EAAO,MAAM,EAC/F,GAAIA,EAAO,aAAe,IAAA,GACxB,OAAOV,EAAO,QAAQ,CAAE,SAAQ,WAAY,UAAUU,EAAO,UAAU,CAAE,CAAC,EAE5E,MAAMC,EAASD,EAAO,cAAgB,uBAAuBP,EAAS,MAAMG,CAAM,CAAC,EACnF,GAAIK,IAAW,IAAA,GACb,OAAOX,EAAO,KACZ,IAAIrF,EAAY,CACd,QACE,yGACJ,CAAC,CACH,EAEF,OAAOqF,EAAO,QAAQ,CAAE,SAAQ,WAAY,cAAcW,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xG,EAAkB,CAAE,SAAQ,OAAM,UAAS,OAAM,SAAQ,CAAC,CAAC,CAC3F,EACA,YAAa,CAAE,OAAM,WAAY,IAAI,oBAAoB,CAAE,OAAM,OAAM,CAAC,CAC1E,CAAC,EAQH,MAAa2G,GAA0E,gBAAM,OAC3F3I,EACAgG,EAAO,IAAI,WAAa,CACtB,MAAM4C,EAAO,MAAO5I,EACpB,OAAA8C,EAAoB,GAAG,CACrB,OAAS,GACPkD,EAAO,IAAI,WAAa,CACtB,MAAMkC,EAAQ,MAAOI,EACrB,OAAO,MAAOM,EAAK,OAAO,CACxB,GAAGC,EACH,MAAO,CAAE,GAAI,SAASA,EAAK,KAAK,EAAIA,EAAK,MAAQ,CAAC,EAAI,IAAKX,EAAM,MAAO,CAC1E,CAAC,CACH,CAAC,EACH,OAAQU,EAAK,MACf,CAAC,CACH,CAAC,CACH,CAAC,CAAC,KAAK3C,EAAM,QAAQwC,EAAiB,CAAC,ECrKvC,IAAa,MAAb,eAAyC,gBAAQ,QAAuB,CAAC,CAAC,gBAAgB,EAAA,AAAE,CAAC,EAG7F,MAAa,OAOR,GAAwCzC,EAAO,QAAQC,EAAM,QAAQ,MAAO6C,CAAgB,CAAC,EAGlG,MAAaC,GAE+C,gBAAO,QACnD,gBAAM,QAAQ,MAAO,CAAE,UAAa,KAAM,CAAC,CAC3D,EAOA,MAAaC,GAAuB/I,EAEpC,MAAagJ,GAAW/I,EACxB,MAAagJ,GAAS/I,EAGtB,MAAagJ,GAA6B/I,GAG1C,MAAagJ,GAE+C,qBAAO/I,CAAyB,EAG5F,MAAagJ,GAA4B/I,GAGzC,MAAagJ,GAE+C,qBAAO/I,EAAwB"}
@@ -0,0 +1,59 @@
1
+ import { ConfigError } from "@distilled.cloud/core/errors";
2
+ import * as Context from "effect/Context";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Redacted from "effect/Redacted";
6
+ export interface Config {
7
+ readonly apiKey: Redacted.Redacted<string>;
8
+ /** Origin including the `/3.0` version segment. */
9
+ readonly apiBaseUrl: string;
10
+ }
11
+ declare const Credentials_base: Context.ServiceClass<Credentials, "MailchimpCredentials", Effect.Effect<Config, ConfigError, never>>;
12
+ export declare class Credentials extends /*@__PURE__*/ Credentials_base {
13
+ }
14
+ /** The data-centre suffix of an API key (`abc123-us21` -> `us21`). */
15
+ export declare const serverPrefixFromApiKey: (apiKey: string) => string | undefined;
16
+ export declare const apiBaseUrlFor: (serverPrefix: string) => string;
17
+ /**
18
+ * Layer from an API key. The data centre comes from the key's suffix unless
19
+ * `serverPrefix` (e.g. `"us21"`) or a full `apiBaseUrl` is given.
20
+ */
21
+ export declare const fromApiKey: (config: {
22
+ readonly apiKey: string | Redacted.Redacted<string>;
23
+ readonly serverPrefix?: string;
24
+ readonly apiBaseUrl?: string;
25
+ }) => Layer.Layer<Credentials>;
26
+ /**
27
+ * Reads `MAILCHIMP_API_KEY` (required) and the optional
28
+ * `MAILCHIMP_SERVER_PREFIX` through Effect `Config`, so it follows whatever
29
+ * `ConfigProvider` is installed -- in a Worker, one built from `env`.
30
+ */
31
+ export declare const CredentialsFromEnv: Layer.Layer<Credentials>;
32
+ /**
33
+ * The document's `basePath` is `/api/1.3`; Mailchimp's own clients and docs
34
+ * call `/api/1.0`, and the versions answer identically.
35
+ */
36
+ export declare const DEFAULT_TRANSACTIONAL_API_BASE_URL = "https://mandrillapp.com/api/1.0";
37
+ export interface TransactionalConfig {
38
+ readonly apiKey: Redacted.Redacted<string>;
39
+ readonly apiBaseUrl: string;
40
+ }
41
+ declare const TransactionalCredentials_base: Context.ServiceClass<TransactionalCredentials, "MailchimpTransactionalCredentials", Effect.Effect<TransactionalConfig, ConfigError, never>>;
42
+ /**
43
+ * The Transactional API (formerly Mandrill) has its own key, issued in the
44
+ * Transactional app, so it is a separate service from {@link Credentials}.
45
+ */
46
+ export declare class TransactionalCredentials extends /*@__PURE__*/ TransactionalCredentials_base {
47
+ }
48
+ /** Layer from a Transactional API key. */
49
+ export declare const fromTransactionalApiKey: (config: {
50
+ readonly apiKey: string | Redacted.Redacted<string>;
51
+ readonly apiBaseUrl?: string;
52
+ }) => Layer.Layer<TransactionalCredentials>;
53
+ /**
54
+ * Reads `MAILCHIMP_TRANSACTIONAL_API_KEY` (or the older `MANDRILL_API_KEY`)
55
+ * through Effect `Config`.
56
+ */
57
+ export declare const TransactionalCredentialsFromEnv: Layer.Layer<TransactionalCredentials>;
58
+ export {};
59
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAc3D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAE5C,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3C,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;;AAED,qBAAa,WACX,SAAQ,aAAa,CAAC,gBAErB;CAAG;AAEN,sEAAsE;AACtE,eAAO,MAAM,sBAAsB,WAAY,MAAM,KAAG,MAAM,GAAG,SAKhE,CAAC;AAEF,eAAO,MAAM,aAAa,iBAAkB,MAAM,KAAG,MACJ,CAAC;AAyBlD;;;GAGG;AACH,eAAO,MAAM,UAAU,WAAY;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAgD,CAAC;AAE5E;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAevD,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,kCAAkC,oCAAoC,CAAC;AAEpF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;;AAED;;;GAGG;AACH,qBAAa,wBACX,SAAQ,aAAa,CAAC,6BAGkB;CAAG;AAU7C,0CAA0C;AAC1C,eAAO,MAAM,uBAAuB,WAAY;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,KAAG,KAAK,CAAC,KAAK,CAAC,wBAAwB,CAC+C,CAAC;AAExF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,EAAE,KAAK,CAAC,KAAK,CAAC,wBAAwB,CAgB/E,CAAC"}
@@ -0,0 +1 @@
1
+ export { credentials$Credentials as Credentials, credentials$CredentialsFromEnv as CredentialsFromEnv, credentials$DEFAULT_TRANSACTIONAL_API_BASE_URL as DEFAULT_TRANSACTIONAL_API_BASE_URL, credentials$TransactionalCredentials as TransactionalCredentials, credentials$TransactionalCredentialsFromEnv as TransactionalCredentialsFromEnv, credentials$apiBaseUrlFor as apiBaseUrlFor, credentials$fromApiKey as fromApiKey, credentials$fromTransactionalApiKey as fromTransactionalApiKey, credentials$serverPrefixFromApiKey as serverPrefixFromApiKey } from "./_bundle/sdk.js";
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Mailchimp error types.
3
+ *
4
+ * Failures arrive as RFC 7807 problem documents
5
+ * (`{ type, title, status, detail, instance }`) and map by status onto the
6
+ * core classes re-exported here: `NotFound`, `BadRequest`, `Unauthorized`,
7
+ * `Forbidden`, `TooManyRequests` and the 5xx family, the last two retryable.
8
+ */
9
+ 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";
10
+ export type { DefaultErrors } from "@distilled.cloud/core/errors";
11
+ import * as Schema from "@distilled.cloud/core/schema-lite-typed";
12
+ declare const MailchimpApiError_base: Schema.TaggedErrorClass<"MailchimpApiError", {
13
+ status: import("effect/Schema").Number;
14
+ code: import("effect/Schema").optional<import("effect/Schema").String>;
15
+ message: import("effect/Schema").optional<import("effect/Schema").String>;
16
+ body: import("effect/Schema").Unknown;
17
+ /** Problem type URI, e.g. `https://mailchimp.com/developer/marketing/docs/errors/`. */
18
+ type: import("effect/Schema").optional<import("effect/Schema").String>;
19
+ title: import("effect/Schema").optional<import("effect/Schema").String>;
20
+ instance: import("effect/Schema").optional<import("effect/Schema").String>;
21
+ }>;
22
+ /**
23
+ * A problem document on a status the core map does not cover (405, 414, ...).
24
+ * Not categorised as a server error: those retry, and these never succeed.
25
+ */
26
+ export declare class MailchimpApiError extends /*@__PURE__*/ MailchimpApiError_base {
27
+ }
28
+ declare const UnknownMailchimpError_base: Schema.TaggedErrorClass<"UnknownMailchimpError", {
29
+ status: import("effect/Schema").Number;
30
+ code: import("effect/Schema").optional<import("effect/Schema").String>;
31
+ message: import("effect/Schema").optional<import("effect/Schema").String>;
32
+ body: import("effect/Schema").Unknown;
33
+ /** Problem type URI, e.g. `https://mailchimp.com/developer/marketing/docs/errors/`. */
34
+ type: import("effect/Schema").optional<import("effect/Schema").String>;
35
+ title: import("effect/Schema").optional<import("effect/Schema").String>;
36
+ instance: import("effect/Schema").optional<import("effect/Schema").String>;
37
+ }>;
38
+ /** A failure that is not a problem document at all. */
39
+ export declare class UnknownMailchimpError extends /*@__PURE__*/ UnknownMailchimpError_base {
40
+ }
41
+ declare const MailchimpParseError_base: Schema.TaggedErrorClass<"MailchimpParseError", {
42
+ readonly body: import("effect/Schema").Unknown;
43
+ readonly cause: import("effect/Schema").Unknown;
44
+ }> & (new (...args: any[]) => {
45
+ "@distilled.cloud/error/categories": {
46
+ ParseError: true;
47
+ };
48
+ });
49
+ /** A 2xx response that does not match the operation's output schema. */
50
+ export declare class MailchimpParseError extends /*@__PURE__*/ MailchimpParseError_base {
51
+ }
52
+ declare const MailchimpTransactionalError_base: Schema.TaggedErrorClass<"MailchimpTransactionalError", {
53
+ readonly status: import("effect/Schema").Number;
54
+ readonly code: import("effect/Schema").optional<import("effect/Schema").Number>;
55
+ readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
56
+ readonly message: import("effect/Schema").String;
57
+ readonly body: import("effect/Schema").Unknown;
58
+ }>;
59
+ /**
60
+ * A Transactional API failure (`{ status: "error", code, name, message }`)
61
+ * on a status that neither the operation nor the core map covers. `name` is
62
+ * the vendor's discriminator (`Invalid_Key`, `Unknown_Template`).
63
+ */
64
+ export declare class MailchimpTransactionalError extends /*@__PURE__*/ MailchimpTransactionalError_base {
65
+ }
66
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;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;;;;;;IAIhE,uFAAuF;;;;;AAMzF;;;GAGG;AACH,qBAAa,iBACX,SAAQ,aAAa,CAAC,sBAGrB;CAAG;;;;;;IAdJ,uFAAuF;;;;;AAgBzF,uDAAuD;AACvD,qBAAa,qBACX,SAAQ,aAAa,CAAC,0BAGrB;CAAG;;;;;;;;;AAEN,wEAAwE;AACxE,qBAAa,mBACX,SAAQ,aAAa,CAAC,wBAGU;CAAG;;;;;;;;AAErC;;;;GAIG;AACH,qBAAa,2BACX,SAAQ,aAAa,CAAC,gCASrB;CAAG"}
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$MailchimpApiError as MailchimpApiError, errors$MailchimpParseError as MailchimpParseError, errors$MailchimpTransactionalError as MailchimpTransactionalError, errors$NotFound as NotFound, errors$ServiceUnavailable as ServiceUnavailable, errors$TooManyRequests as TooManyRequests, errors$Unauthorized as Unauthorized, errors$UnknownMailchimpError as UnknownMailchimpError, errors$UnprocessableEntity as UnprocessableEntity } from "./_bundle/sdk.js";
package/lib/index.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @distilled.cloud/mailchimp -- Mailchimp Marketing and Transactional API SDK
3
+ * for Effect.
4
+ *
5
+ * `./services` is generated by `scripts/generate.ts`; everything else in this
6
+ * folder is hand-written. Marketing operations are exported flat; the
7
+ * Transactional API (formerly Mandrill) is under `Transactional`, with its
8
+ * own key.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import * as Effect from "effect/Effect";
13
+ * import * as FetchHttpClient from "effect/http/FetchHttpClient";
14
+ * import * as Mailchimp from "@distilled.cloud/mailchimp";
15
+ *
16
+ * const program = Mailchimp.setListMember({
17
+ * list_id: "a1b2c3d4e5",
18
+ * subscriber_hash: Mailchimp.subscriberHash("ada@example.com"),
19
+ * email_address: "ada@example.com",
20
+ * status_if_new: "subscribed",
21
+ * }).pipe(
22
+ * Effect.provide(Mailchimp.fromApiKey({ apiKey: "...-us21" })),
23
+ * Effect.provide(FetchHttpClient.layer),
24
+ * );
25
+ *
26
+ * const send = Mailchimp.Transactional.sendMessage({
27
+ * message: { to: [{ email: "ada@example.com" }], subject: "Hi", text: "..." },
28
+ * }).pipe(
29
+ * Effect.provide(Mailchimp.fromTransactionalApiKey({ apiKey: "md-..." })),
30
+ * Effect.provide(FetchHttpClient.layer),
31
+ * );
32
+ * ```
33
+ */
34
+ export * from "./credentials.ts";
35
+ export * as T from "./traits.ts";
36
+ export * as Retry from "./retry.ts";
37
+ export { MailchimpProtocol, MailchimpTransactionalProtocol, type MailchimpOpError, type MailchimpOpContext, type MailchimpTransactionalOpError, type MailchimpTransactionalOpContext, } from "./protocol.ts";
38
+ export * from "./errors.ts";
39
+ export { paginateOffset } from "./pagination.ts";
40
+ export { md5, subscriberHash } from "./subscriber-hash.ts";
41
+ export * as Services from "./services/index.ts";
42
+ export * from "./services/marketing.ts";
43
+ export * as Transactional from "./services/transactional.ts";
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,8BAA8B,EAC9B,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,6BAA6B,EAClC,KAAK,+BAA+B,GACrC,MAAM,eAAe,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,OAAO,KAAK,aAAa,MAAM,6BAA6B,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./credentials.js";
2
+ export * as T from "./traits.js";
3
+ export * as Retry from "./retry.js";
4
+ export { MailchimpProtocol, MailchimpTransactionalProtocol } from "./protocol.js";
5
+ export * from "./errors.js";
6
+ export { paginateOffset } from "./pagination.js";
7
+ export { md5, subscriberHash } from "./subscriber-hash.js";
8
+ export * as Services from "./services/index.js";
9
+ export * from "./services/marketing.js";
10
+ export * as Transactional from "./services/transactional.js";
@@ -0,0 +1,10 @@
1
+ export * from "./credentials.js";
2
+ export * as T from "./traits.js";
3
+ export * as Retry from "./retry.js";
4
+ export { MailchimpProtocol, MailchimpTransactionalProtocol } from "./protocol.js";
5
+ export * from "./errors.js";
6
+ export { paginateOffset } from "./pagination.js";
7
+ export { md5, subscriberHash } from "./subscriber-hash.js";
8
+ export * as Services from "./services.lazy/index.js";
9
+ export * from "./services.lazy/marketing.js";
10
+ export * as Transactional from "./services.lazy/transactional.js";
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,8BAA8B,GAK/B,MAAM,eAAe,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,OAAO,KAAK,aAAa,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { type PaginationStrategy } from "@distilled.cloud/core/pagination";
2
+ export { getItems } from "@distilled.cloud/core/pagination";
3
+ /**
4
+ * Stream of pages using `offset`/`count`.
5
+ *
6
+ * Stops on whichever comes first: `offset` reaching `total_items`, an empty
7
+ * page, or a page shorter than the requested `count` (the only end marker on
8
+ * operations that report no total).
9
+ */
10
+ export declare const paginateOffset: PaginationStrategy;
11
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,kCAAkC,CAAC;AAY1C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAK5D;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,EAAE,kBAwC5B,CAAC"}
@@ -0,0 +1 @@
1
+ export { pagination$getItems as getItems, pagination$paginateOffset as paginateOffset } from "./_bundle/sdk.js";