@oblax/templates 2.1.0 → 2.2.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 CHANGED
@@ -2,7 +2,7 @@ import type { OblaxModulePlugin } from '@oblax/core';
2
2
  import { TemplatesModule } from './templates-module.js';
3
3
  import type { TemplatesConfig } from './types.js';
4
4
  export { TemplatesModule } from './templates-module.js';
5
- export type { TemplatesConfig, Template, CreateTemplateParams, UpdateTemplateParams, TemplateKeyParams, TemplateFormat, } from './types.js';
5
+ export type { TemplatesConfig, Template, CreateTemplateParams, UpdateTemplateParams, TemplateKeyParams, TemplateFormat, RenderTemplateParams, RenderedTemplate, } from './types.js';
6
6
  /**
7
7
  * Templates module factory.
8
8
  *
@@ -15,15 +15,15 @@ export type { TemplatesConfig, Template, CreateTemplateParams, UpdateTemplatePar
15
15
  * import { Templates } from '@oblax/templates'
16
16
  *
17
17
  * const oblax = new Oblax({
18
- * endpoint: 'https://api.my-app.oblax.io',
19
- * clientId: 'my-app',
18
+ * endpoint: '<api-endpoint>', // the client's endpoint: `obx project clients list`
19
+ * clientId: '<client-id>',
20
20
  * modules: [PlatformServer(), Templates()],
21
21
  * })
22
22
  *
23
23
  * const tpl = await oblax.templates.create({
24
24
  * displayName: 'Welcome',
25
25
  * format: 'html',
26
- * content: '<p>Hello {{name}}</p>',
26
+ * content: '<p>Hello {{.name}}</p>',
27
27
  * fields: ['name'],
28
28
  * })
29
29
  * ```
@@ -1 +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"}
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,EACd,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,SAAS,CAAC,MAAM,GAAE,eAAoB,GAAG,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,CAOvG"}
package/dist/index.js CHANGED
@@ -12,15 +12,15 @@ export { TemplatesModule } from './templates-module.js';
12
12
  * import { Templates } from '@oblax/templates'
13
13
  *
14
14
  * const oblax = new Oblax({
15
- * endpoint: 'https://api.my-app.oblax.io',
16
- * clientId: 'my-app',
15
+ * endpoint: '<api-endpoint>', // the client's endpoint: `obx project clients list`
16
+ * clientId: '<client-id>',
17
17
  * modules: [PlatformServer(), Templates()],
18
18
  * })
19
19
  *
20
20
  * const tpl = await oblax.templates.create({
21
21
  * displayName: 'Welcome',
22
22
  * format: 'html',
23
- * content: '<p>Hello {{name}}</p>',
23
+ * content: '<p>Hello {{.name}}</p>',
24
24
  * fields: ['name'],
25
25
  * })
26
26
  * ```
package/dist/index.js.map CHANGED
@@ -1 +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"}
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;AAavD;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -1,34 +1,56 @@
1
1
  import type { OblaxContext } from '@oblax/core';
2
- import type { CreateTemplateParams, Template, TemplateKeyParams, TemplatesConfig, UpdateTemplateParams } from './types.js';
2
+ import type { CreateTemplateParams, RenderedTemplate, RenderTemplateParams, Template, TemplateKeyParams, TemplatesConfig, UpdateTemplateParams } from './types.js';
3
3
  /**
4
4
  * The Templates module.
5
5
  *
6
- * Manages templates in the render service.
6
+ * Manages templates in the render service; every call is for the admin role by default. A
7
+ * template's format is `html`, `markdown` or
8
+ * `plaintext` (see {@link TemplateFormat}): the mailer sends html as it is, markdown turned into
9
+ * HTML, and plaintext as a text-only mail.
7
10
  *
8
11
  * @example
9
12
  * ```typescript
10
13
  * const tpl = await oblax.templates.create({
11
14
  * displayName: 'Welcome Email',
12
15
  * format: 'html',
13
- * content: '<h1>Hello {{name}}</h1>',
16
+ * content: '<h1>Hello {{.name}}</h1>',
14
17
  * fields: ['name'],
15
18
  * })
16
19
  *
17
20
  * const all = await oblax.templates.list()
21
+ *
22
+ * const { content } = await oblax.templates.render({ key: tpl.key, data: { name: 'Ana' } })
18
23
  * ```
19
24
  */
