@oblax/templates 1.0.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.
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/templates-module.d.ts +34 -0
- package/dist/templates-module.d.ts.map +1 -0
- package/dist/templates-module.js +56 -0
- package/dist/templates-module.js.map +1 -0
- package/dist/types.d.ts +35 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { OblaxModulePlugin } from '@oblax/core';
|
|
2
|
+
import { TemplatesModule } from './templates-module.js';
|
|
3
|
+
import type { TemplatesConfig } from './types.js';
|
|
4
|
+
export { TemplatesModule } from './templates-module.js';
|
|
5
|
+
export type { TemplatesConfig, Template, CreateTemplateParams, UpdateTemplateParams, TemplateKeyParams, TemplateFormat, } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Templates module factory.
|
|
8
|
+
*
|
|
9
|
+
* Registers the templates module with the Oblax SDK.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { Oblax } from '@oblax/core'
|
|
14
|
+
* import { PlatformServer } from '@oblax/platform-server'
|
|
15
|
+
* import { Templates } from '@oblax/templates'
|
|
16
|
+
*
|
|
17
|
+
* const oblax = new Oblax({
|
|
18
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
19
|
+
* clientId: 'my-app',
|
|
20
|
+
* modules: [PlatformServer(), Templates()],
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* const tpl = await oblax.templates.create({
|
|
24
|
+
* displayName: 'Welcome',
|
|
25
|
+
* format: 'html',
|
|
26
|
+
* content: '<p>Hello {{name}}</p>',
|
|
27
|
+
* fields: ['name'],
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function Templates(config?: TemplatesConfig): OblaxModulePlugin<'templates', TemplatesModule>;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,YAAY,EACV,eAAe,EACf,QAAQ,EACR,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,GACf,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,SAAS,CAAC,MAAM,GAAE,eAAoB,GAAG,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,CAOvG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TemplatesModule } from './templates-module.js';
|
|
2
|
+
export { TemplatesModule } from './templates-module.js';
|
|
3
|
+
/**
|
|
4
|
+
* Templates module factory.
|
|
5
|
+
*
|
|
6
|
+
* Registers the templates module with the Oblax SDK.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { Oblax } from '@oblax/core'
|
|
11
|
+
* import { PlatformServer } from '@oblax/platform-server'
|
|
12
|
+
* import { Templates } from '@oblax/templates'
|
|
13
|
+
*
|
|
14
|
+
* const oblax = new Oblax({
|
|
15
|
+
* endpoint: 'https://api.my-app.oblax.io',
|
|
16
|
+
* clientId: 'my-app',
|
|
17
|
+
* modules: [PlatformServer(), Templates()],
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* const tpl = await oblax.templates.create({
|
|
21
|
+
* displayName: 'Welcome',
|
|
22
|
+
* format: 'html',
|
|
23
|
+
* content: '<p>Hello {{name}}</p>',
|
|
24
|
+
* fields: ['name'],
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function Templates(config = {}) {
|
|
29
|
+
return {
|
|
30
|
+
name: 'templates',
|
|
31
|
+
create(ctx) {
|
|
32
|
+
return new TemplatesModule(ctx, config);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAGvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAWvD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,SAAS,CAAC,SAA0B,EAAE;IACpD,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,MAAM,CAAC,GAAiB;YACtB,OAAO,IAAI,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACzC,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { OblaxContext } from '@oblax/core';
|
|
2
|
+
import type { CreateTemplateParams, Template, TemplateKeyParams, TemplatesConfig, UpdateTemplateParams } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The Templates module.
|
|
5
|
+
*
|
|
6
|
+
* Manages templates in the render service.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const tpl = await oblax.templates.create({
|
|
11
|
+
* displayName: 'Welcome Email',
|
|
12
|
+
* format: 'html',
|
|
13
|
+
* content: '<h1>Hello {{name}}</h1>',
|
|
14
|
+
* fields: ['name'],
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* const all = await oblax.templates.list()
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class TemplatesModule {
|
|
21
|
+
private readonly ctx;
|
|
22
|
+
constructor(ctx: OblaxContext, _config: TemplatesConfig);
|
|
23
|
+
/** Creates a new template. */
|
|
24
|
+
create(params: CreateTemplateParams): Promise<Template>;
|
|
25
|
+
/** Returns all templates. */
|
|
26
|
+
list(): Promise<Template[]>;
|
|
27
|
+
/** Fetches a single template by key. */
|
|
28
|
+
get(params: TemplateKeyParams): Promise<Template>;
|
|
29
|
+
/** Updates a template. */
|
|
30
|
+
update(params: UpdateTemplateParams): Promise<Template>;
|
|
31
|
+
/** Deletes a template by key. */
|
|
32
|
+
delete(params: TemplateKeyParams): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=templates-module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates-module.d.ts","sourceRoot":"","sources":["../src/templates-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EACV,oBAAoB,EACpB,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAgBnB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe;IAExE,8BAA8B;IACxB,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI7D,6BAA6B;IACvB,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIjC,wCAAwC;IAClC,GAAG,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIvD,0BAA0B;IACpB,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI7D,iCAAiC;IAC3B,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAGvD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Maps camelCase input to the snake_case wire format. */
|
|
2
|
+
function templateToApi(params) {
|
|
3
|
+
const out = {
|
|
4
|
+
display_name: params.displayName,
|
|
5
|
+
format: params.format,
|
|
6
|
+
content: params.content,
|
|
7
|
+
fields: params.fields,
|
|
8
|
+
};
|
|
9
|
+
if ('parentId' in params) {
|
|
10
|
+
out.parent_id = params.parentId;
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The Templates module.
|
|
16
|
+
*
|
|
17
|
+
* Manages templates in the render service.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const tpl = await oblax.templates.create({
|
|
22
|
+
* displayName: 'Welcome Email',
|
|
23
|
+
* format: 'html',
|
|
24
|
+
* content: '<h1>Hello {{name}}</h1>',
|
|
25
|
+
* fields: ['name'],
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* const all = await oblax.templates.list()
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export class TemplatesModule {
|
|
32
|
+
constructor(ctx, _config) {
|
|
33
|
+
this.ctx = ctx;
|
|
34
|
+
}
|
|
35
|
+
/** Creates a new template. */
|
|
36
|
+
async create(params) {
|
|
37
|
+
return this.ctx.http.post('/templates', templateToApi(params));
|
|
38
|
+
}
|
|
39
|
+
/** Returns all templates. */
|
|
40
|
+
async list() {
|
|
41
|
+
return this.ctx.http.get('/templates');
|
|
42
|
+
}
|
|
43
|
+
/** Fetches a single template by key. */
|
|
44
|
+
async get(params) {
|
|
45
|
+
return this.ctx.http.get(`/templates/${params.key}`);
|
|
46
|
+
}
|
|
47
|
+
/** Updates a template. */
|
|
48
|
+
async update(params) {
|
|
49
|
+
return this.ctx.http.put(`/templates/${params.key}`, templateToApi(params));
|
|
50
|
+
}
|
|
51
|
+
/** Deletes a template by key. */
|
|
52
|
+
async delete(params) {
|
|
53
|
+
return this.ctx.http.delete(`/templates/${params.key}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=templates-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates-module.js","sourceRoot":"","sources":["../src/templates-module.ts"],"names":[],"mappings":"AASA,0DAA0D;AAC1D,SAAS,aAAa,CAAC,MAAmD;IACxE,MAAM,GAAG,GAA4B;QACnC,YAAY,EAAE,MAAM,CAAC,WAAW;QAChC,MAAM,EAAQ,MAAM,CAAC,MAAM;QAC3B,OAAO,EAAO,MAAM,CAAC,OAAO;QAC5B,MAAM,EAAQ,MAAM,CAAC,MAAM;KAC5B,CAAA;IACD,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;QACzB,GAAG,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAA;IACjC,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,eAAe;IAC1B,YAA6B,GAAiB,EAAE,OAAwB;QAA3C,QAAG,GAAH,GAAG,CAAc;IAA6B,CAAC;IAE5E,8BAA8B;IAC9B,KAAK,CAAC,MAAM,CAAC,MAA4B;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAW,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;IAC1E,CAAC;IAED,6BAA6B;IAC7B,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAa,YAAY,CAAC,CAAA;IACpD,CAAC;IAED,wCAAwC;IACxC,KAAK,CAAC,GAAG,CAAC,MAAyB;QACjC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAW,cAAc,MAAM,CAAC,GAAG,EAAE,CAAC,CAAA;IAChE,CAAC;IAED,0BAA0B;IAC1B,KAAK,CAAC,MAAM,CAAC,MAA4B;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAW,cAAc,MAAM,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;IACvF,CAAC;IAED,iCAAiC;IACjC,KAAK,CAAC,MAAM,CAAC,MAAyB;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAO,cAAc,MAAM,CAAC,GAAG,EAAE,CAAC,CAAA;IAC/D,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type TemplateFormat = 'html' | 'txt' | 'md' | string;
|
|
2
|
+
/**
|
|
3
|
+
* A template stored in the Oblax render service.
|
|
4
|
+
*/
|
|
5
|
+
export interface Template {
|
|
6
|
+
id: string;
|
|
7
|
+
key: string;
|
|
8
|
+
display_name: string;
|
|
9
|
+
format: string;
|
|
10
|
+
content: string;
|
|
11
|
+
fields: string[];
|
|
12
|
+
parent_id: string;
|
|
13
|
+
author_id: string;
|
|
14
|
+
versions?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface CreateTemplateParams {
|
|
17
|
+
displayName: string;
|
|
18
|
+
format: TemplateFormat;
|
|
19
|
+
content: string;
|
|
20
|
+
fields: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface UpdateTemplateParams {
|
|
23
|
+
key: string;
|
|
24
|
+
parentId: string;
|
|
25
|
+
displayName: string;
|
|
26
|
+
format: TemplateFormat;
|
|
27
|
+
content: string;
|
|
28
|
+
fields: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface TemplateKeyParams {
|
|
31
|
+
key: string;
|
|
32
|
+
}
|
|
33
|
+
export interface TemplatesConfig {
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,CAAA;AAE3D;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,cAAc,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,cAAc,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,eAAe;CAE/B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oblax/templates",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Oblax SDK — templates module (create, list, get, update, delete templates)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Oblax SDK for JavaScript Team",
|
|
8
|
+
"url": "https://docs.oblax.io/docs/getting-started/your-first-sdk-call"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/oblaxio/oblax-sdk-js#readme",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/oblaxio/oblax-sdk-js.git",
|
|
14
|
+
"directory": "packages/templates"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/oblaxio/oblax-sdk-js/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"oblax",
|
|
21
|
+
"sdk",
|
|
22
|
+
"templates"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@oblax/core": "1.0.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"typescript": "^5.5.0",
|
|
44
|
+
"@oblax/core": "1.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc --build tsconfig.json",
|
|
48
|
+
"typecheck": "tsc --build tsconfig.json --dry",
|
|
49
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
50
|
+
}
|
|
51
|
+
}
|