@fayz-ai/sdk 0.1.2 → 0.1.4
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/README.md +20 -1
- package/dist/chunk-3VVLBMKG.cjs +442 -0
- package/dist/chunk-3VVLBMKG.cjs.map +1 -0
- package/dist/chunk-7FF2FLPG.js +45 -0
- package/dist/chunk-7FF2FLPG.js.map +1 -0
- package/dist/chunk-JBQDG2GN.js +439 -0
- package/dist/chunk-JBQDG2GN.js.map +1 -0
- package/dist/chunk-JXXIKYP3.cjs +50 -0
- package/dist/chunk-JXXIKYP3.cjs.map +1 -0
- package/dist/{chunk-REGBJXXB.cjs → chunk-MCB2L25R.cjs} +60 -2
- package/dist/chunk-MCB2L25R.cjs.map +1 -0
- package/dist/{chunk-O6XSRB3Q.js → chunk-R4XVCBFG.js} +60 -2
- package/dist/chunk-R4XVCBFG.js.map +1 -0
- package/dist/client.cjs +4 -4
- package/dist/client.d.ts +54 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.cjs +30 -4
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/release-channels.cjs +24 -0
- package/dist/release-channels.cjs.map +1 -0
- package/dist/release-channels.d.ts +10 -0
- package/dist/release-channels.d.ts.map +1 -0
- package/dist/release-channels.js +3 -0
- package/dist/release-channels.js.map +1 -0
- package/dist/shop.cjs +16 -0
- package/dist/shop.cjs.map +1 -0
- package/dist/shop.d.ts +391 -0
- package/dist/shop.d.ts.map +1 -0
- package/dist/shop.js +3 -0
- package/dist/shop.js.map +1 -0
- package/package.json +15 -2
- package/src/client.test.ts +135 -0
- package/src/client.ts +126 -0
- package/src/index.ts +36 -1
- package/src/release-channels.json +13 -0
- package/src/release-channels.test.ts +42 -0
- package/src/release-channels.ts +41 -0
- package/src/runtime.test.ts +4 -4
- package/src/shop.test.ts +83 -0
- package/src/shop.ts +660 -0
- package/dist/chunk-O6XSRB3Q.js.map +0 -1
- package/dist/chunk-REGBJXXB.cjs.map +0 -1
package/src/client.ts
CHANGED
|
@@ -14,6 +14,65 @@ export interface FayzRequestOptions extends Omit<RequestInit, 'headers'> {
|
|
|
14
14
|
token?: string
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export type FayzTableFilterOperator =
|
|
18
|
+
| 'eq'
|
|
19
|
+
| 'neq'
|
|
20
|
+
| 'gt'
|
|
21
|
+
| 'lt'
|
|
22
|
+
| 'gte'
|
|
23
|
+
| 'lte'
|
|
24
|
+
| 'like'
|
|
25
|
+
| 'ilike'
|
|
26
|
+
| 'is_null'
|
|
27
|
+
| 'is_not_null'
|
|
28
|
+
|
|
29
|
+
export interface FayzTableFilter {
|
|
30
|
+
column: string
|
|
31
|
+
operator: FayzTableFilterOperator
|
|
32
|
+
value?: unknown
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface FayzTableListOptions {
|
|
36
|
+
projectId?: string
|
|
37
|
+
table: string
|
|
38
|
+
schema?: string
|
|
39
|
+
filters?: FayzTableFilter[]
|
|
40
|
+
sortColumn?: string
|
|
41
|
+
sortDirection?: 'asc' | 'desc'
|
|
42
|
+
page?: number
|
|
43
|
+
limit?: number
|
|
44
|
+
runtime?: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface FayzTableListResponse<T> {
|
|
48
|
+
rows: T[]
|
|
49
|
+
total: number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface FayzTableMutationOptions {
|
|
53
|
+
projectId?: string
|
|
54
|
+
table: string
|
|
55
|
+
schema?: string
|
|
56
|
+
runtime?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface FayzTableCreateOptions<T = Record<string, unknown>> extends FayzTableMutationOptions {
|
|
60
|
+
row: T
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface FayzTableUpdateOptions<T = Record<string, unknown>> extends FayzTableMutationOptions {
|
|
64
|
+
primaryKeys: Record<string, unknown>
|
|
65
|
+
row: Partial<T>
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface FayzTableDeleteOptions extends FayzTableMutationOptions {
|
|
69
|
+
rows: Record<string, unknown>[]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface FayzTableDeleteResponse {
|
|
73
|
+
deletedCount: number
|
|
74
|
+
}
|
|
75
|
+
|
|
17
76
|
export class FayzApiError extends Error {
|
|
18
77
|
constructor(
|
|
19
78
|
message: string,
|
|
@@ -66,6 +125,39 @@ function unwrapUser(body: FayzUser | FayzAuthMeResponse): FayzUser {
|
|
|
66
125
|
: body as FayzUser
|
|
67
126
|
}
|
|
68
127
|
|
|
128
|
+
function tableRowsPath(options: FayzTableListOptions): string {
|
|
129
|
+
const route = tableRowsRoute(options)
|
|
130
|
+
const params = new URLSearchParams()
|
|
131
|
+
|
|
132
|
+
if (options.schema) params.set('schema', options.schema)
|
|
133
|
+
if (options.filters?.length) params.set('filters', JSON.stringify(options.filters))
|
|
134
|
+
if (options.sortColumn) params.set('sortColumn', options.sortColumn)
|
|
135
|
+
if (options.sortDirection) params.set('sortDirection', options.sortDirection)
|
|
136
|
+
if (options.page != null) params.set('page', String(options.page))
|
|
137
|
+
if (options.limit != null) params.set('limit', String(options.limit))
|
|
138
|
+
|
|
139
|
+
const query = params.toString()
|
|
140
|
+
return query ? `${route}?${query}` : route
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function tableRowsRoute(options: FayzTableMutationOptions): string {
|
|
144
|
+
const projectId = encodeURIComponent(options.projectId ?? appParams.projectId ?? 'current')
|
|
145
|
+
const table = encodeURIComponent(options.table)
|
|
146
|
+
return options.runtime
|
|
147
|
+
? `/api/v1/runtime/projects/${projectId}/database/tables/${table}/rows`
|
|
148
|
+
: `/api/projects/${projectId}/database/tables/${table}/rows`
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function mutationRowsPath(options: FayzTableMutationOptions): string {
|
|
152
|
+
const route = tableRowsRoute(options)
|
|
153
|
+
const params = new URLSearchParams()
|
|
154
|
+
|
|
155
|
+
if (options.schema) params.set('schema', options.schema)
|
|
156
|
+
|
|
157
|
+
const query = params.toString()
|
|
158
|
+
return query ? `${route}?${query}` : route
|
|
159
|
+
}
|
|
160
|
+
|
|
69
161
|
export function createFayzClient(options: FayzClientOptions = {}) {
|
|
70
162
|
const baseUrl = normalizeBaseUrl(options.baseUrl ?? appParams.apiBaseUrl)
|
|
71
163
|
const fetcher = options.fetcher ?? fetch
|
|
@@ -94,6 +186,40 @@ export function createFayzClient(options: FayzClientOptions = {}) {
|
|
|
94
186
|
return unwrapUser(await request<FayzUser | FayzAuthMeResponse>('/auth/me'))
|
|
95
187
|
},
|
|
96
188
|
},
|
|
189
|
+
data: {
|
|
190
|
+
async listRows<T = Record<string, unknown>>(options: FayzTableListOptions): Promise<FayzTableListResponse<T>> {
|
|
191
|
+
return request<FayzTableListResponse<T>>(tableRowsPath(options))
|
|
192
|
+
},
|
|
193
|
+
async countRows(options: FayzTableListOptions): Promise<number> {
|
|
194
|
+
const response = await request<FayzTableListResponse<unknown>>(tableRowsPath({
|
|
195
|
+
...options,
|
|
196
|
+
page: options.page ?? 1,
|
|
197
|
+
limit: 1,
|
|
198
|
+
}))
|
|
199
|
+
return response.total
|
|
200
|
+
},
|
|
201
|
+
async createRow<T = Record<string, unknown>>(options: FayzTableCreateOptions<Partial<T>>): Promise<T> {
|
|
202
|
+
return request<T>(mutationRowsPath(options), {
|
|
203
|
+
method: 'POST',
|
|
204
|
+
body: JSON.stringify(options.row),
|
|
205
|
+
})
|
|
206
|
+
},
|
|
207
|
+
async updateRow<T = Record<string, unknown>>(options: FayzTableUpdateOptions<T>): Promise<T> {
|
|
208
|
+
return request<T>(mutationRowsPath(options), {
|
|
209
|
+
method: 'PATCH',
|
|
210
|
+
body: JSON.stringify({
|
|
211
|
+
primaryKeys: options.primaryKeys,
|
|
212
|
+
data: options.row,
|
|
213
|
+
}),
|
|
214
|
+
})
|
|
215
|
+
},
|
|
216
|
+
async deleteRows(options: FayzTableDeleteOptions): Promise<FayzTableDeleteResponse> {
|
|
217
|
+
return request<FayzTableDeleteResponse>(mutationRowsPath(options), {
|
|
218
|
+
method: 'DELETE',
|
|
219
|
+
body: JSON.stringify({ rows: options.rows }),
|
|
220
|
+
})
|
|
221
|
+
},
|
|
222
|
+
},
|
|
97
223
|
runtime: {
|
|
98
224
|
createClient: createFayzRuntimeClient,
|
|
99
225
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,45 @@
|
|
|
1
1
|
export { appParams, resolveAppParams } from './app-params'
|
|
2
2
|
export { createFayzClient, fayz, FayzApiError } from './client'
|
|
3
|
-
export type {
|
|
3
|
+
export type {
|
|
4
|
+
FayzClientOptions,
|
|
5
|
+
FayzRequestOptions,
|
|
6
|
+
FayzTableFilter,
|
|
7
|
+
FayzTableFilterOperator,
|
|
8
|
+
FayzTableListOptions,
|
|
9
|
+
FayzTableListResponse,
|
|
10
|
+
FayzTableMutationOptions,
|
|
11
|
+
FayzTableCreateOptions,
|
|
12
|
+
FayzTableUpdateOptions,
|
|
13
|
+
FayzTableDeleteOptions,
|
|
14
|
+
FayzTableDeleteResponse,
|
|
15
|
+
} from './client'
|
|
16
|
+
export {
|
|
17
|
+
fayzPackageVersionSets,
|
|
18
|
+
resolveFayzPackageDependencies,
|
|
19
|
+
resolveFayzPackageVersion,
|
|
20
|
+
resolveFayzPackageVersions,
|
|
21
|
+
} from './release-channels'
|
|
22
|
+
export type { FayzPackageChannel, FayzPackageVersionSet } from './release-channels'
|
|
4
23
|
export {
|
|
5
24
|
createFayzRuntimeClient,
|
|
6
25
|
FayzRuntimeError,
|
|
7
26
|
} from './runtime'
|
|
27
|
+
export {
|
|
28
|
+
createFayzShopProvider,
|
|
29
|
+
FayzShopError,
|
|
30
|
+
} from './shop'
|
|
31
|
+
export type {
|
|
32
|
+
FayzShopProviderOptions,
|
|
33
|
+
FayzShopProductMetadataOverlay,
|
|
34
|
+
FayzShopListProductsOptions,
|
|
35
|
+
FayzShopListOrdersOptions,
|
|
36
|
+
FayzShopListCustomersOptions,
|
|
37
|
+
FayzShopListDiscountsOptions,
|
|
38
|
+
FayzShopProductStatus,
|
|
39
|
+
FayzShopOrderStatus,
|
|
40
|
+
FayzShopFinancialStatus,
|
|
41
|
+
FayzShopFulfillmentStatus,
|
|
42
|
+
} from './shop'
|
|
8
43
|
export type {
|
|
9
44
|
FayzRuntimeClientOptions,
|
|
10
45
|
FayzRuntimeEnvironment,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import releaseChannels from './release-channels.json' with { type: 'json' }
|
|
3
|
+
import {
|
|
4
|
+
resolveFayzPackageDependencies,
|
|
5
|
+
fayzPackageVersionSets,
|
|
6
|
+
resolveFayzPackageVersion,
|
|
7
|
+
resolveFayzPackageVersions,
|
|
8
|
+
} from './release-channels'
|
|
9
|
+
|
|
10
|
+
describe('release channels', () => {
|
|
11
|
+
it('keeps stable as the default channel', () => {
|
|
12
|
+
expect(resolveFayzPackageVersions()).toEqual({
|
|
13
|
+
channel: 'stable',
|
|
14
|
+
packages: {
|
|
15
|
+
'@fayz-ai/sdk': '^0.1.4',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('returns a copy of package dependencies', () => {
|
|
21
|
+
const dependencies = resolveFayzPackageDependencies()
|
|
22
|
+
dependencies['@fayz-ai/sdk'] = 'tampered'
|
|
23
|
+
|
|
24
|
+
expect(resolveFayzPackageDependencies()['@fayz-ai/sdk']).toBe('^0.1.4')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('throws when a package is not mapped for a channel', () => {
|
|
28
|
+
expect(() => resolveFayzPackageVersion('@fayz-ai/app-runtime')).toThrow(
|
|
29
|
+
'No Fayz package version configured for @fayz-ai/app-runtime in stable channel',
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('keeps the machine-readable release-channel manifest aligned with the typed export', () => {
|
|
34
|
+
expect(releaseChannels).toEqual({
|
|
35
|
+
channels: {
|
|
36
|
+
stable: fayzPackageVersionSets.stable.packages,
|
|
37
|
+
latest: fayzPackageVersionSets.latest.packages,
|
|
38
|
+
preview: fayzPackageVersionSets.preview.packages,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import releaseChannels from './release-channels.json'
|
|
2
|
+
|
|
3
|
+
export type FayzPackageChannel = 'stable' | 'latest' | 'preview'
|
|
4
|
+
|
|
5
|
+
export interface FayzPackageVersionSet {
|
|
6
|
+
channel: FayzPackageChannel
|
|
7
|
+
packages: Record<string, string>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const releaseChannelPackages = releaseChannels.channels as Record<FayzPackageChannel, Record<string, string>>
|
|
11
|
+
|
|
12
|
+
function buildVersionSet(channel: FayzPackageChannel): FayzPackageVersionSet {
|
|
13
|
+
return {
|
|
14
|
+
channel,
|
|
15
|
+
packages: { ...releaseChannelPackages[channel] },
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const fayzPackageVersionSets: Record<FayzPackageChannel, FayzPackageVersionSet> = {
|
|
20
|
+
stable: buildVersionSet('stable'),
|
|
21
|
+
latest: buildVersionSet('latest'),
|
|
22
|
+
preview: buildVersionSet('preview'),
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function resolveFayzPackageVersions(channel: FayzPackageChannel = 'stable'): FayzPackageVersionSet {
|
|
26
|
+
return fayzPackageVersionSets[channel]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function resolveFayzPackageDependencies(channel: FayzPackageChannel = 'stable'): Record<string, string> {
|
|
30
|
+
return { ...resolveFayzPackageVersions(channel).packages }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function resolveFayzPackageVersion(packageName: string, channel: FayzPackageChannel = 'stable'): string {
|
|
34
|
+
const version = resolveFayzPackageVersions(channel).packages[packageName]
|
|
35
|
+
|
|
36
|
+
if (!version) {
|
|
37
|
+
throw new Error(`No Fayz package version configured for ${packageName} in ${channel} channel`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return version
|
|
41
|
+
}
|
package/src/runtime.test.ts
CHANGED
|
@@ -20,7 +20,7 @@ describe('createFayzRuntimeClient', () => {
|
|
|
20
20
|
projectId: 'project-1',
|
|
21
21
|
tenantKey: 'tenant-a',
|
|
22
22
|
environment: 'preview',
|
|
23
|
-
pluginId: '@fayz/plugin-agenda',
|
|
23
|
+
pluginId: '@fayz-ai/plugin-agenda',
|
|
24
24
|
grants: [{ grantId: 'grant-1', provider: 'google-calendar', scopes: ['calendar.read'] }],
|
|
25
25
|
}))
|
|
26
26
|
const client = createFayzRuntimeClient({
|
|
@@ -31,7 +31,7 @@ describe('createFayzRuntimeClient', () => {
|
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
const response = await client.exchangePluginOAuth({
|
|
34
|
-
pluginId: '@fayz/plugin-agenda',
|
|
34
|
+
pluginId: '@fayz-ai/plugin-agenda',
|
|
35
35
|
scopes: ['calendar.read'],
|
|
36
36
|
})
|
|
37
37
|
|
|
@@ -45,7 +45,7 @@ describe('createFayzRuntimeClient', () => {
|
|
|
45
45
|
'Content-Type': 'application/json',
|
|
46
46
|
}),
|
|
47
47
|
body: JSON.stringify({
|
|
48
|
-
pluginId: '@fayz/plugin-agenda',
|
|
48
|
+
pluginId: '@fayz-ai/plugin-agenda',
|
|
49
49
|
environment: 'preview',
|
|
50
50
|
scopes: ['calendar.read'],
|
|
51
51
|
}),
|
|
@@ -113,7 +113,7 @@ describe('createFayzRuntimeClient', () => {
|
|
|
113
113
|
fetcher,
|
|
114
114
|
})
|
|
115
115
|
|
|
116
|
-
await expect(client.exchangePluginOAuth({ pluginId: '@fayz/plugin-agenda' }))
|
|
116
|
+
await expect(client.exchangePluginOAuth({ pluginId: '@fayz-ai/plugin-agenda' }))
|
|
117
117
|
.rejects.toMatchObject({
|
|
118
118
|
name: 'FayzRuntimeError',
|
|
119
119
|
status: 502,
|
package/src/shop.test.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { createFayzShopProvider } from './shop'
|
|
4
|
+
|
|
5
|
+
function jsonResponse(body: unknown, status = 200): Response {
|
|
6
|
+
return new Response(JSON.stringify(body), {
|
|
7
|
+
status,
|
|
8
|
+
headers: { 'Content-Type': 'application/json' },
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function productRow(overrides: Record<string, unknown> = {}) {
|
|
13
|
+
return {
|
|
14
|
+
id: 'prod-1',
|
|
15
|
+
tenant_id: 'store-1',
|
|
16
|
+
name: 'Runner Vortex Neon',
|
|
17
|
+
slug: 'runner-vortex-neon',
|
|
18
|
+
sku: 'SNK-001',
|
|
19
|
+
price: 499.9,
|
|
20
|
+
metadata: {},
|
|
21
|
+
images: [],
|
|
22
|
+
...overrides,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('createFayzShopProvider', () => {
|
|
27
|
+
it('merges app-owned product metadata overlays into listed products', async () => {
|
|
28
|
+
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(jsonResponse([
|
|
29
|
+
productRow({
|
|
30
|
+
metadata: {
|
|
31
|
+
colorway: 'Backend wins',
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
]))
|
|
35
|
+
|
|
36
|
+
const provider = createFayzShopProvider({
|
|
37
|
+
supabaseUrl: 'https://example.supabase.co',
|
|
38
|
+
publishableKey: 'publishable-key',
|
|
39
|
+
storeId: 'store-1',
|
|
40
|
+
productMetadata: [
|
|
41
|
+
{
|
|
42
|
+
sku: 'SNK-001',
|
|
43
|
+
slug: 'runner-vortex-neon',
|
|
44
|
+
metadata: {
|
|
45
|
+
colorway: 'Overlay loses',
|
|
46
|
+
sizes: ['38', '39', '40'],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
fetcher,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const [product] = await provider.listProducts({ status: 'active' })
|
|
54
|
+
|
|
55
|
+
expect(product?.metadata.sizes).toEqual(['38', '39', '40'])
|
|
56
|
+
expect(product?.metadata.colorway).toBe('Backend wins')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('uses slug overlays when fetching a single product', async () => {
|
|
60
|
+
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(jsonResponse([
|
|
61
|
+
productRow({ sku: null }),
|
|
62
|
+
]))
|
|
63
|
+
|
|
64
|
+
const provider = createFayzShopProvider({
|
|
65
|
+
supabaseUrl: 'https://example.supabase.co',
|
|
66
|
+
publishableKey: 'publishable-key',
|
|
67
|
+
storeId: 'store-1',
|
|
68
|
+
productMetadata: [
|
|
69
|
+
{
|
|
70
|
+
slug: 'runner-vortex-neon',
|
|
71
|
+
metadata: {
|
|
72
|
+
sizes: ['40', '41'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
fetcher,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const product = await provider.getProduct('prod-1')
|
|
80
|
+
|
|
81
|
+
expect(product?.metadata.sizes).toEqual(['40', '41'])
|
|
82
|
+
})
|
|
83
|
+
})
|