@aurabase/aurabase-js 0.3.1 → 0.4.1
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 +26 -795
- package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.ts → dist/AuraClient-BcFE8u1v.d.cts} +1 -1
- package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.cts → dist/AuraClient-BcFE8u1v.d.ts} +1 -1
- package/{packages/aurabase/dist → dist}/index.d.cts +1 -1
- package/{packages/aurabase/dist → dist}/index.d.ts +1 -1
- package/{packages/aurabase/dist → dist}/ssr.d.cts +1 -1
- package/{packages/aurabase/dist → dist}/ssr.d.ts +1 -1
- package/package.json +74 -82
- package/.changeset/config.json +0 -11
- package/CHANGELOG.md +0 -30
- package/packages/ai/LICENSE +0 -21
- package/packages/ai/README.md +0 -106
- package/packages/ai/dist/index.cjs +0 -229
- package/packages/ai/dist/index.d.cts +0 -139
- package/packages/ai/dist/index.d.ts +0 -139
- package/packages/ai/dist/index.js +0 -226
- package/packages/ai/package.json +0 -61
- package/packages/aurabase/LICENSE +0 -21
- package/packages/aurabase/README.md +0 -64
- package/packages/aurabase/package.json +0 -80
- package/packages/aurabase/vitest.e2e.config.ts +0 -9
- package/packages/auth/LICENSE +0 -21
- package/packages/auth/README.md +0 -215
- package/packages/auth/dist/index.cjs +0 -1175
- package/packages/auth/dist/index.d.cts +0 -397
- package/packages/auth/dist/index.d.ts +0 -397
- package/packages/auth/dist/index.js +0 -1170
- package/packages/auth/package.json +0 -61
- package/packages/core/LICENSE +0 -21
- package/packages/core/README.md +0 -132
- package/packages/core/dist/index.cjs +0 -695
- package/packages/core/dist/index.d.cts +0 -1137
- package/packages/core/dist/index.d.ts +0 -1137
- package/packages/core/dist/index.js +0 -673
- package/packages/core/package.json +0 -57
- package/packages/db/LICENSE +0 -21
- package/packages/db/README.md +0 -152
- package/packages/db/VENDORED.md +0 -93
- package/packages/db/dist/index.cjs +0 -544
- package/packages/db/dist/index.d.cts +0 -1111
- package/packages/db/dist/index.d.ts +0 -1111
- package/packages/db/dist/index.js +0 -541
- package/packages/db/package.json +0 -62
- package/packages/functions/LICENSE +0 -21
- package/packages/functions/README.md +0 -96
- package/packages/functions/dist/index.cjs +0 -173
- package/packages/functions/dist/index.d.cts +0 -81
- package/packages/functions/dist/index.d.ts +0 -81
- package/packages/functions/dist/index.js +0 -168
- package/packages/functions/package.json +0 -60
- package/packages/gen/LICENSE +0 -21
- package/packages/gen/README.md +0 -84
- package/packages/gen/dist/cli.cjs +0 -334
- package/packages/gen/dist/cli.d.cts +0 -1
- package/packages/gen/dist/cli.d.ts +0 -1
- package/packages/gen/dist/cli.js +0 -332
- package/packages/gen/dist/index.cjs +0 -257
- package/packages/gen/dist/index.d.cts +0 -12
- package/packages/gen/dist/index.d.ts +0 -12
- package/packages/gen/dist/index.js +0 -255
- package/packages/gen/package.json +0 -66
- package/packages/notifications/LICENSE +0 -21
- package/packages/notifications/README.md +0 -134
- package/packages/notifications/dist/index.cjs +0 -128
- package/packages/notifications/dist/index.d.cts +0 -81
- package/packages/notifications/dist/index.d.ts +0 -81
- package/packages/notifications/dist/index.js +0 -125
- package/packages/notifications/package.json +0 -60
- package/packages/realtime/LICENSE +0 -21
- package/packages/realtime/README.md +0 -183
- package/packages/realtime/dist/index.cjs +0 -977
- package/packages/realtime/dist/index.d.cts +0 -259
- package/packages/realtime/dist/index.d.ts +0 -259
- package/packages/realtime/dist/index.js +0 -973
- package/packages/realtime/package.json +0 -60
- package/packages/storage/LICENSE +0 -21
- package/packages/storage/README.md +0 -141
- package/packages/storage/dist/index.cjs +0 -333
- package/packages/storage/dist/index.d.cts +0 -185
- package/packages/storage/dist/index.d.ts +0 -185
- package/packages/storage/dist/index.js +0 -329
- package/packages/storage/package.json +0 -60
- /package/{packages/aurabase/dist → dist}/index.cjs +0 -0
- /package/{packages/aurabase/dist → dist}/index.js +0 -0
- /package/{packages/aurabase/dist → dist}/ssr.cjs +0 -0
- /package/{packages/aurabase/dist → dist}/ssr.js +0 -0
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
// src/generate.ts
|
|
2
|
-
function enumRef(name, ctx) {
|
|
3
|
-
return ctx.enumNames.has(name) ? `${ctx.typeName}['${ctx.schemaName}']['Enums']['${name}']` : (
|
|
4
|
-
// Enum inconnu du bloc Enums → auto-référence non résoluble → repli textuel.
|
|
5
|
-
"string"
|
|
6
|
-
);
|
|
7
|
-
}
|
|
8
|
-
function mapColType(colType, ctx) {
|
|
9
|
-
if (typeof colType === "string") {
|
|
10
|
-
switch (colType) {
|
|
11
|
-
case "text":
|
|
12
|
-
case "varchar":
|
|
13
|
-
case "bpchar":
|
|
14
|
-
case "uuid":
|
|
15
|
-
case "timestamp":
|
|
16
|
-
case "timestamptz":
|
|
17
|
-
case "date":
|
|
18
|
-
case "time":
|
|
19
|
-
case "bytea":
|
|
20
|
-
case "numeric":
|
|
21
|
-
return "string";
|
|
22
|
-
case "int":
|
|
23
|
-
case "int2":
|
|
24
|
-
case "int4":
|
|
25
|
-
case "int8":
|
|
26
|
-
case "bigint":
|
|
27
|
-
case "float":
|
|
28
|
-
case "float4":
|
|
29
|
-
case "float8":
|
|
30
|
-
return "number";
|
|
31
|
-
case "bool":
|
|
32
|
-
return "boolean";
|
|
33
|
-
case "json":
|
|
34
|
-
case "jsonb":
|
|
35
|
-
return "Json";
|
|
36
|
-
default:
|
|
37
|
-
return "unknown";
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (colType && typeof colType === "object") {
|
|
41
|
-
if ("array" in colType) return `${mapColType(colType.array, ctx)}[]`;
|
|
42
|
-
if ("vector" in colType) return "number[]";
|
|
43
|
-
if ("enum" in colType) return enumRef(String(colType.enum), ctx);
|
|
44
|
-
}
|
|
45
|
-
return "unknown";
|
|
46
|
-
}
|
|
47
|
-
function mapPgType(raw, ctx) {
|
|
48
|
-
if (raw.startsWith("_")) return `${mapPgType(raw.slice(1), ctx)}[]`;
|
|
49
|
-
switch (raw) {
|
|
50
|
-
case "int2":
|
|
51
|
-
case "int4":
|
|
52
|
-
case "int8":
|
|
53
|
-
case "float4":
|
|
54
|
-
case "float8":
|
|
55
|
-
return "number";
|
|
56
|
-
case "numeric":
|
|
57
|
-
return "string";
|
|
58
|
-
case "bool":
|
|
59
|
-
return "boolean";
|
|
60
|
-
case "text":
|
|
61
|
-
case "varchar":
|
|
62
|
-
case "bpchar":
|
|
63
|
-
case "citext":
|
|
64
|
-
case "uuid":
|
|
65
|
-
case "date":
|
|
66
|
-
case "time":
|
|
67
|
-
case "timetz":
|
|
68
|
-
case "timestamp":
|
|
69
|
-
case "timestamptz":
|
|
70
|
-
case "bytea":
|
|
71
|
-
return "string";
|
|
72
|
-
case "json":
|
|
73
|
-
case "jsonb":
|
|
74
|
-
return "Json";
|
|
75
|
-
case "void":
|
|
76
|
-
return "undefined";
|
|
77
|
-
case "record":
|
|
78
|
-
return "unknown";
|
|
79
|
-
default:
|
|
80
|
-
return ctx.enumNames.has(raw) ? enumRef(raw, ctx) : "unknown";
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function tsType(col, ctx) {
|
|
84
|
-
const base = mapColType(col.col_type, ctx);
|
|
85
|
-
return col.nullable ? `${base} | null` : base;
|
|
86
|
-
}
|
|
87
|
-
function genRow(cols, ctx) {
|
|
88
|
-
return cols.map((c) => ` ${c.name}: ${tsType(c, ctx)}`).join("\n");
|
|
89
|
-
}
|
|
90
|
-
var AUTO_COLS = /* @__PURE__ */ new Set(["id", "created_at", "updated_at"]);
|
|
91
|
-
function isInsertOptional(col) {
|
|
92
|
-
return col.nullable || col.default_val != null || AUTO_COLS.has(col.name);
|
|
93
|
-
}
|
|
94
|
-
function genInsert(cols, ctx) {
|
|
95
|
-
return cols.map((c) => ` ${c.name}${isInsertOptional(c) ? "?" : ""}: ${tsType(c, ctx)}`).join("\n");
|
|
96
|
-
}
|
|
97
|
-
function genUpdate(cols, ctx) {
|
|
98
|
-
return cols.map((c) => ` ${c.name}?: ${tsType(c, ctx)}`).join("\n");
|
|
99
|
-
}
|
|
100
|
-
function genRelationships(t) {
|
|
101
|
-
const fks = t.columns.filter((c) => c.references);
|
|
102
|
-
if (fks.length === 0) return "[]";
|
|
103
|
-
const groups = /* @__PURE__ */ new Map();
|
|
104
|
-
for (const c of fks) {
|
|
105
|
-
const ref = c.references;
|
|
106
|
-
const name = ref.constraint_name ?? `${t.name}_${c.name}_fkey`;
|
|
107
|
-
const key = ref.constraint_name ?? `\0synthetic\0${c.name}`;
|
|
108
|
-
let g = groups.get(key);
|
|
109
|
-
if (!g) {
|
|
110
|
-
g = { name, columns: [], refTable: ref.table, refColumns: [], cols: [] };
|
|
111
|
-
groups.set(key, g);
|
|
112
|
-
}
|
|
113
|
-
g.columns.push(c.name);
|
|
114
|
-
g.refColumns.push(ref.column);
|
|
115
|
-
g.cols.push(c);
|
|
116
|
-
}
|
|
117
|
-
const entries = [...groups.values()].map((g) => {
|
|
118
|
-
const isOneToOne = g.cols.every((c) => c.unique || t.primary_key === c.name);
|
|
119
|
-
const cols = g.columns.map((c) => `'${c}'`).join(", ");
|
|
120
|
-
const refCols = g.refColumns.map((c) => `'${c}'`).join(", ");
|
|
121
|
-
return ` {
|
|
122
|
-
foreignKeyName: '${g.name}'
|
|
123
|
-
columns: [${cols}]
|
|
124
|
-
isOneToOne: ${isOneToOne}
|
|
125
|
-
referencedRelation: '${g.refTable}'
|
|
126
|
-
referencedColumns: [${refCols}]
|
|
127
|
-
}`;
|
|
128
|
-
});
|
|
129
|
-
return `[
|
|
130
|
-
${entries.join(",\n")}
|
|
131
|
-
]`;
|
|
132
|
-
}
|
|
133
|
-
function genFunctionArgs(fn, ctx) {
|
|
134
|
-
const inputArgs = fn.args.filter((a) => a.mode.toUpperCase() !== "OUT");
|
|
135
|
-
if (inputArgs.length === 0) return "Record<string, never>";
|
|
136
|
-
const entries = inputArgs.map((a) => `${a.name}: ${mapPgType(a.data_type, ctx)}`).join("; ");
|
|
137
|
-
return `{ ${entries} }`;
|
|
138
|
-
}
|
|
139
|
-
function mapReturnType(fn, ctx) {
|
|
140
|
-
const base = mapPgType(fn.returns, ctx);
|
|
141
|
-
if (!fn.is_set_returning) return base;
|
|
142
|
-
return base === "unknown" ? "Record<string, unknown>[]" : `${base}[]`;
|
|
143
|
-
}
|
|
144
|
-
function genSetofOptions(fn, ctx) {
|
|
145
|
-
if (!fn.is_set_returning) return null;
|
|
146
|
-
const to = ctx.relationNames.has(fn.returns) ? fn.returns : fn.name;
|
|
147
|
-
return `{ isSetofReturn: true; isOneToOne: false; to: '${to}'; from: '*' }`;
|
|
148
|
-
}
|
|
149
|
-
function genFunctionsBody(functions, ctx) {
|
|
150
|
-
if (functions.length === 0) return "Record<string, never>";
|
|
151
|
-
const groups = /* @__PURE__ */ new Map();
|
|
152
|
-
for (const fn of functions) {
|
|
153
|
-
const g = groups.get(fn.name);
|
|
154
|
-
if (g) g.push(fn);
|
|
155
|
-
else groups.set(fn.name, [fn]);
|
|
156
|
-
}
|
|
157
|
-
const entries = [...groups.values()].map((overloads) => {
|
|
158
|
-
const argsUnion = uniq(overloads.map((fn) => genFunctionArgs(fn, ctx))).join(" | ");
|
|
159
|
-
const returnsUnion = uniq(overloads.map((fn) => mapReturnType(fn, ctx))).join(" | ");
|
|
160
|
-
const lines = [
|
|
161
|
-
` ${overloads[0].name}: {`,
|
|
162
|
-
` Args: ${argsUnion}`,
|
|
163
|
-
` Returns: ${returnsUnion}`
|
|
164
|
-
];
|
|
165
|
-
if (overloads.length === 1) {
|
|
166
|
-
const setofOptions = genSetofOptions(overloads[0], ctx);
|
|
167
|
-
if (setofOptions) lines.push(` SetofOptions: ${setofOptions}`);
|
|
168
|
-
}
|
|
169
|
-
lines.push(" }");
|
|
170
|
-
return lines.join("\n");
|
|
171
|
-
});
|
|
172
|
-
return `{
|
|
173
|
-
${entries.join("\n")}
|
|
174
|
-
}`;
|
|
175
|
-
}
|
|
176
|
-
function uniq(items) {
|
|
177
|
-
return [...new Set(items)];
|
|
178
|
-
}
|
|
179
|
-
function genEnumsBody(enums) {
|
|
180
|
-
if (enums.length === 0) return "Record<string, never>";
|
|
181
|
-
const entries = enums.map((e) => {
|
|
182
|
-
const union = e.values.length === 0 ? "never" : e.values.map((v) => `'${v}'`).join(" | ");
|
|
183
|
-
return ` ${e.name}: ${union}`;
|
|
184
|
-
});
|
|
185
|
-
return `{
|
|
186
|
-
${entries.join("\n")}
|
|
187
|
-
}`;
|
|
188
|
-
}
|
|
189
|
-
function genViewsBody(views, ctx) {
|
|
190
|
-
if (views.length === 0) return "Record<string, never>";
|
|
191
|
-
const entries = views.map(
|
|
192
|
-
(v) => ` ${v.name}: {
|
|
193
|
-
Row: {
|
|
194
|
-
${genRow(v.columns, ctx)}
|
|
195
|
-
}
|
|
196
|
-
Relationships: []
|
|
197
|
-
}`
|
|
198
|
-
);
|
|
199
|
-
return `{
|
|
200
|
-
${entries.join("\n")}
|
|
201
|
-
}`;
|
|
202
|
-
}
|
|
203
|
-
var HEADER = `// ============================================================
|
|
204
|
-
// Types TypeScript auto-g\xE9n\xE9r\xE9s par Aurabase (@aurabase/gen)
|
|
205
|
-
// NE PAS MODIFIER \u2014 r\xE9g\xE9n\xE9rer avec \`npx @aurabase/gen\`
|
|
206
|
-
// ============================================================
|
|
207
|
-
`;
|
|
208
|
-
function generateDatabaseTypes(tables, options = {}) {
|
|
209
|
-
const schemaName = options.schemaName ?? "public";
|
|
210
|
-
const typeName = options.typeName ?? "Database";
|
|
211
|
-
const enums = options.enums ?? [];
|
|
212
|
-
const views = options.views ?? [];
|
|
213
|
-
const relationNames = new Set([...tables, ...views].map((r) => r.name));
|
|
214
|
-
const ctx = { typeName, schemaName, enumNames: new Set(enums.map((e) => e.name)), relationNames };
|
|
215
|
-
const functionsBody = genFunctionsBody(options.functions ?? [], ctx);
|
|
216
|
-
const enumsBody = genEnumsBody(enums);
|
|
217
|
-
const viewsBody = genViewsBody(views, ctx);
|
|
218
|
-
const tablesBody = tables.length === 0 ? "Record<string, never>" : `{
|
|
219
|
-
${tables.map(
|
|
220
|
-
(t) => ` ${t.name}: {
|
|
221
|
-
Row: {
|
|
222
|
-
${genRow(t.columns, ctx)}
|
|
223
|
-
}
|
|
224
|
-
Insert: {
|
|
225
|
-
${genInsert(t.columns, ctx)}
|
|
226
|
-
}
|
|
227
|
-
Update: {
|
|
228
|
-
${genUpdate(t.columns, ctx)}
|
|
229
|
-
}
|
|
230
|
-
Relationships: ${genRelationships(t)}
|
|
231
|
-
}`
|
|
232
|
-
).join("\n")}
|
|
233
|
-
}`;
|
|
234
|
-
return `${HEADER}
|
|
235
|
-
export type Json =
|
|
236
|
-
| string
|
|
237
|
-
| number
|
|
238
|
-
| boolean
|
|
239
|
-
| null
|
|
240
|
-
| { [key: string]: Json | undefined }
|
|
241
|
-
| Json[]
|
|
242
|
-
|
|
243
|
-
export interface ${typeName} {
|
|
244
|
-
${schemaName}: {
|
|
245
|
-
Tables: ${tablesBody}
|
|
246
|
-
Views: ${viewsBody}
|
|
247
|
-
Functions: ${functionsBody}
|
|
248
|
-
Enums: ${enumsBody}
|
|
249
|
-
CompositeTypes: Record<string, never>
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
`;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export { generateDatabaseTypes };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@aurabase/gen",
|
|
3
|
-
"version": "0.3.0",
|
|
4
|
-
"description": "Générateur de types TypeScript Database pour le SDK Aurabase (CLI aurabase-gen)",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.cjs",
|
|
7
|
-
"module": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"bin": {
|
|
10
|
-
"aurabase-gen": "./dist/cli.js"
|
|
11
|
-
},
|
|
12
|
-
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"import": {
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"default": "./dist/index.js"
|
|
17
|
-
},
|
|
18
|
-
"require": {
|
|
19
|
-
"types": "./dist/index.d.cts",
|
|
20
|
-
"default": "./dist/index.cjs"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"sideEffects": false,
|
|
25
|
-
"files": [
|
|
26
|
-
"dist",
|
|
27
|
-
"README.md",
|
|
28
|
-
"LICENSE"
|
|
29
|
-
],
|
|
30
|
-
"engines": {
|
|
31
|
-
"node": ">=20.0.0"
|
|
32
|
-
},
|
|
33
|
-
"license": "MIT",
|
|
34
|
-
"author": "Aurabase",
|
|
35
|
-
"repository": {
|
|
36
|
-
"type": "git",
|
|
37
|
-
"url": "git+https://github.com/daylami555/aurabase.git",
|
|
38
|
-
"directory": "aurabase-js/packages/gen"
|
|
39
|
-
},
|
|
40
|
-
"homepage": "https://github.com/daylami555/aurabase/tree/main/aurabase-js/packages/gen#readme",
|
|
41
|
-
"bugs": {
|
|
42
|
-
"url": "https://github.com/daylami555/aurabase/issues"
|
|
43
|
-
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"aurabase",
|
|
46
|
-
"baas",
|
|
47
|
-
"sdk",
|
|
48
|
-
"generator",
|
|
49
|
-
"types"
|
|
50
|
-
],
|
|
51
|
-
"scripts": {
|
|
52
|
-
"build": "tsup",
|
|
53
|
-
"test": "vitest run --passWithNoTests",
|
|
54
|
-
"typecheck": "tsc --noEmit"
|
|
55
|
-
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"@aurabase/core": "workspace:*",
|
|
58
|
-
"aurabase": "workspace:*"
|
|
59
|
-
},
|
|
60
|
-
"devDependencies": {
|
|
61
|
-
"tsup": "catalog:",
|
|
62
|
-
"typescript": "catalog:",
|
|
63
|
-
"vitest": "catalog:",
|
|
64
|
-
"@types/node": "catalog:"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Aurabase
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
# @aurabase/notifications
|
|
2
|
-
|
|
3
|
-
Service de notifications multi-canal du SDK Aurabase : email, SMS, push et webhook derrière une API unique, avec templates, règles déclenchées par événement et administration complète (`aura.notifications.admin`).
|
|
4
|
-
|
|
5
|
-
 
|
|
6
|
-
|
|
7
|
-
> Pre-release — pas encore publié sur npm.
|
|
8
|
-
|
|
9
|
-
Fait partie du SDK **[aurabase](../aurabase)**. Installé automatiquement avec `aurabase` ; ce package est publié séparément pour un usage ciblé / tree-shaking.
|
|
10
|
-
|
|
11
|
-
Le multi-canal unifié (un seul `send()` pour email/SMS/push/webhook, avec dead-letter, retries et règles) est un **différenciateur** face à des solutions push-only (FCM) ou tiers payantes (OneSignal).
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm i @aurabase/notifications
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
> Ce package dépend de `@aurabase/core` (`workspace:*` en interne, résolu en semver côté npm). Si vous utilisez déjà le package `aurabase`, `@aurabase/notifications` est déjà inclus — cette installation ciblée n'est utile que pour composer votre propre client ou limiter la taille du bundle.
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
Dans l'usage courant, `NotificationsService` n'est jamais instancié directement : il est exposé par le client principal sous `aura.notifications` (et son admin sous `aura.notifications.admin`).
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import { createClient } from 'aurabase'
|
|
27
|
-
|
|
28
|
-
const aura = createClient('http://localhost:8080', 'my-project', 'aura_anon_xxx')
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Envoi
|
|
32
|
-
|
|
33
|
-
Canaux disponibles : `'email' | 'sms' | 'push' | 'webhook'`.
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
const { data, error } = await aura.notifications.send(
|
|
37
|
-
'email',
|
|
38
|
-
'user@example.com',
|
|
39
|
-
'Votre commande a été expédiée.',
|
|
40
|
-
{ subject: 'Expédition', variables: { order_id: '1234' }, idempotencyKey: 'order-1234-shipped' },
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
if (error) throw error
|
|
44
|
-
console.log(data!.status)
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Envoi en lot
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
const { data: batch } = await aura.notifications.sendBatch([
|
|
51
|
-
{ channel: 'email', recipient: 'a@example.com', body: 'Bonjour A' },
|
|
52
|
-
{ channel: 'sms', recipient: '+15551234567', body: 'Bonjour B' },
|
|
53
|
-
])
|
|
54
|
-
|
|
55
|
-
for (const item of batch!.items) {
|
|
56
|
-
console.log(item.status, item.notification?.id)
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Historique et templates
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
const { data: sent } = await aura.notifications.list({
|
|
64
|
-
channel: 'email',
|
|
65
|
-
status: 'delivered',
|
|
66
|
-
sort: 'created_at',
|
|
67
|
-
order: 'desc',
|
|
68
|
-
limit: 20,
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const notificationId = sent![0]!.id
|
|
72
|
-
const { data: notif } = await aura.notifications.get(notificationId)
|
|
73
|
-
|
|
74
|
-
const { data: template } = await aura.notifications.createTemplate({
|
|
75
|
-
name: 'order-shipped',
|
|
76
|
-
channel: 'email',
|
|
77
|
-
subject: 'Expédition {{order_id}}',
|
|
78
|
-
body: 'Votre commande {{order_id}} est en route.',
|
|
79
|
-
variables: ['order_id'],
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
await aura.notifications.updateTemplate(template!.id, { body: 'Mise à jour : {{order_id}} expédiée.' })
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Administration (`aura.notifications.admin`)
|
|
86
|
-
|
|
87
|
-
```ts
|
|
88
|
-
const { data: settings } = await aura.notifications.admin.getSettings()
|
|
89
|
-
await aura.notifications.admin.updateSettings({ quotas: { daily_email: 10000 } })
|
|
90
|
-
|
|
91
|
-
const { data: stats } = await aura.notifications.admin.getStats({ window: '24h', channel: 'email' })
|
|
92
|
-
const { data: queue } = await aura.notifications.admin.getQueue()
|
|
93
|
-
|
|
94
|
-
const failedId = 'notification-id'
|
|
95
|
-
const { data: attempts } = await aura.notifications.admin.listAttempts(failedId)
|
|
96
|
-
|
|
97
|
-
const { data: deadLetters } = await aura.notifications.admin.listDeadLetters({ channel: 'email', limit: 50 })
|
|
98
|
-
await aura.notifications.admin.retryDeadLetter(deadLetters![0]!.id)
|
|
99
|
-
|
|
100
|
-
const { data: events } = await aura.notifications.admin.listEvents({ status: 'failed' })
|
|
101
|
-
const { data: logs } = await aura.notifications.admin.listProviderLogs({ channel: 'sms' })
|
|
102
|
-
|
|
103
|
-
const templateId = 'template-id'
|
|
104
|
-
const { data: preview } = await aura.notifications.admin.previewTemplate(templateId, { order_id: '1234' })
|
|
105
|
-
console.log(preview!.subject, preview!.body)
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### Règles déclenchées par événement
|
|
109
|
-
|
|
110
|
-
```ts
|
|
111
|
-
const { data: rule } = await aura.notifications.admin.createRule({
|
|
112
|
-
name: 'welcome-email',
|
|
113
|
-
trigger_type: 'user.created',
|
|
114
|
-
channel: 'email',
|
|
115
|
-
recipient_expr: 'user.email',
|
|
116
|
-
template_id: 'welcome-template-id',
|
|
117
|
-
delay_seconds: 0,
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
const { data: rules } = await aura.notifications.admin.listRules()
|
|
121
|
-
await aura.notifications.admin.updateRule(rule!.id, { enabled: false })
|
|
122
|
-
await aura.notifications.admin.deleteRule(rule!.id)
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
## Limitations
|
|
126
|
-
|
|
127
|
-
- Pas de gestion d'audience/segments/devices : `recipient` est une chaîne brute (email, numéro, endpoint webhook, device token) — pas d'abstraction "device" ou "utilisateur" côté SDK.
|
|
128
|
-
- Pas de scheduling explicite d'un envoi (« envoyer à telle date ») en dehors du `delay_seconds` des règles déclenchées.
|
|
129
|
-
- Payloads génériques : `body` est une chaîne libre associée à des `variables` (interpolation côté backend), pas un objet structuré par canal (pas de builder push spécifique avec badge/son/icône, par exemple).
|
|
130
|
-
- Pas d'API de désabonnement/préférences par canal exposée par le SDK.
|
|
131
|
-
|
|
132
|
-
## Documentation
|
|
133
|
-
|
|
134
|
-
Référence complète du SDK (tous les services, types partagés, SSR) : [README racine](../../README.md).
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@aurabase/core');
|
|
4
|
-
|
|
5
|
-
// src/NotificationsService.ts
|
|
6
|
-
var NotificationsService = class extends core.BaseService {
|
|
7
|
-
admin;
|
|
8
|
-
constructor(client) {
|
|
9
|
-
super(client);
|
|
10
|
-
this.admin = new NotificationsAdminService(client);
|
|
11
|
-
}
|
|
12
|
-
get prefix() {
|
|
13
|
-
return `/v1/notifications/${this.client.projectId}`;
|
|
14
|
-
}
|
|
15
|
-
// -- Send -------------------------------------------------------------------
|
|
16
|
-
async send(channel, recipient, body, options) {
|
|
17
|
-
return this.request("POST", `${this.prefix}/send`, {
|
|
18
|
-
channel,
|
|
19
|
-
recipient,
|
|
20
|
-
body,
|
|
21
|
-
subject: options?.subject,
|
|
22
|
-
template_id: options?.templateId,
|
|
23
|
-
variables: options?.variables,
|
|
24
|
-
metadata: options?.metadata,
|
|
25
|
-
idempotency_key: options?.idempotencyKey
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async sendBatch(items) {
|
|
29
|
-
return this.request("POST", `${this.prefix}/send/batch`, { items });
|
|
30
|
-
}
|
|
31
|
-
// -- Notification history ---------------------------------------------------
|
|
32
|
-
async list(options) {
|
|
33
|
-
const params = new URLSearchParams();
|
|
34
|
-
if (options?.channel !== void 0) params.set("channel", options.channel);
|
|
35
|
-
if (options?.status !== void 0) params.set("status", options.status);
|
|
36
|
-
if (options?.search !== void 0) params.set("search", options.search);
|
|
37
|
-
if (options?.sort !== void 0) params.set("sort", options.sort);
|
|
38
|
-
if (options?.order !== void 0) params.set("order", options.order);
|
|
39
|
-
if (options?.limit !== void 0) params.set("limit", String(options.limit));
|
|
40
|
-
if (options?.offset !== void 0) params.set("offset", String(options.offset));
|
|
41
|
-
const qs = params.toString();
|
|
42
|
-
const sep = qs ? "?" : "";
|
|
43
|
-
return this.request("GET", `${this.prefix}${sep}${qs}`);
|
|
44
|
-
}
|
|
45
|
-
async get(id) {
|
|
46
|
-
return this.request("GET", `${this.prefix}/${id}`);
|
|
47
|
-
}
|
|
48
|
-
// -- Templates --------------------------------------------------------------
|
|
49
|
-
async listTemplates() {
|
|
50
|
-
return this.request("GET", `${this.prefix}/templates`);
|
|
51
|
-
}
|
|
52
|
-
async getTemplate(id) {
|
|
53
|
-
return this.request("GET", `${this.prefix}/templates/${id}`);
|
|
54
|
-
}
|
|
55
|
-
async createTemplate(template) {
|
|
56
|
-
return this.request("POST", `${this.prefix}/templates`, template);
|
|
57
|
-
}
|
|
58
|
-
async updateTemplate(id, updates) {
|
|
59
|
-
return this.request("PATCH", `${this.prefix}/templates/${id}`, updates);
|
|
60
|
-
}
|
|
61
|
-
async deleteTemplate(id) {
|
|
62
|
-
return this.request("DELETE", `${this.prefix}/templates/${id}`);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var NotificationsAdminService = class extends core.BaseService {
|
|
66
|
-
constructor(client) {
|
|
67
|
-
super(client);
|
|
68
|
-
}
|
|
69
|
-
get prefix() {
|
|
70
|
-
return `/v1/notifications/${this.client.projectId}`;
|
|
71
|
-
}
|
|
72
|
-
query(options) {
|
|
73
|
-
const params = new URLSearchParams();
|
|
74
|
-
for (const [key, value] of Object.entries(options ?? {})) {
|
|
75
|
-
if (value !== void 0 && value !== null && value !== "") params.set(key, String(value));
|
|
76
|
-
}
|
|
77
|
-
const qs = params.toString();
|
|
78
|
-
return qs ? `?${qs}` : "";
|
|
79
|
-
}
|
|
80
|
-
async getSettings() {
|
|
81
|
-
return this.request("GET", `${this.prefix}/settings`);
|
|
82
|
-
}
|
|
83
|
-
async updateSettings(settings) {
|
|
84
|
-
return this.request("PATCH", `${this.prefix}/settings`, settings);
|
|
85
|
-
}
|
|
86
|
-
async getStats(options) {
|
|
87
|
-
return this.request("GET", `${this.prefix}/stats${this.query(options)}`);
|
|
88
|
-
}
|
|
89
|
-
async getQueue() {
|
|
90
|
-
return this.request("GET", `${this.prefix}/queue`);
|
|
91
|
-
}
|
|
92
|
-
async listAttempts(notificationId) {
|
|
93
|
-
return this.request("GET", `${this.prefix}/${notificationId}/attempts`);
|
|
94
|
-
}
|
|
95
|
-
async listDeadLetters(options) {
|
|
96
|
-
return this.request("GET", `${this.prefix}/dead-letters${this.query(options)}`);
|
|
97
|
-
}
|
|
98
|
-
async retryDeadLetter(id) {
|
|
99
|
-
return this.request("POST", `${this.prefix}/dead-letters/${id}/retry`);
|
|
100
|
-
}
|
|
101
|
-
async listEvents(options) {
|
|
102
|
-
return this.request("GET", `${this.prefix}/events${this.query(options)}`);
|
|
103
|
-
}
|
|
104
|
-
async listProviderLogs(options) {
|
|
105
|
-
return this.request("GET", `${this.prefix}/providers/logs${this.query(options)}`);
|
|
106
|
-
}
|
|
107
|
-
async previewTemplate(id, variables) {
|
|
108
|
-
return this.request("POST", `${this.prefix}/templates/${id}/preview`, variables);
|
|
109
|
-
}
|
|
110
|
-
async listRules() {
|
|
111
|
-
return this.request("GET", `${this.prefix}/rules`);
|
|
112
|
-
}
|
|
113
|
-
async createRule(rule) {
|
|
114
|
-
return this.request("POST", `${this.prefix}/rules`, rule);
|
|
115
|
-
}
|
|
116
|
-
async getRule(id) {
|
|
117
|
-
return this.request("GET", `${this.prefix}/rules/${id}`);
|
|
118
|
-
}
|
|
119
|
-
async updateRule(id, updates) {
|
|
120
|
-
return this.request("PATCH", `${this.prefix}/rules/${id}`, updates);
|
|
121
|
-
}
|
|
122
|
-
async deleteRule(id) {
|
|
123
|
-
return this.request("DELETE", `${this.prefix}/rules/${id}`);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
exports.NotificationsAdminService = NotificationsAdminService;
|
|
128
|
-
exports.NotificationsService = NotificationsService;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { BaseService, AuraClientLike, AuraResponse, NotificationSettings, NotificationStats, NotificationQueueStats, NotificationAttempt, NotificationDeadLetter, Notification, NotificationEvent, NotificationProviderLog, NotificationTemplatePreview, NotificationRule, SendNotificationRequest, BatchSendResponse, NotificationTemplate } from '@aurabase/core';
|
|
2
|
-
export { AuraResponse, BatchSendResponse, Notification, NotificationAttempt, NotificationDeadLetter, NotificationEvent, NotificationProviderLog, NotificationQueueStats, NotificationRule, NotificationSettings, NotificationStats, NotificationTemplate, NotificationTemplatePreview, SendNotificationRequest } from '@aurabase/core';
|
|
3
|
-
|
|
4
|
-
type NotificationChannel = 'email' | 'sms' | 'push' | 'webhook';
|
|
5
|
-
type NotificationStatus = 'queued' | 'processing' | 'sent' | 'failed' | 'delivered' | 'expired' | 'dead_lettered';
|
|
6
|
-
type CreateNotificationRuleRequest = {
|
|
7
|
-
name: string;
|
|
8
|
-
trigger_type: string;
|
|
9
|
-
condition?: Record<string, unknown>;
|
|
10
|
-
template_id?: string | null;
|
|
11
|
-
channel: NotificationChannel;
|
|
12
|
-
recipient_expr: string;
|
|
13
|
-
delay_seconds?: number;
|
|
14
|
-
};
|
|
15
|
-
declare class NotificationsService extends BaseService {
|
|
16
|
-
readonly admin: NotificationsAdminService;
|
|
17
|
-
constructor(client: AuraClientLike);
|
|
18
|
-
private get prefix();
|
|
19
|
-
send(channel: NotificationChannel, recipient: string, body: string, options?: {
|
|
20
|
-
subject?: string;
|
|
21
|
-
templateId?: string;
|
|
22
|
-
variables?: Record<string, unknown>;
|
|
23
|
-
metadata?: Record<string, unknown>;
|
|
24
|
-
idempotencyKey?: string;
|
|
25
|
-
}): Promise<AuraResponse<Notification>>;
|
|
26
|
-
sendBatch(items: SendNotificationRequest[]): Promise<AuraResponse<BatchSendResponse>>;
|
|
27
|
-
list(options?: {
|
|
28
|
-
channel?: NotificationChannel;
|
|
29
|
-
status?: NotificationStatus;
|
|
30
|
-
search?: string;
|
|
31
|
-
sort?: 'created_at' | 'updated_at' | 'status';
|
|
32
|
-
order?: 'asc' | 'desc';
|
|
33
|
-
limit?: number;
|
|
34
|
-
offset?: number;
|
|
35
|
-
}): Promise<AuraResponse<Notification[]>>;
|
|
36
|
-
get(id: string): Promise<AuraResponse<Notification>>;
|
|
37
|
-
listTemplates(): Promise<AuraResponse<NotificationTemplate[]>>;
|
|
38
|
-
getTemplate(id: string): Promise<AuraResponse<NotificationTemplate>>;
|
|
39
|
-
createTemplate(template: Omit<NotificationTemplate, 'id' | 'created_at' | 'updated_at'>): Promise<AuraResponse<NotificationTemplate>>;
|
|
40
|
-
updateTemplate(id: string, updates: Partial<Omit<NotificationTemplate, 'id' | 'created_at' | 'updated_at'>>): Promise<AuraResponse<NotificationTemplate>>;
|
|
41
|
-
deleteTemplate(id: string): Promise<AuraResponse<null>>;
|
|
42
|
-
}
|
|
43
|
-
declare class NotificationsAdminService extends BaseService {
|
|
44
|
-
constructor(client: AuraClientLike);
|
|
45
|
-
private get prefix();
|
|
46
|
-
private query;
|
|
47
|
-
getSettings(): Promise<AuraResponse<NotificationSettings>>;
|
|
48
|
-
updateSettings(settings: Partial<NotificationSettings>): Promise<AuraResponse<NotificationSettings>>;
|
|
49
|
-
getStats(options?: {
|
|
50
|
-
window?: string;
|
|
51
|
-
channel?: NotificationChannel;
|
|
52
|
-
}): Promise<AuraResponse<NotificationStats>>;
|
|
53
|
-
getQueue(): Promise<AuraResponse<NotificationQueueStats>>;
|
|
54
|
-
listAttempts(notificationId: string): Promise<AuraResponse<NotificationAttempt[]>>;
|
|
55
|
-
listDeadLetters(options?: {
|
|
56
|
-
channel?: NotificationChannel;
|
|
57
|
-
search?: string;
|
|
58
|
-
limit?: number;
|
|
59
|
-
offset?: number;
|
|
60
|
-
}): Promise<AuraResponse<NotificationDeadLetter[]>>;
|
|
61
|
-
retryDeadLetter(id: string): Promise<AuraResponse<Notification>>;
|
|
62
|
-
listEvents(options?: {
|
|
63
|
-
status?: 'received' | 'matched' | 'ignored' | 'failed' | 'enqueued';
|
|
64
|
-
limit?: number;
|
|
65
|
-
offset?: number;
|
|
66
|
-
}): Promise<AuraResponse<NotificationEvent[]>>;
|
|
67
|
-
listProviderLogs(options?: {
|
|
68
|
-
channel?: NotificationChannel;
|
|
69
|
-
status?: string;
|
|
70
|
-
limit?: number;
|
|
71
|
-
offset?: number;
|
|
72
|
-
}): Promise<AuraResponse<NotificationProviderLog[]>>;
|
|
73
|
-
previewTemplate(id: string, variables: Record<string, unknown>): Promise<AuraResponse<NotificationTemplatePreview>>;
|
|
74
|
-
listRules(): Promise<AuraResponse<NotificationRule[]>>;
|
|
75
|
-
createRule(rule: CreateNotificationRuleRequest): Promise<AuraResponse<NotificationRule>>;
|
|
76
|
-
getRule(id: string): Promise<AuraResponse<NotificationRule>>;
|
|
77
|
-
updateRule(id: string, updates: Partial<Omit<NotificationRule, 'id' | 'project_id' | 'created_at' | 'updated_at'>>): Promise<AuraResponse<NotificationRule>>;
|
|
78
|
-
deleteRule(id: string): Promise<AuraResponse<null>>;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export { NotificationsAdminService, NotificationsService };
|