@sponson/adapters 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +4 -2
  3. package/dist/algolia.d.ts +6 -0
  4. package/dist/algolia.js +151 -0
  5. package/dist/algolia.js.map +1 -0
  6. package/dist/clerk.d.ts +8 -0
  7. package/dist/clerk.js +107 -0
  8. package/dist/clerk.js.map +1 -0
  9. package/dist/cloudflare.d.ts +25 -0
  10. package/dist/cloudflare.js +310 -0
  11. package/dist/cloudflare.js.map +1 -0
  12. package/dist/common.d.ts +73 -0
  13. package/dist/common.js +140 -0
  14. package/dist/common.js.map +1 -0
  15. package/dist/digest.d.ts +46 -0
  16. package/dist/digest.js +129 -0
  17. package/dist/digest.js.map +1 -0
  18. package/dist/digitalocean.d.ts +5 -0
  19. package/dist/digitalocean.js +243 -0
  20. package/dist/digitalocean.js.map +1 -0
  21. package/dist/http-adapter-action.d.ts +63 -0
  22. package/dist/http-adapter-action.js +369 -0
  23. package/dist/http-adapter-action.js.map +1 -0
  24. package/dist/http-adapter-auth.d.ts +88 -0
  25. package/dist/http-adapter-auth.js +437 -0
  26. package/dist/http-adapter-auth.js.map +1 -0
  27. package/dist/http-adapter-client.d.ts +51 -0
  28. package/dist/http-adapter-client.js +156 -0
  29. package/dist/http-adapter-client.js.map +1 -0
  30. package/dist/http-adapter-graphql.d.ts +39 -0
  31. package/dist/http-adapter-graphql.js +157 -0
  32. package/dist/http-adapter-graphql.js.map +1 -0
  33. package/dist/http-adapter-list.d.ts +33 -0
  34. package/dist/http-adapter-list.js +421 -0
  35. package/dist/http-adapter-list.js.map +1 -0
  36. package/dist/http-adapter-resource.d.ts +29 -0
  37. package/dist/http-adapter-resource.js +462 -0
  38. package/dist/http-adapter-resource.js.map +1 -0
  39. package/dist/http-adapter-spec.d.ts +216 -0
  40. package/dist/http-adapter-spec.js +660 -0
  41. package/dist/http-adapter-spec.js.map +1 -0
  42. package/dist/http-adapter.d.ts +16 -0
  43. package/dist/http-adapter.js +28 -0
  44. package/dist/http-adapter.js.map +1 -0
  45. package/dist/http.d.ts +179 -0
  46. package/dist/http.js +352 -0
  47. package/dist/http.js.map +1 -0
  48. package/dist/index.d.ts +28 -0
  49. package/dist/index.js +45 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/launchdarkly.d.ts +15 -0
  52. package/dist/launchdarkly.js +337 -0
  53. package/dist/launchdarkly.js.map +1 -0
  54. package/dist/manual.d.ts +13 -0
  55. package/dist/manual.js +201 -0
  56. package/dist/manual.js.map +1 -0
  57. package/dist/neon.d.ts +8 -0
  58. package/dist/neon.js +167 -0
  59. package/dist/neon.js.map +1 -0
  60. package/dist/netlify.d.ts +18 -0
  61. package/dist/netlify.js +436 -0
  62. package/dist/netlify.js.map +1 -0
  63. package/dist/planetscale.d.ts +10 -0
  64. package/dist/planetscale.js +311 -0
  65. package/dist/planetscale.js.map +1 -0
  66. package/dist/providers.d.ts +26 -0
  67. package/dist/providers.js +36 -0
  68. package/dist/providers.js.map +1 -0
  69. package/dist/recipes.d.ts +167 -0
  70. package/dist/recipes.js +246 -0
  71. package/dist/recipes.js.map +1 -0
  72. package/dist/secrets.d.ts +72 -0
  73. package/dist/secrets.js +476 -0
  74. package/dist/secrets.js.map +1 -0
  75. package/dist/sigv4.d.ts +56 -0
  76. package/dist/sigv4.js +118 -0
  77. package/dist/sigv4.js.map +1 -0
  78. package/dist/supabase.d.ts +9 -0
  79. package/dist/supabase.js +385 -0
  80. package/dist/supabase.js.map +1 -0
  81. package/dist/vercel.d.ts +8 -0
  82. package/dist/vercel.js +475 -0
  83. package/dist/vercel.js.map +1 -0
  84. package/dist/xata.d.ts +8 -0
  85. package/dist/xata.js +142 -0
  86. package/dist/xata.js.map +1 -0
  87. package/dist/xml.d.ts +25 -0
  88. package/dist/xml.js +211 -0
  89. package/dist/xml.js.map +1 -0
  90. package/package.json +58 -3
  91. package/recipes/amplify.yaml +147 -0
  92. package/recipes/auth0.yaml +178 -0
  93. package/recipes/azure_swa.yaml +116 -0
  94. package/recipes/cloud_run.yaml +97 -0
  95. package/recipes/cloudflare.yaml +108 -0
  96. package/recipes/cockroachdb.yaml +132 -0
  97. package/recipes/configcat.yaml +123 -0
  98. package/recipes/datadog.yaml +136 -0
  99. package/recipes/firebase.yaml +84 -0
  100. package/recipes/flagsmith.yaml +98 -0
  101. package/recipes/fly.yaml +97 -0
  102. package/recipes/fly_machines.yaml +67 -0
  103. package/recipes/gcs.yaml +102 -0
  104. package/recipes/github.yaml +123 -0
  105. package/recipes/growthbook.yaml +124 -0
  106. package/recipes/heroku.yaml +98 -0
  107. package/recipes/honeycomb.yaml +89 -0
  108. package/recipes/inngest.yaml +97 -0
  109. package/recipes/kinde.yaml +120 -0
  110. package/recipes/mongodb_atlas.yaml +119 -0
  111. package/recipes/okta.yaml +177 -0
  112. package/recipes/posthog.yaml +127 -0
  113. package/recipes/postmark.yaml +105 -0
  114. package/recipes/postmark_server.yaml +93 -0
  115. package/recipes/prisma.yaml +150 -0
  116. package/recipes/qstash.yaml +134 -0
  117. package/recipes/railway.yaml +130 -0
  118. package/recipes/render.yaml +103 -0
  119. package/recipes/resend.yaml +130 -0
  120. package/recipes/s3.yaml +108 -0
  121. package/recipes/sendgrid.yaml +165 -0
  122. package/recipes/sentry.yaml +158 -0
  123. package/recipes/split.yaml +121 -0
  124. package/recipes/statsig.yaml +124 -0
  125. package/recipes/stripe.yaml +310 -0
  126. package/recipes/stytch.yaml +113 -0
  127. package/recipes/svix.yaml +109 -0
  128. package/recipes/turso.yaml +98 -0
  129. package/recipes/unleash.yaml +149 -0
  130. package/recipes/upstash.yaml +130 -0
  131. package/recipes/vercel.yaml +116 -0
  132. package/recipes/workos.yaml +70 -0