20
25
  export declare class TemplatesModule {
21
26
  private readonly ctx;
22
27
  constructor(ctx: OblaxContext, _config: TemplatesConfig);
23
- /** Creates a new template. */
28
+ /**
29
+ * Creates a template. Its key is made from the display name and format, unless `key` is a
30
+ * `system.*` key, which overrides that system mail's template (see `CreateTemplateParams.key`).
31
+ */
24
32
  create(params: CreateTemplateParams): Promise<Template>;
25
- /** Returns all templates. */
33
+ /**
34
+ * Every template of the project, and Oblax's built-in system mail templates it hasn't
35
+ * overridden (`built_in` true).
36
+ */
26
37
  list(): Promise<Template[]>;
27
- /** Fetches a single template by key. */
38
+ /**
39
+ * A template by key. A `system.*` key the project hasn't saved answers with Oblax's built-in
40
+ * template (`built_in` true, no `id`).
41
+ */
28
42
  get(params: TemplateKeyParams): Promise<Template>;
29
- /** Updates a template. */
30
- update(params: UpdateTemplateParams): Promise<Template>;
43
+ /**
44
+ * Saves a new version of the template with the key. A key the project hasn't saved (a
45
+ * built-in it hasn't overridden, a deleted one) is 404: create it instead. Answers `true`.
46
+ */
47
+ update(params: UpdateTemplateParams): Promise<boolean>;
31
48
  /** Deletes a template by key. */
32
49
  delete(params: TemplateKeyParams): Promise<void>;
50
+ /**
51
+ * Renders the template's last version with the data, as it is: html stays html and markdown
52
+ * stays markdown. A key that isn't there is 404; a render too large is a 400 `content: max`.
53
+ */
54
+ render(params: RenderTemplateParams): Promise<RenderedTemplate>;
33
55
  }
34
56
  //# sourceMappingURL=templates-module.d.ts.map
@@ -1 +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"}
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;AAE/C,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,QAAQ,EAER,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACrB,MAAM,YAAY,CAAA;AAgBnB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe;IAExE;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAM7D;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIjC;;;OAGG;IACG,GAAG,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIvD;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAI5D,iCAAiC;IAC3B,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAMtE"}
@@ -1,3 +1,4 @@
1
+ import { pathSegment } from '@oblax/core';
1
2
  /** Maps camelCase input to the snake_case wire format. */
