@voidhash/api-spec 0.0.1-alpha.1-canary.2.1.223955
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.md +21 -0
- package/README.md +43 -0
- package/package.json +37 -0
- package/src/api.ts +420 -0
- package/src/auth.ts +102 -0
- package/src/changeset.ts +204 -0
- package/src/errors/admin.ts +11 -0
- package/src/errors/analytics.ts +29 -0
- package/src/errors/api-key.ts +20 -0
- package/src/errors/billing.ts +29 -0
- package/src/errors/changeset.ts +11 -0
- package/src/errors/common.ts +30 -0
- package/src/errors/customer.ts +37 -0
- package/src/errors/index.ts +18 -0
- package/src/errors/organization.ts +20 -0
- package/src/errors/payment-provider.ts +74 -0
- package/src/errors/paywall-location.ts +11 -0
- package/src/errors/paywall.ts +38 -0
- package/src/errors/perk.ts +33 -0
- package/src/errors/product-perk.ts +20 -0
- package/src/errors/product.ts +33 -0
- package/src/errors/project.ts +24 -0
- package/src/errors/sdk.ts +42 -0
- package/src/errors/user.ts +11 -0
- package/src/errors/webhook.ts +38 -0
- package/src/index.ts +5 -0
- package/src/middlewares.ts +32 -0
- package/src/schema.ts +535 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HttpApiSchema } from "@effect/platform";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
/** Generic SDK service error */
|
|
5
|
+
export class SdkServiceError extends Schema.TaggedError<SdkServiceError>()(
|
|
6
|
+
"SdkServiceError",
|
|
7
|
+
{
|
|
8
|
+
cause: Schema.String,
|
|
9
|
+
},
|
|
10
|
+
HttpApiSchema.annotations({ status: 500 })
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
/** SDK customer not found */
|
|
14
|
+
export class SdkCustomerNotFoundError extends Schema.TaggedError<SdkCustomerNotFoundError>()(
|
|
15
|
+
"SdkCustomerNotFoundError",
|
|
16
|
+
{
|
|
17
|
+
message: Schema.String,
|
|
18
|
+
},
|
|
19
|
+
HttpApiSchema.annotations({ status: 404 })
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
/** SDK customer already identified */
|
|
23
|
+
export class SdkCustomerAlreadyIdentifiedError extends Schema.TaggedError<SdkCustomerAlreadyIdentifiedError>()(
|
|
24
|
+
"SdkCustomerAlreadyIdentifiedError",
|
|
25
|
+
{
|
|
26
|
+
appUserId: Schema.String,
|
|
27
|
+
},
|
|
28
|
+
HttpApiSchema.annotations({ status: 409 })
|
|
29
|
+
) {
|
|
30
|
+
toString(): string {
|
|
31
|
+
return `The following customer was already identified: ${this.appUserId}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** SDK validation error */
|
|
36
|
+
export class SdkValidationError extends Schema.TaggedError<SdkValidationError>()(
|
|
37
|
+
"SdkValidationError",
|
|
38
|
+
{
|
|
39
|
+
message: Schema.String,
|
|
40
|
+
},
|
|
41
|
+
HttpApiSchema.annotations({ status: 400 })
|
|
42
|
+
) {}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpApiSchema } from "@effect/platform";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
/** Generic user service error */
|
|
5
|
+
export class UserServiceError extends Schema.TaggedError<UserServiceError>()(
|
|
6
|
+
"UserServiceError",
|
|
7
|
+
{
|
|
8
|
+
cause: Schema.String,
|
|
9
|
+
},
|
|
10
|
+
HttpApiSchema.annotations({ status: 500 })
|
|
11
|
+
) {}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { HttpApiSchema } from "@effect/platform";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
/** Generic webhook service error */
|
|
5
|
+
export class WebhookServiceError extends Schema.TaggedError<WebhookServiceError>()(
|
|
6
|
+
"WebhookServiceError",
|
|
7
|
+
{
|
|
8
|
+
cause: Schema.String,
|
|
9
|
+
},
|
|
10
|
+
HttpApiSchema.annotations({ status: 500 })
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
/** Webhook endpoint not found */
|
|
14
|
+
export class WebhookEndpointNotFoundError extends Schema.TaggedError<WebhookEndpointNotFoundError>()(
|
|
15
|
+
"WebhookEndpointNotFoundError",
|
|
16
|
+
{
|
|
17
|
+
endpointId: Schema.String,
|
|
18
|
+
},
|
|
19
|
+
HttpApiSchema.annotations({ status: 404 })
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
/** Webhook delivery not found */
|
|
23
|
+
export class WebhookDeliveryNotFoundError extends Schema.TaggedError<WebhookDeliveryNotFoundError>()(
|
|
24
|
+
"WebhookDeliveryNotFoundError",
|
|
25
|
+
{
|
|
26
|
+
deliveryId: Schema.String,
|
|
27
|
+
},
|
|
28
|
+
HttpApiSchema.annotations({ status: 404 })
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
/** Webhook validation error */
|
|
32
|
+
export class WebhookValidationError extends Schema.TaggedError<WebhookValidationError>()(
|
|
33
|
+
"WebhookValidationError",
|
|
34
|
+
{
|
|
35
|
+
message: Schema.String,
|
|
36
|
+
},
|
|
37
|
+
HttpApiSchema.annotations({ status: 400 })
|
|
38
|
+
) {}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { HttpApiMiddleware, HttpApiSecurity } from "@effect/platform";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
import { ApiAuthSession } from "./auth";
|
|
5
|
+
import { AuthenticationError, NotAuthenticatedError } from "./errors";
|
|
6
|
+
|
|
7
|
+
export class AuthMiddleware extends HttpApiMiddleware.Tag<AuthMiddleware>()(
|
|
8
|
+
"Http/AuthenticationMiddleware",
|
|
9
|
+
{
|
|
10
|
+
// Optionally define the error schema for the middleware
|
|
11
|
+
failure: Schema.Union(AuthenticationError, NotAuthenticatedError),
|
|
12
|
+
provides: ApiAuthSession,
|
|
13
|
+
security: {
|
|
14
|
+
apiKey: HttpApiSecurity.apiKey({
|
|
15
|
+
in: "header",
|
|
16
|
+
key: "x-api-key",
|
|
17
|
+
}),
|
|
18
|
+
betterAuthCookie: HttpApiSecurity.apiKey({
|
|
19
|
+
in: "cookie",
|
|
20
|
+
key: "__Secure-better-auth.session_token",
|
|
21
|
+
}),
|
|
22
|
+
publishableKey: HttpApiSecurity.apiKey({
|
|
23
|
+
in: "header",
|
|
24
|
+
key: "x-publishable-key",
|
|
25
|
+
}),
|
|
26
|
+
secretKey: HttpApiSecurity.apiKey({
|
|
27
|
+
in: "header",
|
|
28
|
+
key: "x-secret-key",
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
) {}
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import { HttpApiSchema } from "@effect/platform";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
import { ChangesetSchema } from "./changeset";
|
|
5
|
+
|
|
6
|
+
export const PublishableKeyAuthHeaders = Schema.Struct({
|
|
7
|
+
"x-app-user-id": Schema.String,
|
|
8
|
+
"x-publishable-key": Schema.String,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const ApiKeyAuthHeaders = Schema.Struct({
|
|
12
|
+
"x-api-key": Schema.String,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const SecretKeyAuthHeaders = Schema.Struct({
|
|
16
|
+
"x-secret-key": Schema.String,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// ========================================================
|
|
20
|
+
// Auth
|
|
21
|
+
// ========================================================
|
|
22
|
+
|
|
23
|
+
const SessionAuthMethods = Schema.Union(
|
|
24
|
+
Schema.Literal("api-key"),
|
|
25
|
+
Schema.Literal("publishable-key"),
|
|
26
|
+
Schema.Literal("secret-key")
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const Session = Schema.Struct({
|
|
30
|
+
method: SessionAuthMethods,
|
|
31
|
+
name: Schema.String,
|
|
32
|
+
organizations: Schema.Array(
|
|
33
|
+
Schema.Struct({
|
|
34
|
+
id: Schema.String,
|
|
35
|
+
name: Schema.String,
|
|
36
|
+
slug: Schema.String,
|
|
37
|
+
})
|
|
38
|
+
),
|
|
39
|
+
projects: Schema.Array(
|
|
40
|
+
Schema.Struct({
|
|
41
|
+
id: Schema.String,
|
|
42
|
+
name: Schema.String,
|
|
43
|
+
organizationId: Schema.String,
|
|
44
|
+
slug: Schema.String,
|
|
45
|
+
})
|
|
46
|
+
),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// ========================================================
|
|
50
|
+
// API Keys
|
|
51
|
+
// ========================================================
|
|
52
|
+
|
|
53
|
+
export class ApiKey extends Schema.Class<ApiKey>("ApiKey")({
|
|
54
|
+
end: Schema.String,
|
|
55
|
+
id: Schema.String,
|
|
56
|
+
isPublic: Schema.Boolean,
|
|
57
|
+
name: Schema.String,
|
|
58
|
+
prefix: Schema.String,
|
|
59
|
+
projectId: Schema.String,
|
|
60
|
+
rawKey: Schema.optional(Schema.String),
|
|
61
|
+
}) {}
|
|
62
|
+
|
|
63
|
+
export class ApiKeyWithRawKey extends Schema.Class<ApiKeyWithRawKey>(
|
|
64
|
+
"ApiKeyWithRawKey"
|
|
65
|
+
)({
|
|
66
|
+
end: Schema.String,
|
|
67
|
+
id: Schema.String,
|
|
68
|
+
isPublic: Schema.Boolean,
|
|
69
|
+
name: Schema.String,
|
|
70
|
+
prefix: Schema.String,
|
|
71
|
+
projectId: Schema.String,
|
|
72
|
+
rawKey: Schema.String,
|
|
73
|
+
}) {}
|
|
74
|
+
|
|
75
|
+
export class CreateSecretKeyBody extends Schema.Class<CreateSecretKeyBody>(
|
|
76
|
+
"CreateSecretKeyBody"
|
|
77
|
+
)({
|
|
78
|
+
name: Schema.String,
|
|
79
|
+
projectId: Schema.String,
|
|
80
|
+
}) {}
|
|
81
|
+
|
|
82
|
+
export const ApiKeyIdParam = HttpApiSchema.param("apiKeyId", Schema.String);
|
|
83
|
+
|
|
84
|
+
// ========================================================
|
|
85
|
+
// Customers
|
|
86
|
+
// ========================================================
|
|
87
|
+
|
|
88
|
+
export class Customer extends Schema.Class<Customer>("Customer")({
|
|
89
|
+
appUserId: Schema.String,
|
|
90
|
+
email: Schema.NullOr(Schema.String),
|
|
91
|
+
id: Schema.String,
|
|
92
|
+
name: Schema.NullOr(Schema.String),
|
|
93
|
+
}) {}
|
|
94
|
+
|
|
95
|
+
export class CreateCustomerBody extends Schema.Class<CreateCustomerBody>(
|
|
96
|
+
"CreateCustomerBody"
|
|
97
|
+
)({
|
|
98
|
+
appUserId: Schema.String,
|
|
99
|
+
email: Schema.optional(Schema.String),
|
|
100
|
+
name: Schema.optional(Schema.String),
|
|
101
|
+
}) {}
|
|
102
|
+
|
|
103
|
+
export const CustomerIdParam = HttpApiSchema.param("customerId", Schema.String);
|
|
104
|
+
|
|
105
|
+
export const AppUserIdParam = HttpApiSchema.param("appUserId", Schema.String);
|
|
106
|
+
|
|
107
|
+
// ========================================================
|
|
108
|
+
// Organizations
|
|
109
|
+
// ========================================================
|
|
110
|
+
|
|
111
|
+
export class CreateOrganizationBody extends Schema.Class<CreateOrganizationBody>(
|
|
112
|
+
"CreateOrganizationBody"
|
|
113
|
+
)({
|
|
114
|
+
name: Schema.String,
|
|
115
|
+
}) {}
|
|
116
|
+
|
|
117
|
+
export class Organization extends Schema.Class<Organization>("Organization")({
|
|
118
|
+
id: Schema.String,
|
|
119
|
+
name: Schema.String,
|
|
120
|
+
slug: Schema.String,
|
|
121
|
+
}) {}
|
|
122
|
+
|
|
123
|
+
// ========================================================
|
|
124
|
+
// Perks
|
|
125
|
+
// ========================================================
|
|
126
|
+
|
|
127
|
+
export class Perk extends Schema.Class<Perk>("Perk")({
|
|
128
|
+
id: Schema.String,
|
|
129
|
+
name: Schema.String,
|
|
130
|
+
projectId: Schema.String,
|
|
131
|
+
slug: Schema.String,
|
|
132
|
+
}) {}
|
|
133
|
+
|
|
134
|
+
// ========================================================
|
|
135
|
+
// Paywall Locations
|
|
136
|
+
// ========================================================
|
|
137
|
+
|
|
138
|
+
export class PaywallLocation extends Schema.Class<PaywallLocation>("PaywallLocation")({
|
|
139
|
+
description: Schema.NullOr(Schema.String),
|
|
140
|
+
id: Schema.String,
|
|
141
|
+
name: Schema.String,
|
|
142
|
+
projectId: Schema.String,
|
|
143
|
+
slug: Schema.String,
|
|
144
|
+
}) {}
|
|
145
|
+
|
|
146
|
+
// ========================================================
|
|
147
|
+
// Products
|
|
148
|
+
// ========================================================
|
|
149
|
+
|
|
150
|
+
export const ProductType = Schema.Literal(
|
|
151
|
+
"subscription",
|
|
152
|
+
"one-time",
|
|
153
|
+
"one-time-consumable"
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
export class Product extends Schema.Class<Product>("Product")({
|
|
157
|
+
id: Schema.String,
|
|
158
|
+
name: Schema.String,
|
|
159
|
+
projectId: Schema.String,
|
|
160
|
+
slug: Schema.String,
|
|
161
|
+
type: ProductType,
|
|
162
|
+
}) {}
|
|
163
|
+
|
|
164
|
+
// ========================================================
|
|
165
|
+
// Product Perks
|
|
166
|
+
// ========================================================
|
|
167
|
+
|
|
168
|
+
export const ProductIdParam = HttpApiSchema.param("productId", Schema.String);
|
|
169
|
+
|
|
170
|
+
export class ProductPerk extends Schema.Class<ProductPerk>("ProductPerk")({
|
|
171
|
+
id: Schema.String,
|
|
172
|
+
perkId: Schema.String,
|
|
173
|
+
productId: Schema.String,
|
|
174
|
+
}) {}
|
|
175
|
+
|
|
176
|
+
// ========================================================
|
|
177
|
+
// Payment Provider Configurations
|
|
178
|
+
// ========================================================
|
|
179
|
+
|
|
180
|
+
export class PaymentProviderConfiguration extends Schema.Class<PaymentProviderConfiguration>(
|
|
181
|
+
"PaymentProviderConfiguration"
|
|
182
|
+
)({
|
|
183
|
+
enabled: Schema.Boolean,
|
|
184
|
+
id: Schema.String,
|
|
185
|
+
name: Schema.String,
|
|
186
|
+
projectId: Schema.String,
|
|
187
|
+
providerId: Schema.String,
|
|
188
|
+
}) {}
|
|
189
|
+
|
|
190
|
+
// ========================================================
|
|
191
|
+
// Payment Provider Products
|
|
192
|
+
// ========================================================
|
|
193
|
+
|
|
194
|
+
export class PaymentProviderProduct extends Schema.Class<PaymentProviderProduct>(
|
|
195
|
+
"PaymentProviderProduct"
|
|
196
|
+
)({
|
|
197
|
+
configuration: Schema.Record({ key: Schema.String, value: Schema.Unknown }),
|
|
198
|
+
id: Schema.String,
|
|
199
|
+
paymentProviderConfigurationId: Schema.String,
|
|
200
|
+
productId: Schema.String,
|
|
201
|
+
providerId: Schema.String,
|
|
202
|
+
}) {}
|
|
203
|
+
|
|
204
|
+
// ========================================================
|
|
205
|
+
// Changesets
|
|
206
|
+
// ========================================================
|
|
207
|
+
|
|
208
|
+
export class DeployChangesetBody extends Schema.Class<DeployChangesetBody>(
|
|
209
|
+
"DeployChangesetBody"
|
|
210
|
+
)({
|
|
211
|
+
changeset: ChangesetSchema,
|
|
212
|
+
}) {}
|
|
213
|
+
|
|
214
|
+
export class DeployChangesetResponse extends Schema.Class<DeployChangesetResponse>(
|
|
215
|
+
"DeployChangesetResponse"
|
|
216
|
+
)({
|
|
217
|
+
deploymentId: Schema.String,
|
|
218
|
+
}) {}
|
|
219
|
+
|
|
220
|
+
// ========================================================
|
|
221
|
+
// Projects
|
|
222
|
+
// ========================================================
|
|
223
|
+
|
|
224
|
+
export class CreateProjectBody extends Schema.Class<CreateProjectBody>(
|
|
225
|
+
"CreateProjectBody"
|
|
226
|
+
)({
|
|
227
|
+
name: Schema.String,
|
|
228
|
+
organizationId: Schema.String,
|
|
229
|
+
}) {}
|
|
230
|
+
|
|
231
|
+
export class Project extends Schema.Class<Project>("Project")({
|
|
232
|
+
id: Schema.String,
|
|
233
|
+
name: Schema.String,
|
|
234
|
+
slug: Schema.String,
|
|
235
|
+
}) {}
|
|
236
|
+
|
|
237
|
+
export const OrganizationIdParam = HttpApiSchema.param(
|
|
238
|
+
"organizationId",
|
|
239
|
+
Schema.String
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
// ========================================================
|
|
243
|
+
// SDK
|
|
244
|
+
// ========================================================
|
|
245
|
+
|
|
246
|
+
const CommonSdkHeaders = Schema.Struct({
|
|
247
|
+
"x-client-bundle-id": Schema.String,
|
|
248
|
+
"x-client-locale": Schema.optional(Schema.String),
|
|
249
|
+
"x-client-version": Schema.optional(Schema.String),
|
|
250
|
+
"x-is-backgrounded": Schema.Literal("false"),
|
|
251
|
+
"x-is-debug-build": Schema.Literal("true", "false"),
|
|
252
|
+
"x-nonce": Schema.optional(Schema.String),
|
|
253
|
+
"x-observer-mode": Schema.Literal("true", "false"),
|
|
254
|
+
"x-platform": Schema.String,
|
|
255
|
+
"x-platform-brand": Schema.optional(Schema.String),
|
|
256
|
+
"x-platform-device": Schema.optional(Schema.String),
|
|
257
|
+
"x-platform-flavor": Schema.Literal("native"),
|
|
258
|
+
"x-platform-flavor-version": Schema.optional(Schema.String),
|
|
259
|
+
"x-platform-version": Schema.optional(Schema.String),
|
|
260
|
+
"x-preferred-locales": Schema.optional(Schema.String),
|
|
261
|
+
"x-sdk": Schema.Literal("react-native"),
|
|
262
|
+
"x-sdk-version": Schema.String,
|
|
263
|
+
"x-storefront": Schema.optional(Schema.String),
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
export const SdkHeaders = Schema.Struct({
|
|
267
|
+
...PublishableKeyAuthHeaders.fields,
|
|
268
|
+
...CommonSdkHeaders.fields,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// SDK Identify
|
|
272
|
+
export class SdkIdentifyBody extends Schema.Class<SdkIdentifyBody>(
|
|
273
|
+
"SdkIdentifyBody"
|
|
274
|
+
)({
|
|
275
|
+
appUserId: Schema.String,
|
|
276
|
+
email: Schema.optional(Schema.String),
|
|
277
|
+
name: Schema.optional(Schema.String),
|
|
278
|
+
}) {}
|
|
279
|
+
|
|
280
|
+
// SDK Sync Customer Attributes
|
|
281
|
+
export class SdkSyncCustomerAttributesBody extends Schema.Class<SdkSyncCustomerAttributesBody>(
|
|
282
|
+
"SdkSyncCustomerAttributesBody"
|
|
283
|
+
)({
|
|
284
|
+
email: Schema.optional(Schema.String),
|
|
285
|
+
name: Schema.optional(Schema.String),
|
|
286
|
+
}) {}
|
|
287
|
+
|
|
288
|
+
export const SdkSyncTransactionBody = Schema.Struct({
|
|
289
|
+
platform: Schema.Literal("ios", "android"),
|
|
290
|
+
productId: Schema.String,
|
|
291
|
+
purchaseDate: Schema.Number,
|
|
292
|
+
purchaseToken: Schema.optional(Schema.String),
|
|
293
|
+
quantity: Schema.Number,
|
|
294
|
+
receipt: Schema.optional(Schema.String),
|
|
295
|
+
transactionId: Schema.String,
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
export class SdkSyncTransactionResponse extends Schema.Class<SdkSyncTransactionResponse>(
|
|
299
|
+
"SdkSyncTransactionResponse"
|
|
300
|
+
)({
|
|
301
|
+
accepted: Schema.Boolean,
|
|
302
|
+
}) {}
|
|
303
|
+
|
|
304
|
+
export class SdkCustomer extends Schema.Class<SdkCustomer>("SdkCustomer")({
|
|
305
|
+
appUserId: Schema.String,
|
|
306
|
+
customerId: Schema.String,
|
|
307
|
+
email: Schema.NullOr(Schema.String),
|
|
308
|
+
name: Schema.NullOr(Schema.String),
|
|
309
|
+
}) {}
|
|
310
|
+
|
|
311
|
+
// ========================================================
|
|
312
|
+
// User
|
|
313
|
+
// ========================================================
|
|
314
|
+
|
|
315
|
+
export class User extends Schema.Class<User>("User")({
|
|
316
|
+
createdAt: Schema.Date,
|
|
317
|
+
email: Schema.String,
|
|
318
|
+
emailVerified: Schema.Boolean,
|
|
319
|
+
id: Schema.String,
|
|
320
|
+
image: Schema.NullOr(Schema.String),
|
|
321
|
+
name: Schema.String,
|
|
322
|
+
organizations: Schema.Array(
|
|
323
|
+
Schema.Struct({
|
|
324
|
+
id: Schema.String,
|
|
325
|
+
logo: Schema.NullOr(Schema.String),
|
|
326
|
+
name: Schema.String,
|
|
327
|
+
slug: Schema.String,
|
|
328
|
+
})
|
|
329
|
+
),
|
|
330
|
+
projects: Schema.Array(
|
|
331
|
+
Schema.Struct({
|
|
332
|
+
id: Schema.String,
|
|
333
|
+
logo: Schema.NullOr(Schema.String),
|
|
334
|
+
name: Schema.String,
|
|
335
|
+
organizationId: Schema.String,
|
|
336
|
+
slug: Schema.String,
|
|
337
|
+
})
|
|
338
|
+
),
|
|
339
|
+
updatedAt: Schema.Date,
|
|
340
|
+
}) {}
|
|
341
|
+
|
|
342
|
+
// ========================================================
|
|
343
|
+
// Webhooks
|
|
344
|
+
// ========================================================
|
|
345
|
+
|
|
346
|
+
export const WebhookEventType = Schema.Literal(
|
|
347
|
+
"customer.created",
|
|
348
|
+
"customer.updated",
|
|
349
|
+
"customer.deleted",
|
|
350
|
+
"subscription.created",
|
|
351
|
+
"subscription.renewed",
|
|
352
|
+
"subscription.cancelled",
|
|
353
|
+
"subscription.expired",
|
|
354
|
+
"purchase.completed",
|
|
355
|
+
"purchase.refunded"
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
export const WebhookEndpointStatus = Schema.Literal("active", "disabled", "failed");
|
|
359
|
+
|
|
360
|
+
export const WebhookDeliveryStatus = Schema.Literal(
|
|
361
|
+
"pending",
|
|
362
|
+
"in_progress",
|
|
363
|
+
"succeeded",
|
|
364
|
+
"failed",
|
|
365
|
+
"exhausted"
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
export class WebhookEndpoint extends Schema.Class<WebhookEndpoint>(
|
|
369
|
+
"WebhookEndpoint"
|
|
370
|
+
)({
|
|
371
|
+
consecutiveFailures: Schema.Number,
|
|
372
|
+
createdAt: Schema.NullOr(Schema.Date),
|
|
373
|
+
description: Schema.NullOr(Schema.String),
|
|
374
|
+
events: Schema.Array(WebhookEventType),
|
|
375
|
+
id: Schema.String,
|
|
376
|
+
lastSuccessAt: Schema.NullOr(Schema.Date),
|
|
377
|
+
name: Schema.String,
|
|
378
|
+
projectId: Schema.String,
|
|
379
|
+
secret: Schema.String,
|
|
380
|
+
status: WebhookEndpointStatus,
|
|
381
|
+
url: Schema.String,
|
|
382
|
+
}) {}
|
|
383
|
+
|
|
384
|
+
export class CreateWebhookEndpointBody extends Schema.Class<CreateWebhookEndpointBody>(
|
|
385
|
+
"CreateWebhookEndpointBody"
|
|
386
|
+
)({
|
|
387
|
+
description: Schema.optional(Schema.String),
|
|
388
|
+
events: Schema.Array(Schema.String),
|
|
389
|
+
name: Schema.String,
|
|
390
|
+
url: Schema.String,
|
|
391
|
+
}) {}
|
|
392
|
+
|
|
393
|
+
export class UpdateWebhookEndpointBody extends Schema.Class<UpdateWebhookEndpointBody>(
|
|
394
|
+
"UpdateWebhookEndpointBody"
|
|
395
|
+
)({
|
|
396
|
+
description: Schema.optional(Schema.NullOr(Schema.String)),
|
|
397
|
+
events: Schema.optional(Schema.Array(Schema.String)),
|
|
398
|
+
name: Schema.optional(Schema.String),
|
|
399
|
+
status: Schema.optional(Schema.Literal("active", "disabled")),
|
|
400
|
+
url: Schema.optional(Schema.String),
|
|
401
|
+
}) {}
|
|
402
|
+
|
|
403
|
+
export const WebhookEndpointIdParam = HttpApiSchema.param(
|
|
404
|
+
"endpointId",
|
|
405
|
+
Schema.String
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
export class WebhookDelivery extends Schema.Class<WebhookDelivery>(
|
|
409
|
+
"WebhookDelivery"
|
|
410
|
+
)({
|
|
411
|
+
attemptCount: Schema.Number,
|
|
412
|
+
completedAt: Schema.NullOr(Schema.Date),
|
|
413
|
+
createdAt: Schema.NullOr(Schema.Date),
|
|
414
|
+
eventOccurredAt: Schema.Date,
|
|
415
|
+
eventType: Schema.String,
|
|
416
|
+
id: Schema.String,
|
|
417
|
+
maxAttempts: Schema.Number,
|
|
418
|
+
nextAttemptAt: Schema.NullOr(Schema.Date),
|
|
419
|
+
payload: Schema.Unknown,
|
|
420
|
+
projectId: Schema.String,
|
|
421
|
+
status: WebhookDeliveryStatus,
|
|
422
|
+
webhookEndpointId: Schema.String,
|
|
423
|
+
}) {}
|
|
424
|
+
|
|
425
|
+
export class WebhookDeliveryAttempt extends Schema.Class<WebhookDeliveryAttempt>(
|
|
426
|
+
"WebhookDeliveryAttempt"
|
|
427
|
+
)({
|
|
428
|
+
attemptNumber: Schema.Number,
|
|
429
|
+
createdAt: Schema.NullOr(Schema.Date),
|
|
430
|
+
durationMs: Schema.NullOr(Schema.Number),
|
|
431
|
+
errorMessage: Schema.NullOr(Schema.String),
|
|
432
|
+
id: Schema.String,
|
|
433
|
+
responseBody: Schema.NullOr(Schema.String),
|
|
434
|
+
statusCode: Schema.NullOr(Schema.Number),
|
|
435
|
+
succeeded: Schema.Boolean,
|
|
436
|
+
}) {}
|
|
437
|
+
|
|
438
|
+
export class WebhookDeliveryWithAttempts extends Schema.Class<WebhookDeliveryWithAttempts>(
|
|
439
|
+
"WebhookDeliveryWithAttempts"
|
|
440
|
+
)({
|
|
441
|
+
attemptCount: Schema.Number,
|
|
442
|
+
attempts: Schema.Array(WebhookDeliveryAttempt),
|
|
443
|
+
completedAt: Schema.NullOr(Schema.Date),
|
|
444
|
+
createdAt: Schema.NullOr(Schema.Date),
|
|
445
|
+
eventOccurredAt: Schema.Date,
|
|
446
|
+
eventType: Schema.String,
|
|
447
|
+
id: Schema.String,
|
|
448
|
+
maxAttempts: Schema.Number,
|
|
449
|
+
nextAttemptAt: Schema.NullOr(Schema.Date),
|
|
450
|
+
payload: Schema.Unknown,
|
|
451
|
+
projectId: Schema.String,
|
|
452
|
+
status: WebhookDeliveryStatus,
|
|
453
|
+
webhookEndpointId: Schema.String,
|
|
454
|
+
}) {}
|
|
455
|
+
|
|
456
|
+
export const WebhookDeliveryIdParam = HttpApiSchema.param(
|
|
457
|
+
"deliveryId",
|
|
458
|
+
Schema.String
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
// ========================================================
|
|
462
|
+
// Feature Flags (SDK)
|
|
463
|
+
// ========================================================
|
|
464
|
+
|
|
465
|
+
export class EvaluateFeatureFlagsBody extends Schema.Class<EvaluateFeatureFlagsBody>(
|
|
466
|
+
"EvaluateFeatureFlagsBody"
|
|
467
|
+
)({
|
|
468
|
+
flagKeys: Schema.optional(Schema.Array(Schema.String)),
|
|
469
|
+
}) {}
|
|
470
|
+
|
|
471
|
+
export class SdkFeatureFlagResult extends Schema.Class<SdkFeatureFlagResult>(
|
|
472
|
+
"SdkFeatureFlagResult"
|
|
473
|
+
)({
|
|
474
|
+
enabled: Schema.Boolean,
|
|
475
|
+
key: Schema.String,
|
|
476
|
+
payload: Schema.NullOr(Schema.Unknown),
|
|
477
|
+
variantKey: Schema.NullOr(Schema.String),
|
|
478
|
+
}) {}
|
|
479
|
+
|
|
480
|
+
export class SdkFeatureFlagsResponse extends Schema.Class<SdkFeatureFlagsResponse>(
|
|
481
|
+
"SdkFeatureFlagsResponse"
|
|
482
|
+
)({
|
|
483
|
+
flags: Schema.Array(SdkFeatureFlagResult),
|
|
484
|
+
}) {}
|
|
485
|
+
|
|
486
|
+
// ========================================================
|
|
487
|
+
// Paywall Resolution (SDK)
|
|
488
|
+
// ========================================================
|
|
489
|
+
|
|
490
|
+
export class SdkResolvePaywallBody extends Schema.Class<SdkResolvePaywallBody>(
|
|
491
|
+
"SdkResolvePaywallBody"
|
|
492
|
+
)({
|
|
493
|
+
locationSlug: Schema.String,
|
|
494
|
+
}) {}
|
|
495
|
+
|
|
496
|
+
const SdkResolvedPaywallShowingType = Schema.Literal(
|
|
497
|
+
"paywall_release",
|
|
498
|
+
"feature_flag"
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
const SdkResolvedPaywallShowingPaywall = Schema.Struct({
|
|
502
|
+
id: Schema.String,
|
|
503
|
+
name: Schema.String,
|
|
504
|
+
slug: Schema.String,
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
const SdkResolvedPaywallShowingPaywallRelease = Schema.Struct({
|
|
508
|
+
htmlUrl: Schema.String,
|
|
509
|
+
publishedAt: Schema.NullOr(Schema.Date),
|
|
510
|
+
releaseId: Schema.String,
|
|
511
|
+
version: Schema.Number,
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
export class SdkResolvedPaywallShowing extends Schema.Class<SdkResolvedPaywallShowing>(
|
|
515
|
+
"SdkResolvedPaywallShowing"
|
|
516
|
+
)({
|
|
517
|
+
id: Schema.String,
|
|
518
|
+
paywall: Schema.NullOr(SdkResolvedPaywallShowingPaywall),
|
|
519
|
+
paywallId: Schema.NullOr(Schema.String),
|
|
520
|
+
paywallRelease: Schema.NullOr(SdkResolvedPaywallShowingPaywallRelease),
|
|
521
|
+
paywallReleaseId: Schema.NullOr(Schema.String),
|
|
522
|
+
startedAt: Schema.Date,
|
|
523
|
+
type: SdkResolvedPaywallShowingType,
|
|
524
|
+
}) {}
|
|
525
|
+
|
|
526
|
+
export class SdkResolvedPaywall extends Schema.Class<SdkResolvedPaywall>(
|
|
527
|
+
"SdkResolvedPaywall"
|
|
528
|
+
)({
|
|
529
|
+
location: Schema.Struct({
|
|
530
|
+
id: Schema.String,
|
|
531
|
+
name: Schema.String,
|
|
532
|
+
slug: Schema.String,
|
|
533
|
+
}),
|
|
534
|
+
showing: SdkResolvedPaywallShowing,
|
|
535
|
+
}) {}
|