@@ -0,0 +1,216 @@
1
+ /**
2
+ * The generic `http` adapter's plan syntax, parsed and checked: the per-API provider block, the params of
3
+ * `http.resource` and `http.list_item`, JSON pointers and path placeholders. Pure: no I/O. Every malformed spec is
4
+ * a PARAM_INVALID (or PLAN_INVALID for the provider block) naming the field at fault. See ADR 0017 and
5
+ * docs/plan-format.md (`http.resource`, `http.list_item`).
6
+ */
7
+ import { type OutputSpec } from "@sponson/core";
8
+ import { type Auth } from "./http-adapter-auth.js";
9
+ import { type GraphqlSpec } from "./http-adapter-graphql.js";
10
+ export type { Auth } from "./http-adapter-auth.js";
11
+ export declare const ADAPTER = "http";
12
+ /** A JSON pointer's reference tokens. `""` is the whole document. */
13
+ export declare function pointerTokens(pointer: string): string[];
14
+ /** A field as the plan writes it: `name` (a top-level field) or a JSON pointer `/config/url`. */
15
+ export declare function fieldTokens(field: string): string[];
16
+ /** The value at `tokens` in `doc`, or undefined. */
17
+ export declare function at(doc: unknown, tokens: string[]): unknown;
18
+ /** A copy of `doc` (an object) with `value` set at `tokens`, creating objects on the way. */
19
+ export declare function setAt(doc: Record<string, unknown>, tokens: string[], value: unknown): Record<string, unknown>;
20
+ /** Objects merged recursively (`b` wins); anything else is replaced by `b`. */
21
+ export declare function deepMerge(a: Record<string, unknown>, b: Record<string, unknown>): Record<string, unknown>;
22
+ /** The request body that sets every field of `fields` (names or pointers), skipping `skip`. */
23
+ export declare function bodyOf(fields: Record<string, unknown>, skip?: (v: unknown) => boolean): Record<string, unknown>;
24
+ /** `item` reduced to the declared fields, in the one canonical form both hashes and diffs use. Absent is null. */
25
+ export declare function projection(item: unknown, fields: string[]): Record<string, unknown>;
26
+ /** The hash of a resource's declared state: `sha256(canonicalJson(projection))`. */
27
+ export declare function stateHash(state: unknown): string;
28
+ /** True when the value is `{ keep: true }`'s marker. */
29
+ export declare function isKeep(v: unknown): boolean;
30
+ /** The first pending or secret marker anywhere in `v`, if any. */
31
+ export declare function firstMarker(v: unknown): string | undefined;
32
+ /** The `{name}` and `{+name}` placeholders of a path, by name. */
33
+ export declare function placeholders(path: string): string[];
34
+ /**
35
+ * `path` with `{id}` and every `{var}` substituted (URI-encoded; `{+var}` keeps `/` and `:`); undefined when a value
36
+ * is not known yet (a pending reference).
37
+ */
38
+ export declare function fillPath(path: string, vars: Record<string, unknown>, id?: string): string | undefined;
39
+ /** One API's configuration, from `providers.http.<api>`. */
40
+ export interface ApiConfig {
41
+ baseUrl: string;
42
+ baseUrlEnv?: string;
43
+ auth: Auth;
44
+ headers: Record<string, string>;
45
+ encoding: "json" | "form" | "xml";
46
+ /** A versioned media type sent as `Accept` and as the `Content-Type` of JSON bodies (Atlas `application/vnd.atlas.2023-01-01+json`). */
47
+ mediaType?: string;
48
+ /** The API is a production system: lines through it need Sponson's approval (`writesEnvironment`). */
49
+ production: boolean;
50
+ /**
51
+ * Credentials this API refuses: a value starting with one of `prefixes` (Stripe's `sk_live_`) is PROVIDER_AUTH
52
+ * before any request, unless the variable `unlessEnv` is `1` or `true`.
53
+ */
54
+ refuse?: {
55
+ prefixes: string[];
56
+ unlessEnv: string;
57
+ };
58
+ }
59
+ /**
60
+ * `OpSpec.writesEnvironment` for both ops: `production` when the line's API block says `production: true` (a live
61
+ * Stripe account, a production tenant), so the run needs approval whatever its environment; otherwise not
62
+ * environment-specific. `provider` is the block `apiBlock` narrowed to, already checked.
63
+ */
64
+ export declare function apiEnvironment(_params: Record<string, unknown>, _ctx: unknown, provider?: Record<string, unknown>): "production" | null;
65
+ /**
66
+ * One API block, checked. `where` names it in messages (`providers.http.statsig`). `authOptional`: a block without
67
+ * `auth` sends no credential (the `manual` adapter's verify requests to public endpoints); the `http` adapter's
68
+ * blocks always need one.
69
+ */
70
+ export declare function parseApi(block: Record<string, unknown>, where: string, opts?: {
71
+ authOptional?: boolean;
72
+ }): ApiConfig;
73
+ /**
74
+ * `OpSpec.providerFor` for both ops: the `providers.http.<api>` block the line's `api` names, checked. Lines of
75
+ * different APIs therefore have independent ledger identities.
76
+ */
77
+ export declare function apiBlock(block: Record<string, unknown>, params: Record<string, unknown>): Record<string, unknown>;
78
+ /** What `destroy` does with what Sponson created: remove it (the default), or leave it in place. */
79
+ export type DestroyMode = "delete" | "keep";
80
+ /**
81
+ * One request of a spec: method and path (placeholders unfilled), the extra body it sends, its media type, the
82
+ * headers it sends (values may be references until apply), and whether the declared `fields` go in its body
83
+ * (`send_fields: false` when the request carries them elsewhere, such as in headers); or a GraphQL request (`path`
84
+ * is then "", the endpoint being the API's base URL).
85
+ */
86
+ export interface RequestSpec {
87
+ method: string;
88
+ path: string;
89
+ body: Record<string, unknown>;
90
+ contentType?: string;
91
+ headers: Record<string, unknown>;
92
+ sendFields: boolean;
93
+ graphql?: GraphqlSpec;
94
+ }
95
+ /** How a resource is located by natural key: a list, the array in it, and the fields that must match. */
96
+ export interface FindSpec {
97
+ /** "" for a GraphQL find. */
98
+ path: string;
99
+ graphql?: GraphqlSpec;
100
+ listPath: string;
101
+ match: Record<string, unknown>;
102
+ /** Pointer to the next page's cursor in a list response, and the query parameter that sends it back. */
103
+ next?: {
104
+ path: string;
105
+ param: string;
106
+ };
107
+ }
108
+ /**
109
+ * Declared output: a pointer into the object, whether it must never be shown, and whether the provider reveals it
110
+ * only in the answer that creates the object (`once`, ADR 0018: an API key's token, a signing secret).
111
+ */
112
+ export interface OutputDecl {
113
+ path: string;
114
+ sensitive: boolean;
115
+ once: boolean;
116
+ }
117
+ /** `http.resource` params, checked. Values may still be markers. */
118
+ export interface ResourceSpec {
119
+ api: string;
120
+ vars: Record<string, unknown>;
121
+ /** The line's own credential value (`credential`), replacing the API block's variable; a marker while pending. */
122
+ credential?: unknown;
123
+ /** `locate`: the create's answer is not the object (the parent, an acknowledgement); find it afterwards. */
124
+ create: RequestSpec & {
125
+ idempotencyKey: boolean;
126
+ locate: boolean;
127
+ };
128
+ read?: {
129
+ path: string;
130
+ graphql?: GraphqlSpec;
131
+ };
132
+ find?: FindSpec;
133
+ update?: RequestSpec;
134
+ /**
135
+ * How the object is removed. A `POST` with a `body` archives instead of deleting (Stripe prices cannot be deleted,
136
+ * only set `active: false`); the body is part of the record id, so destroy needs nothing but the ledger. Or a
137
+ * GraphQL mutation.
138
+ */
139
+ delete: {
140
+ method: string;
141
+ path: string;
142
+ body?: Record<string, unknown>;
143
+ graphql?: GraphqlSpec;
144
+ };
145
+ destroy: DestroyMode;
146
+ itemPath: string;
147
+ idPath: string;
148
+ fields: Record<string, unknown>;
149
+ outputs: Record<string, OutputDecl>;
150
+ /** Statuses that mean "it exists already" on create (besides 409 and the client's conflict wording). */
151
+ existsStatus: number[];
152
+ /** Statuses that mean "it is gone" on read and delete (besides 404). */
153
+ goneStatus: number[];
154
+ }
155
+ /** A request's headers with their resolved values, as strings; PARAM_INVALID for a value that is not a scalar. */
156
+ export declare function requestHeaders(req: RequestSpec, param: string): Record<string, string>;
157
+ /** `http.resource` params, checked; PARAM_INVALID naming the field otherwise. */
158
+ export declare function parseResource(line: Record<string, unknown>): ResourceSpec;
159
+ /**
160
+ * `OpSpec.credentialInputs` for both ops: the line's `credential`, which the engine checks is a masked reference.
161
+ * Its own rules (its form, `destroy: keep`) are checked here too, so a wrong line fails before any request.
162
+ */
163
+ export declare function credentialInputs(kind: "resource" | "list_item"): (params: Record<string, unknown>) => string[];
164
+ /** The outputs one `http.resource` line declares: always `id`, plus its `outputs` (`once` ones as in ADR 0018). */
165
+ export declare function resourceOutputs(line: Record<string, unknown>): Record<string, OutputSpec>;
166
+ /**
167
+ * How the parent holds its items: a JSON array (`array`), one string of values joined by `separator`
168
+ * (`delimited`, such as a comma-separated allow-list), or a map of name to value (`map`, such as config vars,
169
+ * where writing `null` for a name deletes it).
170
+ */
171
+ export type ListShape = "array" | "delimited" | "map";
172
+ /**
173
+ * What a write of the parent sends besides the collection: nothing (`field`; a keyed map's one entry, as a merge
174
+ * patch), nothing but the whole collection (`collection`; a keyed map too, for an API that replaces the map it is
175
+ * sent), the whole object read just before (`parent`), or the listed fields of it (names or pointers), for a
176
+ * replace that resets what it is not sent.
177
+ */
178
+ export type ParentSend = "field" | "parent" | "collection" | string[];
179
+ /** `http.list_item` params, checked. */
180
+ export interface ListItemSpec {
181
+ api: string;
182
+ vars: Record<string, unknown>;
183
+ /** The line's own credential value (`credential`), replacing the API block's variable; a marker while pending. */
184
+ credential?: unknown;
185
+ /**
186
+ * `itemPath`: where the parent object is in the read answer (`/feature` for `{ feature: {...} }`); default the whole
187
+ * body. `ifMissing: empty`: a 404 parent reads as an empty collection; `whenEmpty: delete`: an empty collection is
188
+ * removed with DELETE instead of written. `readMethod: POST`: the parent is read with a POST without a body (an
189
+ * Azure Resource Manager list action such as `listAppSettings`), which changes nothing. `writeListPath`: where a
190
+ * write puts the collection, when the API names it otherwise than its read (Kinde reads `{ redirect_urls }` and replaces with `{ urls }`); default `list_path`.
191
+ */
192
+ parent: {
193
+ path: string;
194
+ readPath: string;
195
+ readMethod: "GET" | "POST";
196
+ method: string;
197
+ send: ParentSend;
198
+ itemPath: string;
199
+ contentType?: string;
200
+ ifMissing: "error" | "empty";
201
+ whenEmpty: "write" | "delete";
202
+ writeListPath?: string;
203
+ };
204
+ listPath: string;
205
+ shape: ListShape;
206
+ separator: string;
207
+ /** The item: a value or a map (`array`), a string (`delimited`), the entry's name (`map`). */
208
+ item: unknown;
209
+ /** For map items of an `array`: the field that identifies an item in the list. */
210
+ keyField?: string;
211
+ /** For `map`: the entry's value. */
212
+ value?: unknown;
213
+ destroy: DestroyMode;
214
+ }
215
+ /** `http.list_item` params, checked; PARAM_INVALID naming the field otherwise. */
216
+ export declare function parseListItem(line: Record<string, unknown>): ListItemSpec;