2
3
  function templateToApi(params) {
3
4
  const out = {
@@ -14,43 +15,70 @@ function templateToApi(params) {
14
15
  /**
15
16
  * The Templates module.
16
17
  *
17
- * Manages templates in the render service.
18
+ * Manages templates in the render service; every call is for the admin role by default. A
19
+ * template's format is `html`, `markdown` or
20
+ * `plaintext` (see {@link TemplateFormat}): the mailer sends html as it is, markdown turned into
21
+ * HTML, and plaintext as a text-only mail.
18
22
  *
19
23
  * @example
20
24
  * ```typescript
21
25
  * const tpl = await oblax.templates.create({
22
26
  * displayName: 'Welcome Email',
23
27
  * format: 'html',
24
- * content: '<h1>Hello {{name}}</h1>',
28
+ * content: '<h1>Hello {{.name}}</h1>',
25
29
  * fields: ['name'],
26
30
  * })
27
31
  *
28
32
  * const all = await oblax.templates.list()
33
+ *
34
+ * const { content } = await oblax.templates.render({ key: tpl.key, data: { name: 'Ana' } })
29
35
  * ```
30
36
  */
31
37
  export class TemplatesModule {
32
38
  constructor(ctx, _config) {
33
39
  this.ctx = ctx;
34
40
  }
35
- /** Creates a new template. */
41
+ /**
42
+ * Creates a template. Its key is made from the display name and format, unless `key` is a
43
+ * `system.*` key, which overrides that system mail's template (see `CreateTemplateParams.key`).
44
+ */
36
45
  async create(params) {
37
- return this.ctx.http.post('/templates', templateToApi(params));
46
+ const body = templateToApi(params);
47
+ if (params.key)
48
+ body.key = params.key;
49
+ return this.ctx.http.post('/templates', body);
38
50
  }
39
- /** Returns all templates. */
51
+ /**
52
+ * Every template of the project, and Oblax's built-in system mail templates it hasn't
53
+ * overridden (`built_in` true).
54
+ */
40
55
  async list() {
41
56
  return this.ctx.http.get('/templates');
42
57
  }
43
- /** Fetches a single template by key. */
58
+ /**
59
+ * A template by key. A `system.*` key the project hasn't saved answers with Oblax's built-in
60
+ * template (`built_in` true, no `id`).
61
+ */
44
62
  async get(params) {
45
- return this.ctx.http.get(`/templates/${params.key}`);
63
+ return this.ctx.http.get(`/templates/${pathSegment(params.key)}`);
46
64
  }
47
- /** Updates a template. */
65
+ /**
66
+ * Saves a new version of the template with the key. A key the project hasn't saved (a
67
+ * built-in it hasn't overridden, a deleted one) is 404: create it instead. Answers `true`.
68
+ */
48
69
  async update(params) {
49
- return this.ctx.http.put(`/templates/${params.key}`, templateToApi(params));
70
+ return this.ctx.http.put(`/templates/${pathSegment(params.key)}`, templateToApi(params));
50
71
  }
51
72
  /** Deletes a template by key. */
52
73
  async delete(params) {
53
- return this.ctx.http.delete(`/templates/${params.key}`);
74
+ return this.ctx.http.delete(`/templates/${pathSegment(params.key)}`);
75
+ }
76
+ /**
77
+ * Renders the template's last version with the data, as it is: html stays html and markdown
78
+ * stays markdown. A key that isn't there is 404; a render too large is a 400 `content: max`.
79
+ */
80
+ async render(params) {
81
+ return this.ctx.http.post(`/templates/${pathSegment(params.key)}:render`, { data: params.data ?? {} });
54
82
  }
55
83
  }
56
84
  //# sourceMappingURL=templates-module.js.map
@@ -1 +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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G,CAAC,EAAE,CAAC,CAAA;IAC7E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,MAA4B;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAU,cAAc,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;IACnG,CAAC;IAED,iCAAiC;IACjC,KAAK,CAAC,MAAM,CAAC,MAAyB;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAO,cAAc,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC5E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,MAA4B;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CACvB,cAAc,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,EAC9C,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE,CAC5B,CAAA;IACH,CAAC;CACF"}
package/dist/types.d.ts CHANGED
@@ -1,19 +1,52 @@
1
- export type TemplateFormat = 'html' | 'txt' | 'md' | string;
2
1
  /**
3
- * A template stored in the Oblax render service.
2
+ * A template's format: `html`, `markdown` or `plaintext`, spelled out. The API refuses anything
3
+ * else (`md`, `txt`, `text`) with 400 VALIDATION_FAILED, `format: oneof`. The format is set at
4
+ * creation and can't change.
5
+ *
6
+ * - `html`: the mail is the rendered HTML as it is. Data is HTML-escaped.
7
+ * - `markdown`: the mailer turns the rendered markdown into HTML (CommonMark plus tables,
8
+ * strikethrough and task lists; a bare address stays text), with no styles, and sends that.
9
+ * Raw HTML in the template is dropped. Data is HTML-escaped, put on one line and its markdown
10
+ * punctuation escaped, so it shows as plain text: no structure or links of its own.
11
+ * - `plaintext`: the mail is a text/plain body with no HTML part. Data is used as it is.
12
+ *
13
+ * html and markdown mail also get a plain-text part made from the HTML. Rendering a template
14
+ * (`POST /templates/:key:render`) answers it in its own format: markdown stays markdown.
15
+ */
16
+ export type TemplateFormat = 'html' | 'markdown' | 'plaintext';
17
+ /**
18
+ * A template stored in the Oblax render service, or one of Oblax's built-in system mail
19
+ * templates (`built_in` true) that the project hasn't overridden: a built-in has a `key`,
20
+ * `display_name`, `format`, `content` and `fields`, and no `id`, `parent_id`, `author_id` or
21
+ * `versions`.
4
22
  */
5
23
  export interface Template {
6
24
  id: string;
25
+ /**
26
+ * The key the template is found, updated and rendered by: made from the display name and
27
+ * format (`welcome_email_html`), or a `system.*` key that overrides a system mail's template.
28
+ */
7
29
  key: string;
8
30
  display_name: string;
9
- format: string;
31
+ /** `html`, `markdown` or `plaintext`; see {@link TemplateFormat}. */
32
+ format: TemplateFormat;
10
33
  content: string;
11
34
  fields: string[];
12
35
  parent_id: string;
13
36
  author_id: string;
14
37
  versions?: number;
38
+ /** `true` for Oblax's built-in template of a system mail the project hasn't overridden. */
39
+ built_in?: boolean;
15
40
  }
16
41
  export interface CreateTemplateParams {
42
+ /**
43
+ * Only a `system.*` key is kept (`system.password_reset`): the template overrides that system
44
+ * mail's built-in one, and an unknown `system.*` key is a 400 `key: oneof`. Any other key is
45
+ * ignored, and the key is made from the display name and format (`Welcome email` in html is
46
+ * `welcome_email_html`). Create doesn't check whether the key is taken: get it first and
47
+ * update the one that's there.
48
+ */
49
+ key?: string;
17
50
  displayName: string;
18
51
  format: TemplateFormat;
19
52
  content: string;
@@ -21,6 +54,7 @@ export interface CreateTemplateParams {
21
54
  }
22
55
  export interface UpdateTemplateParams {
23
56
  key: string;
57
+ /** The template's `parent_id`, as `get()` answers it. */
24
58
  parentId: string;
25
59
  displayName: string;
26
60
  format: TemplateFormat;
@@ -30,6 +64,19 @@ export interface UpdateTemplateParams {
30
64
  export interface TemplateKeyParams {
31
65
  key: string;
32
66
  }
67
+ export interface RenderTemplateParams {
68
+ key: string;
69
+ /** The values for the template's fields (`{{.name}}` reads `data.name`). */
70
+ data?: Record<string, unknown>;
71
+ }
72
+ /**
73
+ * A rendered template: its key and its last version rendered with the data, in the template's
74
+ * own format (a markdown template renders to markdown, not the HTML the mailer makes of it).
75
+ */
76
+ export interface RenderedTemplate {
77
+ key: string;
78
+ content: string;
79
+ }
33
80
  export interface TemplatesConfig {
34
81
  }
35
82
  //# sourceMappingURL=types.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[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AO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;CAE/B"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@oblax/templates",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Oblax SDK — templates module (create, list, get, update, delete templates)",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Oblax SDK for JavaScript Team",
8
- "url": "https://docs.oblax.io/docs/getting-started/your-first-sdk-call"
8
+ "url": "https://docs.oblax.io/docs/getting-started/first-call/"
9
9
  },
10
10
  "homepage": "https://github.com/oblaxio/oblax-sdk-js#readme",
11
11
  "repository": {
@@ -37,11 +37,11 @@
37
37
  "access": "public"
38
38
  },
39
39
  "peerDependencies": {
40
- "@oblax/core": "^2.1.0"
40
+ "@oblax/core": "^2.2.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "typescript": "^5.5.0",
44
- "@oblax/core": "2.1.0"
44
+ "@oblax/core": "2.2.0"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsc --build tsconfig.json",